diff --git a/src/ircmanager.cpp b/src/ircmanager.cpp index d8c5b9cf7..fc19cbd42 100644 --- a/src/ircmanager.cpp +++ b/src/ircmanager.cpp @@ -292,14 +292,12 @@ void IrcManager::handleUserNoticeMessage(Communi::IrcMessage *message) void IrcManager::handleModeMessage(Communi::IrcMessage *message) { - auto channel = channelManager.getTwitchChannel(message->parameter(0).remove(0,1)); - if(message->parameter(1) == "+o") - { - channel->modList.append(message->parameter(2)); - } else if(message->parameter(1) == "-o") - { - channel->modList.append(message->parameter(2)); - } + auto channel = channelManager.getTwitchChannel(message->parameter(0).remove(0, 1)); + if (message->parameter(1) == "+o") { + channel->modList.append(message->parameter(2)); + } else if (message->parameter(1) == "-o") { + channel->modList.append(message->parameter(2)); + } } bool IrcManager::isTwitchBlockedUser(QString const &username) diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index 49aa6f969..bb0df02ee 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -1,10 +1,10 @@ #include "widgets/accountpopup.hpp" -#include "util/urlfetch.hpp" #include "accountmanager.hpp" #include "channel.hpp" #include "credentials.hpp" #include "settingsmanager.hpp" #include "ui_accountpopupform.h" +#include "util/urlfetch.hpp" #include #include @@ -32,20 +32,16 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) SettingsManager &settings = SettingsManager::getInstance(); permission = permissions::User; - for(auto button : this->_ui->profileLayout->findChildren()) - { + for (auto button : this->_ui->profileLayout->findChildren()) { button->setFocusProxy(this); } - for(auto button: this->_ui->userLayout->findChildren()) - { + for (auto button : this->_ui->userLayout->findChildren()) { button->setFocusProxy(this); } - for(auto button: this->_ui->modLayout->findChildren()) - { + for (auto button : this->_ui->modLayout->findChildren()) { button->setFocusProxy(this); } - for(auto button: this->_ui->ownerLayout->findChildren()) - { + for (auto button : this->_ui->ownerLayout->findChildren()) { button->setFocusProxy(this); } @@ -69,41 +65,33 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) userNickname = currentTwitchUser->getNickName(); } - QObject::connect(this->_ui->profile, &QPushButton::clicked, this, [=](){ - QDesktopServices::openUrl(QUrl("https://twitch.tv/" + - this->_ui->lblUsername->text())); + QObject::connect(this->_ui->profile, &QPushButton::clicked, this, [=]() { + QDesktopServices::openUrl(QUrl("https://twitch.tv/" + this->_ui->lblUsername->text())); }); - QObject::connect(this->_ui->sendMessage, &QPushButton::clicked, this, [=](){ - QDesktopServices::openUrl(QUrl("https://www.twitch.tv/message/compose?to=" + - this->_ui->lblUsername->text())); + QObject::connect(this->_ui->sendMessage, &QPushButton::clicked, this, [=]() { + QDesktopServices::openUrl( + QUrl("https://www.twitch.tv/message/compose?to=" + this->_ui->lblUsername->text())); }); - QObject::connect(this->_ui->copy, &QPushButton::clicked, this, [=](){ - QApplication::clipboard()->setText(this->_ui->lblUsername->text()); + QObject::connect(this->_ui->copy, &QPushButton::clicked, this, + [=]() { QApplication::clipboard()->setText(this->_ui->lblUsername->text()); }); + + QObject::connect(this->_ui->follow, &QPushButton::clicked, this, [=]() { + QUrl requestUrl("https://api.twitch.tv/kraken/users/" + userId + "/follows/channels/" + + this->userID); + + util::twitch::put(requestUrl, + [](QJsonObject obj) { qDebug() << "follows channel: " << obj; }); }); - QObject::connect(this->_ui->follow, &QPushButton::clicked, this, [=](){ - QUrl requestUrl("https://api.twitch.tv/kraken/users/" + - userId + - "/follows/channels/" + this->userID); + QObject::connect(this->_ui->ignore, &QPushButton::clicked, this, [=]() { + QUrl requestUrl("https://api.twitch.tv/kraken/users/" + userId + "/blocks/" + this->userID); - util::twitch::put(requestUrl,[](QJsonObject obj){ - qDebug() << "follows channel: " << obj; - }); + util::twitch::put(requestUrl, [](QJsonObject obj) { qDebug() << "blocks user: " << obj; }); }); - QObject::connect(this->_ui->ignore, &QPushButton::clicked, this, [=](){ - QUrl requestUrl("https://api.twitch.tv/kraken/users/" + - userId + - "/blocks/" + this->userID); - - util::twitch::put(requestUrl,[](QJsonObject obj){ - qDebug() << "blocks user: " << obj; - }); - }); - - QObject::connect(this->_ui->disableHighlights, &QPushButton::clicked, this, [=, &settings](){ + QObject::connect(this->_ui->disableHighlights, &QPushButton::clicked, this, [=, &settings]() { QString str = settings.highlightUserBlacklist.getnonConst(); str.append(this->_ui->lblUsername->text() + "\n"); settings.highlightUserBlacklist.set(str); @@ -111,7 +99,7 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) this->_ui->enableHighlights->show(); }); - QObject::connect(this->_ui->enableHighlights, &QPushButton::clicked, this, [=, &settings](){ + QObject::connect(this->_ui->enableHighlights, &QPushButton::clicked, this, [=, &settings]() { QString str = settings.highlightUserBlacklist.getnonConst(); QStringList list = str.split("\n"); list.removeAll(this->_ui->lblUsername->text()); @@ -120,10 +108,9 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) this->_ui->disableHighlights->show(); }); - - updateButtons(this->_ui->userLayout,false); - updateButtons(this->_ui->modLayout,false); - updateButtons(this->_ui->ownerLayout,false); + updateButtons(this->_ui->userLayout, false); + updateButtons(this->_ui->modLayout, false); + updateButtons(this->_ui->ownerLayout, false); // Close button connect(_ui->btnClose, &QPushButton::clicked, [=]() { @@ -131,9 +118,7 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr channel) }); util::twitch::getUserID(userNickname, this, - [=](const QString &id){ - currentTwitchUser->setUserId(id); - }); + [=](const QString &id) { currentTwitchUser->setUserId(id); }); } void AccountPopupWidget::setName(const QString &name) @@ -149,7 +134,7 @@ void AccountPopupWidget::setChannel(std::shared_ptr channel) void AccountPopupWidget::getUserId() { - util::twitch::getUserID(this->_ui->lblUsername->text(), this, [=](const QString &id){ + util::twitch::getUserID(this->_ui->lblUsername->text(), this, [=](const QString &id) { userID = id; getUserData(); }); @@ -157,13 +142,14 @@ void AccountPopupWidget::getUserId() void AccountPopupWidget::getUserData() { - util::twitch::get("https://api.twitch.tv/kraken/channels/" + userID, this, [=](const QJsonObject &obj){ - _ui->lblFollowers->setText(QString::number(obj.value("followers").toInt())); - _ui->lblViews->setText(QString::number(obj.value("views").toInt())); - _ui->lblAccountAge->setText(obj.value("created_at").toString().section("T", 0, 0)); + util::twitch::get( + "https://api.twitch.tv/kraken/channels/" + userID, this, [=](const QJsonObject &obj) { + _ui->lblFollowers->setText(QString::number(obj.value("followers").toInt())); + _ui->lblViews->setText(QString::number(obj.value("views").toInt())); + _ui->lblAccountAge->setText(obj.value("created_at").toString().section("T", 0, 0)); - loadAvatar(QUrl(obj.value("logo").toString())); - }); + loadAvatar(QUrl(obj.value("logo").toString())); + }); } void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl) @@ -201,36 +187,33 @@ void AccountPopupWidget::updatePermissions() return; } - if(this->_channel.get()->name == currentTwitchUser->getNickName()) - { + if (this->_channel.get()->name == currentTwitchUser->getNickName()) { permission = permissions::Owner; - } - else if(this->_channel->modList.contains(currentTwitchUser->getNickName())) - { + } else if (this->_channel->modList.contains(currentTwitchUser->getNickName())) { // XXX(pajlada): This might always trigger if user is anonymous (if nickName is empty?) permission = permissions::Mod; } } -void AccountPopupWidget::updateButtons(QWidget* layout, bool state) +void AccountPopupWidget::updateButtons(QWidget *layout, bool state) { - for(auto button : layout->findChildren()) - { + for (auto button : layout->findChildren()) { button->setVisible(state); } } void AccountPopupWidget::timeout(QPushButton *button, int time) { - QObject::connect(button, &QPushButton::clicked, this, [=](){ - this->_channel->sendMessage("/timeout " + this->_ui->lblUsername->text() + " " + QString::number(time)); + QObject::connect(button, &QPushButton::clicked, this, [=]() { + this->_channel->sendMessage("/timeout " + this->_ui->lblUsername->text() + " " + + QString::number(time)); }); } void AccountPopupWidget::sendCommand(QPushButton *button, QString command) { - QObject::connect(button, &QPushButton::clicked, this, [=](){ - this->_channel->sendMessage(command + this->_ui->lblUsername->text()); + QObject::connect(button, &QPushButton::clicked, this, [=]() { + this->_channel->sendMessage(command + this->_ui->lblUsername->text()); }); } @@ -253,42 +236,32 @@ void AccountPopupWidget::showEvent(QShowEvent *event) return; } - if(this->_ui->lblUsername->text() != currentTwitchUser->getNickName()) - { + if (this->_ui->lblUsername->text() != currentTwitchUser->getNickName()) { updateButtons(this->_ui->userLayout, true); - if(permission != permissions::User) - { - if(!this->_channel->modList.contains(this->_ui->lblUsername->text())) - { + if (permission != permissions::User) { + if (!this->_channel->modList.contains(this->_ui->lblUsername->text())) { updateButtons(this->_ui->modLayout, true); } - if(permission == permissions::Owner) - { + if (permission == permissions::Owner) { updateButtons(this->_ui->ownerLayout, true); updateButtons(this->_ui->modLayout, true); } } - } - else - { + } else { updateButtons(this->_ui->modLayout, false); updateButtons(this->_ui->userLayout, false); updateButtons(this->_ui->ownerLayout, false); } QString blacklisted = SettingsManager::getInstance().highlightUserBlacklist.getnonConst(); - QStringList list = blacklisted.split("\n",QString::SkipEmptyParts); - if(list.contains(this->_ui->lblUsername->text(),Qt::CaseInsensitive)) - { + QStringList list = blacklisted.split("\n", QString::SkipEmptyParts); + if (list.contains(this->_ui->lblUsername->text(), Qt::CaseInsensitive)) { this->_ui->disableHighlights->hide(); this->_ui->enableHighlights->show(); - } - else - { + } else { this->_ui->disableHighlights->show(); this->_ui->enableHighlights->hide(); } - } } // namespace widgets diff --git a/src/widgets/accountpopup.hpp b/src/widgets/accountpopup.hpp index 8b89ab184..e5eee9cb8 100644 --- a/src/widgets/accountpopup.hpp +++ b/src/widgets/accountpopup.hpp @@ -1,4 +1,5 @@ #pragma once + #include "concurrentmap.hpp" #include "twitch/twitchchannel.hpp" @@ -35,9 +36,9 @@ private: void getUserData(); void loadAvatar(const QUrl &avatarUrl); - void updateButtons(QWidget* layout, bool state); - void timeout(QPushButton* button, int time); - void sendCommand(QPushButton* button, QString command); + void updateButtons(QWidget *layout, bool state); + void timeout(QPushButton *button, int time); + void sendCommand(QPushButton *button, QString command); enum class permissions { User, Mod, Owner }; permissions permission; diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index b1f1c14fd..75e234b67 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -135,7 +135,8 @@ QVBoxLayout *SettingsDialog::createAccountsTab() // Select the currently logged in user if (listWidget->count() > 0) { - const QString ¤tUsername = AccountManager::getInstance().Twitch.getCurrent()->getUserName(); + const QString ¤tUsername = + AccountManager::getInstance().Twitch.getCurrent()->getUserName(); for (int i = 0; i < listWidget->count(); ++i) { QString itemText = listWidget->item(i)->text(); if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) {