input of channel names
This commit is contained in:
+36
-15
@@ -1,37 +1,51 @@
|
|||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
|
#include "ircmanager.h"
|
||||||
|
|
||||||
Channel Channels::m_whispers(QString("/whispers"));
|
Channel Channels::m_whispers(QString("/whispers"));
|
||||||
Channel Channels::m_mentions(QString("/mentions"));
|
Channel Channels::m_mentions(QString("/mentions"));
|
||||||
|
Channel Channels::m_empty(QString(""));
|
||||||
|
|
||||||
QMap<QString, std::tuple<Channel *, int>> Channels::m_channels;
|
QMap<QString, std::tuple<Channel *, int>> Channels::m_channels;
|
||||||
|
|
||||||
Channel *
|
Channel *
|
||||||
Channels::addChannel(const QString &channel)
|
Channels::addChannel(const QString &channel)
|
||||||
{
|
{
|
||||||
auto c = getChannel(channel);
|
QString c = channel.toLower();
|
||||||
|
|
||||||
if (c == NULL) {
|
auto a = m_channels.find(c);
|
||||||
c = new Channel(channel);
|
|
||||||
m_channels.insert(channel, std::tuple<Channel *, int>(c, 1));
|
|
||||||
|
|
||||||
return c;
|
if (a == m_channels.end()) {
|
||||||
|
auto _c = new Channel(c);
|
||||||
|
m_channels.insert(c, std::tuple<Channel *, int>(_c, 1));
|
||||||
|
|
||||||
|
IrcManager::joinChannel(c);
|
||||||
|
|
||||||
|
return _c;
|
||||||
|
} else {
|
||||||
|
std::get<1>(a.value())++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return std::get<0>(a.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel *
|
Channel *
|
||||||
Channels::getChannel(const QString &channel)
|
Channels::getChannel(const QString &channel)
|
||||||
{
|
{
|
||||||
if (channel == "/whispers") {
|
QString c = channel.toLower();
|
||||||
return &m_whispers;
|
|
||||||
|
if (channel.length() > 1 && channel.at(0) == '/') {
|
||||||
|
if (c == "/whispers") {
|
||||||
|
return &m_whispers;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c == "/mentions") {
|
||||||
|
return &m_mentions;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &m_empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel == "/mentions") {
|
auto a = m_channels.find(c);
|
||||||
return &m_mentions;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto a = m_channels.find(channel);
|
|
||||||
|
|
||||||
if (a == m_channels.end()) {
|
if (a == m_channels.end()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -43,7 +57,13 @@ Channels::getChannel(const QString &channel)
|
|||||||
void
|
void
|
||||||
Channels::removeChannel(const QString &channel)
|
Channels::removeChannel(const QString &channel)
|
||||||
{
|
{
|
||||||
auto a = m_channels.find(channel);
|
if (channel.length() > 1 && channel.at(0) == '/') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString c = channel.toLower();
|
||||||
|
|
||||||
|
auto a = m_channels.find(c);
|
||||||
|
|
||||||
if (a == m_channels.end()) {
|
if (a == m_channels.end()) {
|
||||||
return;
|
return;
|
||||||
@@ -52,7 +72,8 @@ Channels::removeChannel(const QString &channel)
|
|||||||
std::get<1>(a.value())--;
|
std::get<1>(a.value())--;
|
||||||
|
|
||||||
if (std::get<1>(a.value()) == 0) {
|
if (std::get<1>(a.value()) == 0) {
|
||||||
m_channels.remove(channel);
|
IrcManager::partChannel(c);
|
||||||
|
m_channels.remove(c);
|
||||||
delete std::get<0>(a.value());
|
delete std::get<0>(a.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ private:
|
|||||||
|
|
||||||
static Channel m_whispers;
|
static Channel m_whispers;
|
||||||
static Channel m_mentions;
|
static Channel m_mentions;
|
||||||
|
static Channel m_empty;
|
||||||
|
|
||||||
static QMap<QString, std::tuple<Channel *, int>> m_channels;
|
static QMap<QString, std::tuple<Channel *, int>> m_channels;
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-2
@@ -68,7 +68,7 @@ SOURCES += main.cpp\
|
|||||||
chatwidgetheaderbutton.cpp \
|
chatwidgetheaderbutton.cpp \
|
||||||
chatwidgetheaderbuttonlabel.cpp \
|
chatwidgetheaderbuttonlabel.cpp \
|
||||||
channels.cpp \
|
channels.cpp \
|
||||||
textinputform.cpp
|
textinputdialog.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
chatwidget.h \
|
chatwidget.h \
|
||||||
@@ -108,7 +108,7 @@ HEADERS += mainwindow.h \
|
|||||||
chatwidgetheaderbutton.h \
|
chatwidgetheaderbutton.h \
|
||||||
chatwidgetheaderbuttonlabel.h \
|
chatwidgetheaderbuttonlabel.h \
|
||||||
channels.h \
|
channels.h \
|
||||||
textinputform.h
|
textinputdialog.h
|
||||||
|
|
||||||
PRECOMPILED_HEADER =
|
PRECOMPILED_HEADER =
|
||||||
|
|
||||||
|
|||||||
+51
-5
@@ -1,14 +1,21 @@
|
|||||||
#include "chatwidget.h"
|
#include "chatwidget.h"
|
||||||
#include "QFont"
|
#include "channels.h"
|
||||||
#include "QFontDatabase"
|
|
||||||
#include "QPainter"
|
|
||||||
#include "QVBoxLayout"
|
|
||||||
#include "colorscheme.h"
|
#include "colorscheme.h"
|
||||||
|
#include "textinputdialog.h"
|
||||||
|
|
||||||
|
#include <QFont>
|
||||||
|
#include <QFontDatabase>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
ChatWidget::ChatWidget(QWidget *parent)
|
ChatWidget::ChatWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_header(this)
|
, m_channel(NULL)
|
||||||
|
, m_channelName(QString())
|
||||||
, m_vbox(this)
|
, m_vbox(this)
|
||||||
|
, m_header(this)
|
||||||
|
, m_view(this)
|
||||||
|
, m_input()
|
||||||
{
|
{
|
||||||
m_vbox.setSpacing(0);
|
m_vbox.setSpacing(0);
|
||||||
m_vbox.setMargin(1);
|
m_vbox.setMargin(1);
|
||||||
@@ -22,6 +29,45 @@ ChatWidget::~ChatWidget()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidget::setChannelName(const QString &name)
|
||||||
|
{
|
||||||
|
QString channel = name.trimmed();
|
||||||
|
|
||||||
|
if (QString::compare(channel, m_channelName, Qt::CaseInsensitive) == 0) {
|
||||||
|
m_channelName = channel;
|
||||||
|
m_header.updateChannelText();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_channelName = channel;
|
||||||
|
m_header.updateChannelText();
|
||||||
|
|
||||||
|
m_view.layoutMessages();
|
||||||
|
|
||||||
|
if (!m_channelName.isEmpty()) {
|
||||||
|
Channels::removeChannel(m_channelName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel.isEmpty()) {
|
||||||
|
m_channel = NULL;
|
||||||
|
} else {
|
||||||
|
m_channel = Channels::addChannel(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidget::showChangeChannelPopup()
|
||||||
|
{
|
||||||
|
TextInputDialog dialog(this);
|
||||||
|
|
||||||
|
dialog.setText(m_channelName);
|
||||||
|
|
||||||
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
|
setChannelName(dialog.text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ChatWidget::paintEvent(QPaintEvent *)
|
ChatWidget::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
|
|||||||
+13
-2
@@ -29,17 +29,28 @@ public:
|
|||||||
return m_channel;
|
return m_channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &
|
||||||
|
channelName() const
|
||||||
|
{
|
||||||
|
return m_channelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChannelName(const QString &name);
|
||||||
|
|
||||||
|
void showChangeChannelPopup();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Channel *m_channel;
|
||||||
|
QString m_channelName;
|
||||||
|
|
||||||
QFont m_font;
|
QFont m_font;
|
||||||
QVBoxLayout m_vbox;
|
QVBoxLayout m_vbox;
|
||||||
ChatWidgetHeader m_header;
|
ChatWidgetHeader m_header;
|
||||||
ChatWidgetView m_view;
|
ChatWidgetView m_view;
|
||||||
ChatWidgetInput m_input;
|
ChatWidgetInput m_input;
|
||||||
|
|
||||||
Channel *m_channel = NULL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHATWIDGET_H
|
#endif // CHATWIDGET_H
|
||||||
|
|||||||
+37
-27
@@ -22,6 +22,7 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
|
|||||||
setFixedHeight(32);
|
setFixedHeight(32);
|
||||||
|
|
||||||
updateColors();
|
updateColors();
|
||||||
|
updateChannelText();
|
||||||
|
|
||||||
setLayout(&m_hbox);
|
setLayout(&m_hbox);
|
||||||
m_hbox.setMargin(0);
|
m_hbox.setMargin(0);
|
||||||
@@ -37,36 +38,28 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
|
|||||||
QObject::connect(&m_leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
QObject::connect(&m_leftLabel, &ChatWidgetHeaderButton::clicked, this,
|
||||||
&ChatWidgetHeader::leftButtonClicked);
|
&ChatWidgetHeader::leftButtonClicked);
|
||||||
|
|
||||||
m_leftMenu.addAction("Add new split", this,
|
m_leftMenu.addAction("Add new split", this, SLOT(menuAddSplit()),
|
||||||
SLOT(menuAddSplit()),
|
QKeySequence(tr("Ctrl+T")));
|
||||||
QKeySequence(tr("Ctrl+T")));
|
m_leftMenu.addAction("Close split", this, SLOT(menuCloseSplit()),
|
||||||
m_leftMenu.addAction("Close split", this,
|
QKeySequence(tr("Ctrl+W")));
|
||||||
SLOT(menuCloseSplit()),
|
m_leftMenu.addAction("Move split", this, SLOT(menuMoveSplit()));
|
||||||
QKeySequence(tr("Ctrl+W")));
|
m_leftMenu.addSeparator();
|
||||||
m_leftMenu.addAction("Move split", this,
|
m_leftMenu.addAction("Change channel", this, SLOT(menuChangeChannel()),
|
||||||
SLOT(menuMoveSplit()));
|
QKeySequence(tr("Ctrl+R")));
|
||||||
m_leftMenu.addSeparator();
|
m_leftMenu.addAction("Clear chat", this, SLOT(menuClearChat()));
|
||||||
m_leftMenu.addAction("Change channel", this,
|
m_leftMenu.addAction("Open channel", this, SLOT(menuOpenChannel()));
|
||||||
SLOT(menuChangeChannel()),
|
m_leftMenu.addAction("Open pop-out player", this, SLOT(menuPopupPlayer()));
|
||||||
QKeySequence(tr("Ctrl+R")));
|
m_leftMenu.addSeparator();
|
||||||
m_leftMenu.addAction("Clear chat", this,
|
m_leftMenu.addAction("Reload channel emotes", this,
|
||||||
SLOT(menuClearChat()));
|
SLOT(menuReloadChannelEmotes()));
|
||||||
m_leftMenu.addAction("Open channel", this,
|
m_leftMenu.addAction("Manual reconnect", this, SLOT(menuManualReconnect()));
|
||||||
SLOT(menuOpenChannel()));
|
m_leftMenu.addSeparator();
|
||||||
m_leftMenu.addAction("Open pop-out player", this,
|
m_leftMenu.addAction("Show changelog", this, SLOT(menuShowChangelog()));
|
||||||
SLOT(menuPopupPlayer()));
|
|
||||||
m_leftMenu.addSeparator();
|
|
||||||
m_leftMenu.addAction("Reload channel emotes", this,
|
|
||||||
SLOT(menuReloadChannelEmotes()));
|
|
||||||
m_leftMenu.addAction("Manual reconnect", this,
|
|
||||||
SLOT(menuManualReconnect()));
|
|
||||||
m_leftMenu.addSeparator();
|
|
||||||
m_leftMenu.addAction("Show changelog", this,
|
|
||||||
SLOT(menuShowChangelog()));
|
|
||||||
|
|
||||||
// middle
|
// middle
|
||||||
m_middleLabel.setAlignment(Qt::AlignCenter);
|
m_middleLabel.setAlignment(Qt::AlignCenter);
|
||||||
m_middleLabel.setText("textString");
|
QObject::connect(&m_middleLabel, &m_middleLabel.mouseDoubleClickEvent, this,
|
||||||
|
&mouseDoubleClickEvent);
|
||||||
|
|
||||||
// right
|
// right
|
||||||
m_rightLabel.setMinimumWidth(height());
|
m_rightLabel.setMinimumWidth(height());
|
||||||
@@ -85,6 +78,14 @@ ChatWidgetHeader::updateColors()
|
|||||||
m_rightLabel.setPalette(palette);
|
m_rightLabel.setPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidgetHeader::updateChannelText()
|
||||||
|
{
|
||||||
|
const QString &c = m_chatWidget->channelName();
|
||||||
|
|
||||||
|
m_middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ChatWidgetHeader::paintEvent(QPaintEvent *)
|
ChatWidgetHeader::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
@@ -139,6 +140,14 @@ ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (event->button() == Qt::LeftButton) {
|
||||||
|
chatWidget()->showChangeChannelPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ChatWidgetHeader::leftButtonClicked()
|
ChatWidgetHeader::leftButtonClicked()
|
||||||
{
|
{
|
||||||
@@ -166,6 +175,7 @@ ChatWidgetHeader::menuMoveSplit()
|
|||||||
void
|
void
|
||||||
ChatWidgetHeader::menuChangeChannel()
|
ChatWidgetHeader::menuChangeChannel()
|
||||||
{
|
{
|
||||||
|
m_chatWidget->showChangeChannelPopup();
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
ChatWidgetHeader::menuClearChat()
|
ChatWidgetHeader::menuClearChat()
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateColors();
|
void updateColors();
|
||||||
|
void updateChannelText();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
void mouseMoveEvent(QMouseEvent *event);
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ChatWidget *m_chatWidget;
|
ChatWidget *m_chatWidget;
|
||||||
|
|||||||
+8
-9
@@ -1,5 +1,6 @@
|
|||||||
#include "chatwidgetview.h"
|
#include "chatwidgetview.h"
|
||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
|
#include "chatwidget.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "word.h"
|
#include "word.h"
|
||||||
#include "wordpart.h"
|
#include "wordpart.h"
|
||||||
@@ -7,22 +8,20 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
|
|
||||||
ChatWidgetView::ChatWidgetView()
|
ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
||||||
: QWidget()
|
: QWidget()
|
||||||
, scrollbar(this)
|
, m_chatWidget(parent)
|
||||||
, m_channel(NULL)
|
, m_scrollbar(this)
|
||||||
{
|
{
|
||||||
auto scroll = QScroller::scroller(this);
|
auto scroll = QScroller::scroller(this);
|
||||||
|
|
||||||
scroll->scrollTo(QPointF(0, 100));
|
scroll->scrollTo(QPointF(0, 100));
|
||||||
|
|
||||||
m_channel = Channels::getChannel("fourtf");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ChatWidgetView::layoutMessages()
|
ChatWidgetView::layoutMessages()
|
||||||
{
|
{
|
||||||
auto c = channel();
|
auto c = m_chatWidget->channel();
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return false;
|
return false;
|
||||||
@@ -41,8 +40,8 @@ ChatWidgetView::layoutMessages()
|
|||||||
void
|
void
|
||||||
ChatWidgetView::resizeEvent(QResizeEvent *)
|
ChatWidgetView::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
scrollbar.resize(scrollbar.width(), height());
|
m_scrollbar.resize(m_scrollbar.width(), height());
|
||||||
scrollbar.move(width() - scrollbar.width(), 0);
|
m_scrollbar.move(width() - m_scrollbar.width(), 0);
|
||||||
|
|
||||||
layoutMessages();
|
layoutMessages();
|
||||||
}
|
}
|
||||||
@@ -54,7 +53,7 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
|||||||
|
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
|
|
||||||
auto c = channel();
|
auto c = m_chatWidget->channel();
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return;
|
return;
|
||||||
|
|||||||
+6
-9
@@ -6,18 +6,14 @@
|
|||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "scrollbar.h"
|
#include "scrollbar.h"
|
||||||
|
|
||||||
|
class ChatWidget;
|
||||||
|
|
||||||
class ChatWidgetView : public QWidget
|
class ChatWidgetView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatWidgetView();
|
ChatWidgetView(ChatWidget *parent);
|
||||||
|
|
||||||
Channel *
|
|
||||||
channel()
|
|
||||||
{
|
|
||||||
return m_channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool layoutMessages();
|
bool layoutMessages();
|
||||||
|
|
||||||
@@ -25,8 +21,9 @@ protected:
|
|||||||
void resizeEvent(QResizeEvent *);
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ScrollBar scrollbar;
|
ChatWidget *m_chatWidget;
|
||||||
Channel *m_channel;
|
|
||||||
|
ScrollBar m_scrollbar;
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
};
|
};
|
||||||
|
|||||||
+58
-39
@@ -13,14 +13,14 @@
|
|||||||
#include <future>
|
#include <future>
|
||||||
|
|
||||||
Account *IrcManager::account = nullptr;
|
Account *IrcManager::account = nullptr;
|
||||||
IrcConnection *IrcManager::connection = NULL;
|
IrcConnection *IrcManager::m_connection = NULL;
|
||||||
QMutex IrcManager::connectionMutex;
|
QMutex IrcManager::m_connectionMutex;
|
||||||
long IrcManager::connectionIteration = 0;
|
long IrcManager::m_connectionIteration = 0;
|
||||||
const QString IrcManager::defaultClientId = "7ue61iz46fz11y3cugd0l3tawb4taal";
|
const QString IrcManager::defaultClientId = "7ue61iz46fz11y3cugd0l3tawb4taal";
|
||||||
QNetworkAccessManager IrcManager::m_accessManager;
|
QNetworkAccessManager IrcManager::m_accessManager;
|
||||||
|
|
||||||
QMap<QString, bool> IrcManager::twitchBlockedUsers;
|
QMap<QString, bool> IrcManager::m_twitchBlockedUsers;
|
||||||
QMutex IrcManager::twitchBlockedUsersMutex;
|
QMutex IrcManager::m_twitchBlockedUsersMutex;
|
||||||
|
|
||||||
IrcManager::IrcManager()
|
IrcManager::IrcManager()
|
||||||
{
|
{
|
||||||
@@ -39,7 +39,7 @@ IrcManager::beginConnecting()
|
|||||||
{
|
{
|
||||||
IrcManager::account = const_cast<Account *>(Account::anon());
|
IrcManager::account = const_cast<Account *>(Account::anon());
|
||||||
|
|
||||||
int iteration = ++connectionIteration;
|
int iteration = ++m_connectionIteration;
|
||||||
|
|
||||||
auto c = new IrcConnection();
|
auto c = new IrcConnection();
|
||||||
|
|
||||||
@@ -62,9 +62,9 @@ IrcManager::beginConnecting()
|
|||||||
QNetworkReply *reply = m_accessManager.get(req);
|
QNetworkReply *reply = m_accessManager.get(req);
|
||||||
|
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
QObject::connect(reply, &QNetworkReply::finished, [=] {
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
twitchBlockedUsers.clear();
|
m_twitchBlockedUsers.clear();
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
|
|
||||||
QByteArray data = reply->readAll();
|
QByteArray data = reply->readAll();
|
||||||
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
|
||||||
@@ -75,15 +75,15 @@ IrcManager::beginConnecting()
|
|||||||
|
|
||||||
auto blocks = root.value("blocks").toArray();
|
auto blocks = root.value("blocks").toArray();
|
||||||
|
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
for (QJsonValue block : blocks) {
|
for (QJsonValue block : blocks) {
|
||||||
QJsonObject user =
|
QJsonObject user =
|
||||||
block.toObject().value("user").toObject();
|
block.toObject().value("user").toObject();
|
||||||
// display_name
|
// display_name
|
||||||
twitchBlockedUsers.insert(
|
m_twitchBlockedUsers.insert(
|
||||||
user.value("name").toString().toLower(), true);
|
user.value("name").toString().toLower(), true);
|
||||||
}
|
}
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,15 +104,15 @@ IrcManager::beginConnecting()
|
|||||||
|
|
||||||
auto blocks = root.value("blocks").toArray();
|
auto blocks = root.value("blocks").toArray();
|
||||||
|
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
for (QJsonValue block : blocks) {
|
for (QJsonValue block : blocks) {
|
||||||
QJsonObject user =
|
QJsonObject user =
|
||||||
block.toObject().value("user").toObject();
|
block.toObject().value("user").toObject();
|
||||||
// display_name
|
// display_name
|
||||||
twitchBlockedUsers.insert(
|
m_twitchBlockedUsers.insert(
|
||||||
user.value("name").toString().toLower(), true);
|
user.value("name").toString().toLower(), true);
|
||||||
}
|
}
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,41 +123,60 @@ IrcManager::beginConnecting()
|
|||||||
c->setUserName("justinfan123");
|
c->setUserName("justinfan123");
|
||||||
c->setNickName("justinfan123");
|
c->setNickName("justinfan123");
|
||||||
c->setRealName("justinfan123");
|
c->setRealName("justinfan123");
|
||||||
c->sendRaw("JOIN #fourtf");
|
|
||||||
|
|
||||||
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/commands"));
|
||||||
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
c->sendCommand(IrcCommand::createCapability("REQ", "twitch.tv/tags"));
|
||||||
|
|
||||||
c->open();
|
c->open();
|
||||||
|
|
||||||
connectionMutex.lock();
|
m_connectionMutex.lock();
|
||||||
if (iteration == connectionIteration) {
|
if (iteration == m_connectionIteration) {
|
||||||
delete connection;
|
delete m_connection;
|
||||||
c->moveToThread(QCoreApplication::instance()->thread());
|
c->moveToThread(QCoreApplication::instance()->thread());
|
||||||
connection = c;
|
m_connection = c;
|
||||||
} else {
|
} else {
|
||||||
delete c;
|
delete c;
|
||||||
}
|
}
|
||||||
connectionMutex.unlock();
|
m_connectionMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IrcManager::disconnect()
|
IrcManager::disconnect()
|
||||||
{
|
{
|
||||||
connectionMutex.lock();
|
m_connectionMutex.lock();
|
||||||
|
|
||||||
if (connection != NULL) {
|
if (m_connection != NULL) {
|
||||||
delete connection;
|
delete m_connection;
|
||||||
connection = NULL;
|
m_connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionMutex.unlock();
|
m_connectionMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IrcManager::joinChannel(const QString &channel)
|
||||||
|
{
|
||||||
|
m_connectionMutex.lock();
|
||||||
|
if (m_connection != NULL) {
|
||||||
|
m_connection->sendRaw("JOIN #" + channel);
|
||||||
|
}
|
||||||
|
m_connectionMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IrcManager::partChannel(const QString &channel)
|
||||||
|
{
|
||||||
|
m_connectionMutex.lock();
|
||||||
|
if (m_connection != NULL) {
|
||||||
|
m_connection->sendRaw("PART #" + channel);
|
||||||
|
}
|
||||||
|
m_connectionMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
IrcManager::messageReceived(IrcMessage *message)
|
IrcManager::messageReceived(IrcMessage *message)
|
||||||
{
|
{
|
||||||
// qInfo(message->command().toStdString().c_str());
|
qInfo(message->command().toStdString().c_str());
|
||||||
|
|
||||||
// if (message->command() == "")
|
// if (message->command() == "")
|
||||||
}
|
}
|
||||||
@@ -165,7 +184,7 @@ IrcManager::messageReceived(IrcMessage *message)
|
|||||||
void
|
void
|
||||||
IrcManager::privateMessageReceived(IrcPrivateMessage *message)
|
IrcManager::privateMessageReceived(IrcPrivateMessage *message)
|
||||||
{
|
{
|
||||||
// qInfo(message->content().toStdString().c_str());
|
// qInfo(message->content().toStdString().c_str());
|
||||||
|
|
||||||
auto c = Channels::getChannel(message->target().mid(1));
|
auto c = Channels::getChannel(message->target().mid(1));
|
||||||
|
|
||||||
@@ -177,16 +196,16 @@ IrcManager::privateMessageReceived(IrcPrivateMessage *message)
|
|||||||
bool
|
bool
|
||||||
IrcManager::isTwitchBlockedUser(QString const &username)
|
IrcManager::isTwitchBlockedUser(QString const &username)
|
||||||
{
|
{
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
|
|
||||||
auto iterator = twitchBlockedUsers.find(username);
|
auto iterator = m_twitchBlockedUsers.find(username);
|
||||||
|
|
||||||
if (iterator == twitchBlockedUsers.end()) {
|
if (iterator == m_twitchBlockedUsers.end()) {
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,9 +221,9 @@ IrcManager::tryAddIgnoredUser(QString const &username, QString &errorMessage)
|
|||||||
reply->waitForReadyRead(10000);
|
reply->waitForReadyRead(10000);
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
twitchBlockedUsers.insert(username, true);
|
m_twitchBlockedUsers.insert(username, true);
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
|
|
||||||
delete reply;
|
delete reply;
|
||||||
return true;
|
return true;
|
||||||
@@ -236,9 +255,9 @@ IrcManager::tryRemoveIgnoredUser(QString const &username, QString &errorMessage)
|
|||||||
reply->waitForReadyRead(10000);
|
reply->waitForReadyRead(10000);
|
||||||
|
|
||||||
if (reply->error() == QNetworkReply::NoError) {
|
if (reply->error() == QNetworkReply::NoError) {
|
||||||
twitchBlockedUsersMutex.lock();
|
m_twitchBlockedUsersMutex.lock();
|
||||||
twitchBlockedUsers.remove(username);
|
m_twitchBlockedUsers.remove(username);
|
||||||
twitchBlockedUsersMutex.unlock();
|
m_twitchBlockedUsersMutex.unlock();
|
||||||
|
|
||||||
delete reply;
|
delete reply;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
+9
-5
@@ -34,19 +34,23 @@ public:
|
|||||||
return m_accessManager;
|
return m_accessManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void joinChannel(const QString &channel);
|
||||||
|
|
||||||
|
static void partChannel(const QString &channel);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IrcManager();
|
IrcManager();
|
||||||
|
|
||||||
static QMap<QString, bool> twitchBlockedUsers;
|
static QMap<QString, bool> m_twitchBlockedUsers;
|
||||||
static QMutex twitchBlockedUsersMutex;
|
static QMutex m_twitchBlockedUsersMutex;
|
||||||
|
|
||||||
static QNetworkAccessManager m_accessManager;
|
static QNetworkAccessManager m_accessManager;
|
||||||
|
|
||||||
static void beginConnecting();
|
static void beginConnecting();
|
||||||
|
|
||||||
static IrcConnection *connection;
|
static IrcConnection *m_connection;
|
||||||
static QMutex connectionMutex;
|
static QMutex m_connectionMutex;
|
||||||
static long connectionIteration;
|
static long m_connectionIteration;
|
||||||
|
|
||||||
static void messageReceived(IrcMessage *message);
|
static void messageReceived(IrcMessage *message);
|
||||||
static void privateMessageReceived(IrcPrivateMessage *message);
|
static void privateMessageReceived(IrcPrivateMessage *message);
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ main(int argc, char *argv[])
|
|||||||
MainWindow &w = Windows::mainWindow();
|
MainWindow &w = Windows::mainWindow();
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
Channels::addChannel("ian678");
|
|
||||||
Channels::addChannel("fourtf");
|
|
||||||
|
|
||||||
IrcManager::connect();
|
IrcManager::connect();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include "textinputdialog.h"
|
||||||
|
#include <QSizePolicy>
|
||||||
|
|
||||||
|
TextInputDialog::TextInputDialog(QWidget *parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
, m_vbox(this)
|
||||||
|
, m_lineEdit()
|
||||||
|
, m_buttonBox()
|
||||||
|
, m_okButton("OK")
|
||||||
|
, m_cancelButton("Cancel")
|
||||||
|
{
|
||||||
|
m_vbox.addWidget(&m_lineEdit);
|
||||||
|
m_vbox.addLayout(&m_buttonBox);
|
||||||
|
m_buttonBox.addStretch(1);
|
||||||
|
m_buttonBox.addWidget(&m_okButton);
|
||||||
|
m_buttonBox.addWidget(&m_cancelButton);
|
||||||
|
|
||||||
|
QObject::connect(&m_okButton, &m_okButton.clicked, this, &okButtonClicked);
|
||||||
|
QObject::connect(&m_cancelButton, &m_cancelButton.clicked, this,
|
||||||
|
&cancelButtonClicked);
|
||||||
|
|
||||||
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
|
setWindowFlags((windowFlags() & ~(Qt::WindowContextHelpButtonHint)) |
|
||||||
|
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TextInputDialog::okButtonClicked()
|
||||||
|
{
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TextInputDialog::cancelButtonClicked()
|
||||||
|
{
|
||||||
|
reject();
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef TEXTINPUTDIALOG_H
|
||||||
|
#define TEXTINPUTDIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QString>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
class TextInputDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
TextInputDialog(QWidget *parent = NULL);
|
||||||
|
|
||||||
|
QString
|
||||||
|
text() const
|
||||||
|
{
|
||||||
|
return m_lineEdit.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
setText(const QString &text)
|
||||||
|
{
|
||||||
|
m_lineEdit.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVBoxLayout m_vbox;
|
||||||
|
QLineEdit m_lineEdit;
|
||||||
|
QHBoxLayout m_buttonBox;
|
||||||
|
QPushButton m_okButton;
|
||||||
|
QPushButton m_cancelButton;
|
||||||
|
|
||||||
|
void okButtonClicked();
|
||||||
|
void cancelButtonClicked();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TEXTINPUTDIALOG_H
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
#include "textinputform.h"
|
|
||||||
|
|
||||||
TextInputForm::TextInputForm()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#ifndef TEXTINPUTFORM_H
|
|
||||||
#define TEXTINPUTFORM_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
|
||||||
|
|
||||||
class TextInputForm : public QDialog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TextInputForm();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // TEXTINPUTFORM_H
|
|
||||||
Reference in New Issue
Block a user