Added some functionality to the accountPopup (#117)
* Added some buttons. * Added some more functionality. * Finished adding button functionality. * Implemented @fourtf's suggestions.
This commit is contained in:
+176
-45
@@ -1,9 +1,14 @@
|
||||
#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 <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@@ -25,10 +30,98 @@ AccountPopupWidget::AccountPopupWidget(std::shared_ptr<Channel> channel)
|
||||
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
|
||||
SettingsManager &settings = SettingsManager::getInstance();
|
||||
|
||||
permission = permissions::User;
|
||||
for(auto button : this->_ui->profileLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->userLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->modLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
for(auto button: this->_ui->ownerLayout->findChildren<QPushButton*>())
|
||||
{
|
||||
button->setFocusProxy(this);
|
||||
}
|
||||
|
||||
timeout(this->_ui->purge, 1);
|
||||
timeout(this->_ui->min1, 60);
|
||||
timeout(this->_ui->min10, 600);
|
||||
timeout(this->_ui->hour1, 3600);
|
||||
timeout(this->_ui->hour24, 86400);
|
||||
|
||||
sendCommand(this->_ui->ban, "/ban ");
|
||||
sendCommand(this->_ui->unBan, "/unban ");
|
||||
sendCommand(this->_ui->mod, "/mod ");
|
||||
sendCommand(this->_ui->unMod, "/unmod ");
|
||||
|
||||
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->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/" +
|
||||
AccountManager::getInstance().getTwitchUser().getUserId() +
|
||||
"/follows/channels/" + this->userID);
|
||||
|
||||
util::twitch::put(requestUrl,[](QJsonObject obj){});
|
||||
});
|
||||
|
||||
QObject::connect(this->_ui->ignore, &QPushButton::clicked, this, [=](){
|
||||
QUrl requestUrl("https://api.twitch.tv/kraken/users/" +
|
||||
AccountManager::getInstance().getTwitchUser().getUserId() +
|
||||
"/blocks/" + this->userID);
|
||||
|
||||
util::twitch::put(requestUrl,[](QJsonObject obj){});
|
||||
});
|
||||
|
||||
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);
|
||||
this->_ui->disableHighlights->hide();
|
||||
this->_ui->enableHighlights->show();
|
||||
});
|
||||
|
||||
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());
|
||||
settings.highlightUserBlacklist.set(list.join("\n"));
|
||||
this->_ui->enableHighlights->hide();
|
||||
this->_ui->disableHighlights->show();
|
||||
});
|
||||
|
||||
|
||||
updateButtons(this->_ui->userLayout,false);
|
||||
updateButtons(this->_ui->modLayout,false);
|
||||
updateButtons(this->_ui->ownerLayout,false);
|
||||
|
||||
// Close button
|
||||
connect(_ui->btnClose, &QPushButton::clicked, [=]() {
|
||||
hide(); //
|
||||
});
|
||||
|
||||
util::twitch::getUserID(AccountManager::getInstance().getTwitchUser().getNickName(),
|
||||
[=](const QString &id){
|
||||
AccountManager::getInstance().getTwitchUser().setUserId(id);
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::setName(const QString &name)
|
||||
@@ -44,55 +137,20 @@ void AccountPopupWidget::setChannel(std::shared_ptr<Channel> channel)
|
||||
|
||||
void AccountPopupWidget::getUserId()
|
||||
{
|
||||
qDebug() << this->_channel.get()->name;
|
||||
QUrl nameUrl("https://api.twitch.tv/kraken/users?login=" + _ui->lblUsername->text());
|
||||
|
||||
QNetworkRequest req(nameUrl);
|
||||
req.setRawHeader(QByteArray("Accept"), QByteArray("application/vnd.twitchtv.v5+json"));
|
||||
req.setRawHeader(QByteArray("Client-ID"), getDefaultClientID());
|
||||
|
||||
static auto manager = new QNetworkAccessManager();
|
||||
auto *reply = manager->get(req);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [=] {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
auto doc = QJsonDocument::fromJson(reply->readAll());
|
||||
auto obj = doc.object();
|
||||
auto array = obj.value("users").toArray();
|
||||
|
||||
userID = array.at(0).toObject().value("_id").toString();
|
||||
|
||||
getUserData();
|
||||
}
|
||||
util::twitch::getUserID(this->_ui->lblUsername->text(),[=](const QString &id){
|
||||
userID = id;
|
||||
getUserData();
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::getUserData()
|
||||
{
|
||||
QUrl idUrl("https://api.twitch.tv/kraken/channels/" + userID);
|
||||
util::twitch::get("https://api.twitch.tv/kraken/channels/" + userID,[=](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));
|
||||
|
||||
QNetworkRequest req(idUrl);
|
||||
req.setRawHeader(QByteArray("Accept"), QByteArray("application/vnd.twitchtv.v5+json"));
|
||||
req.setRawHeader(QByteArray("Client-ID"), getDefaultClientID());
|
||||
|
||||
static auto manager = new QNetworkAccessManager();
|
||||
auto *reply = manager->get(req);
|
||||
|
||||
QObject::connect(reply, &QNetworkReply::finished, this, [=] {
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
auto doc = QJsonDocument::fromJson(reply->readAll());
|
||||
auto obj = doc.object();
|
||||
|
||||
_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()));
|
||||
} else {
|
||||
_ui->lblFollowers->setText("ERROR");
|
||||
_ui->lblViews->setText("ERROR");
|
||||
_ui->lblAccountAge->setText("ERROR");
|
||||
}
|
||||
loadAvatar(QUrl(obj.value("logo").toString()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,10 +180,43 @@ void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPopupWidget::updatePermissions()
|
||||
{
|
||||
if(this->_channel.get()->name == AccountManager::getInstance().getTwitchUser().getNickName())
|
||||
{
|
||||
permission = permissions::Owner;
|
||||
}
|
||||
else if(this->_channel->modList.contains(AccountManager::getInstance().getTwitchUser().getNickName()))
|
||||
{
|
||||
permission = permissions::Mod;
|
||||
}
|
||||
}
|
||||
|
||||
void AccountPopupWidget::updateButtons(QWidget* layout, bool state)
|
||||
{
|
||||
for(auto button : layout->findChildren<QPushButton*>())
|
||||
{
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::sendCommand(QPushButton *button, QString command)
|
||||
{
|
||||
QObject::connect(button, &QPushButton::clicked, this, [=](){
|
||||
this->_channel->sendMessage(command + this->_ui->lblUsername->text());
|
||||
});
|
||||
}
|
||||
|
||||
void AccountPopupWidget::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
hide();
|
||||
|
||||
this->hide();
|
||||
_ui->lblFollowers->setText("Loading...");
|
||||
_ui->lblViews->setText("Loading...");
|
||||
_ui->lblAccountAge->setText("Loading...");
|
||||
@@ -133,5 +224,45 @@ void AccountPopupWidget::focusOutEvent(QFocusEvent *event)
|
||||
_ui->lblAvatar->setText("Loading...");
|
||||
}
|
||||
|
||||
void AccountPopupWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
if(this->_ui->lblUsername->text() != AccountManager::getInstance().getTwitchUser().getNickName())
|
||||
{
|
||||
updateButtons(this->_ui->userLayout, true);
|
||||
if(permission != permissions::User)
|
||||
{
|
||||
if(!this->_channel->modList.contains(this->_ui->lblUsername->text()))
|
||||
{
|
||||
updateButtons(this->_ui->modLayout, true);
|
||||
}
|
||||
if(permission == permissions::Owner)
|
||||
{
|
||||
updateButtons(this->_ui->ownerLayout, true);
|
||||
updateButtons(this->_ui->modLayout, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
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))
|
||||
{
|
||||
this->_ui->disableHighlights->hide();
|
||||
this->_ui->enableHighlights->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->_ui->disableHighlights->show();
|
||||
this->_ui->enableHighlights->hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "concurrentmap.hpp"
|
||||
#include "twitch/twitchchannel.hpp"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
#include <memory>
|
||||
@@ -24,6 +26,8 @@ public:
|
||||
void setName(const QString &name);
|
||||
void setChannel(std::shared_ptr<Channel> channel);
|
||||
|
||||
void updatePermissions();
|
||||
|
||||
private:
|
||||
Ui::AccountPopup *_ui;
|
||||
|
||||
@@ -31,6 +35,13 @@ 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);
|
||||
|
||||
enum class permissions { User, Mod, Owner };
|
||||
permissions permission;
|
||||
|
||||
std::shared_ptr<Channel> _channel;
|
||||
|
||||
QString userID;
|
||||
@@ -40,6 +51,7 @@ private:
|
||||
|
||||
protected:
|
||||
virtual void focusOutEvent(QFocusEvent *event) override;
|
||||
virtual void showEvent(QShowEvent *event) override;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
|
||||
@@ -30,7 +30,7 @@ ChannelView::ChannelView(WindowManager &windowManager, BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
, windowManager(windowManager)
|
||||
, scrollBar(this)
|
||||
, userPopupWidget(std::shared_ptr<Channel>())
|
||||
, userPopupWidget(std::shared_ptr<twitch::TwitchChannel>())
|
||||
{
|
||||
#ifndef Q_OS_MAC
|
||||
// this->setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
@@ -787,6 +787,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||
auto user = link.getValue();
|
||||
this->userPopupWidget.setName(user);
|
||||
this->userPopupWidget.move(event->screenPos().toPoint());
|
||||
this->userPopupWidget.updatePermissions();
|
||||
this->userPopupWidget.show();
|
||||
this->userPopupWidget.setFocus();
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ void ChatWidget::doChangeChannel()
|
||||
{
|
||||
this->showChangeChannelPopup("Change channel");
|
||||
auto popup = this->findChildren<QDockWidget *>();
|
||||
if (popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
|
||||
if (popup.size() && popup.at(0)->isVisible() && !popup.at(0)->isFloating()) {
|
||||
popup.at(0)->hide();
|
||||
doOpenViewerList();
|
||||
}
|
||||
@@ -426,6 +426,7 @@ void ChatWidget::doOpenAccountPopupWidget(AccountPopupWidget *widget, QString us
|
||||
{
|
||||
widget->setName(user);
|
||||
widget->move(QCursor::pos());
|
||||
widget->updatePermissions();
|
||||
widget->show();
|
||||
widget->setFocus();
|
||||
}
|
||||
|
||||
@@ -379,9 +379,12 @@ void SettingsDialog::addTabs()
|
||||
// Highlighting
|
||||
vbox = new QVBoxLayout();
|
||||
auto highlights = new QListWidget();
|
||||
auto highlightUserBlacklist = new QTextEdit();
|
||||
globalHighlights = highlights;
|
||||
QStringList items = settings.highlightProperties.get().keys();
|
||||
highlights->addItems(items);
|
||||
highlightUserBlacklist->setText(settings.highlightUserBlacklist.getnonConst());
|
||||
auto highlightTab = new QTabWidget();
|
||||
auto customSound = new QHBoxLayout();
|
||||
auto soundForm = new QFormLayout();
|
||||
{
|
||||
@@ -404,6 +407,7 @@ void SettingsDialog::addTabs()
|
||||
|
||||
soundForm->addRow(customSound);
|
||||
|
||||
|
||||
{
|
||||
auto hbox = new QHBoxLayout();
|
||||
auto addBtn = new QPushButton("Add");
|
||||
@@ -480,14 +484,38 @@ void SettingsDialog::addTabs()
|
||||
}
|
||||
});
|
||||
vbox->addLayout(soundForm);
|
||||
vbox->addWidget(highlights);
|
||||
auto layoutVbox = new QVBoxLayout();
|
||||
auto btnHbox = new QHBoxLayout();
|
||||
|
||||
hbox->addWidget(addBtn);
|
||||
hbox->addWidget(editBtn);
|
||||
hbox->addWidget(delBtn);
|
||||
auto highlightWidget = new QWidget();
|
||||
auto btnWidget = new QWidget();
|
||||
|
||||
btnHbox->addWidget(addBtn);
|
||||
btnHbox->addWidget(editBtn);
|
||||
btnHbox->addWidget(delBtn);
|
||||
btnWidget->setLayout(btnHbox);
|
||||
|
||||
layoutVbox->addWidget(highlights);
|
||||
layoutVbox->addWidget(btnWidget);
|
||||
highlightWidget->setLayout(layoutVbox);
|
||||
|
||||
highlightTab->addTab(highlightWidget,"Highlights");
|
||||
highlightTab->addTab(highlightUserBlacklist,"Disabled Users");
|
||||
vbox->addWidget(highlightTab);
|
||||
|
||||
vbox->addLayout(hbox);
|
||||
}
|
||||
|
||||
QObject::connect(&this->ui.okButton, &QPushButton::clicked, this, [=, &settings](){
|
||||
QStringList list = highlightUserBlacklist->toPlainText().split("\n",QString::SkipEmptyParts);
|
||||
list.removeDuplicates();
|
||||
settings.highlightUserBlacklist.set(list.join("\n") + "\n");
|
||||
});
|
||||
|
||||
settings.highlightUserBlacklist.valueChanged.connect([=](const QString &str){
|
||||
highlightUserBlacklist->setPlainText(str);
|
||||
});
|
||||
|
||||
vbox->addStretch(1);
|
||||
addTab(vbox, "Highlighting", ":/images/format_Bold_16xLG.png");
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ public:
|
||||
void select(SettingsDialogTab *tab);
|
||||
|
||||
static void showDialog();
|
||||
|
||||
private:
|
||||
SettingsSnapshot snapshot;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user