From 54166ec130b8242b62f0a90113c88a4142df253a Mon Sep 17 00:00:00 2001 From: apa420 Date: Sun, 12 Aug 2018 15:29:40 +0200 Subject: [PATCH] temp stuff --- .../notifications/NotificationController.cpp | 87 +++++++++++++------ .../notifications/NotificationController.hpp | 24 +++-- src/providers/twitch/TwitchChannel.cpp | 58 ++++++++++++- src/providers/twitch/TwitchChannel.hpp | 2 + src/singletons/Toasts.cpp | 12 +-- src/singletons/Toasts.hpp | 9 +- .../settingspages/NotificationPage.cpp | 36 ++++++-- src/widgets/splits/SplitHeader.cpp | 7 +- 8 files changed, 185 insertions(+), 50 deletions(-) diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index 3dcd13901..e6f6fac1d 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -14,38 +14,68 @@ namespace chatterino { void NotificationController::initialize(Settings &settings, Paths &paths) { this->initialized_ = true; - for (const QString &channelName : this->notificationSetting_.getValue()) { - this->notificationVector.appendItem(channelName); + for (const QString &channelName : this->twitchSetting_.getValue()) { + this->twitchVector.appendItem(channelName); } - this->notificationVector.delayedItemsChanged.connect([this] { // - this->notificationSetting_.setValue( - this->notificationVector.getVector()); + this->twitchVector.delayedItemsChanged.connect([this] { // + this->twitchSetting_.setValue(this->twitchVector.getVector()); + }); + + for (const QString &channelName : this->mixerSetting_.getValue()) { + this->mixerVector.appendItem(channelName); + } + + this->mixerVector.delayedItemsChanged.connect([this] { // + this->mixerSetting_.setValue(this->mixerVector.getVector()); }); } void NotificationController::updateChannelNotification( - const QString &channelName) + const QString &channelName, int &i) { - if (isChannelNotified(channelName)) { - removeChannelNotification(channelName); - } else { - addChannelNotification(channelName); + if (i == 0) { + int j = 0; + if (isChannelNotified(channelName, j)) { + removeChannelNotification(channelName, twitchVector); + } else { + addChannelNotification(channelName, twitchVector); + } + } else if (i == 1) { + int k = 1; + if (isChannelNotified(channelName, k)) { + removeChannelNotification(channelName, mixerVector); + } else { + addChannelNotification(channelName, mixerVector); + } } } -bool NotificationController::isChannelNotified(const QString &channelName) +bool NotificationController::isChannelNotified(const QString &channelName, + int &i) { + /* for (std::vector::size_type i = 0; i != notificationVector.getVector().size(); i++) { qDebug() << notificationVector.getVector()[i] << " vector to the left channel to the right " << channelName << " vectorsize:" << notificationVector.getVector().size(); } - for (std::vector::size_type i = 0; - i != notificationVector.getVector().size(); i++) { - if (notificationVector.getVector()[i] == channelName) { - return true; + */ + qDebug() << channelName << " channel and now i: " << i; + if (i == 0) { + for (std::vector::size_type i = 0; + i != twitchVector.getVector().size(); i++) { + if (twitchVector.getVector()[i] == channelName) { + return true; + } + } + } else if (i == 1) { + for (std::vector::size_type i = 0; + i != mixerVector.getVector().size(); i++) { + if (mixerVector.getVector()[i] == channelName) { + return true; + } } } return false; @@ -92,13 +122,14 @@ public: } }; */ -void NotificationController::addChannelNotification(const QString &channelName) +void NotificationController::addChannelNotification( + const QString &channelName, UnsortedSignalVector &vector) { - notificationVector.appendItem(channelName); + vector.appendItem(channelName); if (WinToastLib::WinToast::isCompatible()) { - QDir dir; - qDebug() << "NaM" << dir.absolutePath(); + // QDir dir; + // qDebug() << "NaM" << dir.absolutePath(); /* WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( @@ -122,21 +153,25 @@ void NotificationController::addChannelNotification(const QString &channelName) } void NotificationController::removeChannelNotification( - const QString &channelName) + const QString &channelName, UnsortedSignalVector &vector) { - for (std::vector::size_type i = 0; - i != notificationVector.getVector().size(); i++) { - if (notificationVector.getVector()[i] == channelName) { - notificationVector.removeItem(i); + for (std::vector::size_type i = 0; i != vector.getVector().size(); + i++) { + if (vector.getVector()[i] == channelName) { + vector.removeItem(i); i--; } } } -NotificationModel *NotificationController::createModel(QObject *parent) +NotificationModel *NotificationController::createModel(QObject *parent, int &i) { NotificationModel *model = new NotificationModel(parent); - model->init(&this->notificationVector); + if (i == 0) { + model->init(&this->twitchVector); + } else if (i == 1) { + model->init(&this->mixerVector); + } return model; } diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index fb5c71cfc..d2fc87e36 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -15,21 +15,27 @@ class NotificationController final : public Singleton public: virtual void initialize(Settings &settings, Paths &paths) override; - bool isChannelNotified(const QString &channelName); + bool isChannelNotified(const QString &channelName, int &i); - void updateChannelNotification(const QString &channelName); - void addChannelNotification(const QString &channelName); - void removeChannelNotification(const QString &channelName); + void updateChannelNotification(const QString &channelName, int &i); + void addChannelNotification(const QString &channelName, + UnsortedSignalVector &vector); + void removeChannelNotification(const QString &channelName, + UnsortedSignalVector &vector); - UnsortedSignalVector notificationVector; + UnsortedSignalVector getVector(int &i); - NotificationModel *createModel(QObject *parent); + UnsortedSignalVector twitchVector; + UnsortedSignalVector mixerVector; + + NotificationModel *createModel(QObject *parent, int &i); private: bool initialized_ = false; - - ChatterinoSetting> notificationSetting_ = { - "/notifications/channels"}; + ChatterinoSetting> twitchSetting_ = { + "/notifications/twitch"}; + ChatterinoSetting> mixerSetting_ = { + "/notifications/mixer"}; }; } // namespace chatterino diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 8ec998774..ce4324388 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -3,6 +3,7 @@ #include "common/Common.hpp" #include "common/NetworkRequest.hpp" #include "controllers/accounts/AccountController.hpp" +#include "controllers/notifications/NotificationController.hpp" #include "debug/Log.hpp" #include "messages/Message.hpp" #include "providers/bttv/LoadBttvChannelEmote.hpp" @@ -12,6 +13,7 @@ #include "providers/twitch/TwitchParseCheerEmotes.hpp" #include "singletons/Emotes.hpp" #include "singletons/Settings.hpp" +#include "singletons/Toasts.hpp" #include "util/PostToThread.hpp" #include @@ -303,6 +305,19 @@ const QString &TwitchChannel::getPopoutPlayerUrl() return this->popoutPlayerUrl_; } +bool Toasts::isEnabled(const QString &channelName) +{ + int i = 0; + return getApp()->notifications->isChannelNotified(channelName, i); +} +/* +bool toastIsEnabled() +{ + QString channelName = this->getName(); + return getApp()->notifications->isChannelNotified(channelName); +} +*/ + void TwitchChannel::setLive(bool newLiveStatus) { bool gotNewLiveStatus = false; @@ -319,6 +334,40 @@ void TwitchChannel::setLive(bool newLiveStatus) } } +/* +void TwitchChannel::setLive(bool newLiveStatus) +{ + // auto guard = this->streamStatus_.access(); + + if (toastIsEnabled() && guard->live != newLiveStatus && guard->live != + newLiveStatus) { Toasts::show + } + + // int i = 0; + // getApp()->toasts->sendChannelNotification(this->getName(), i); + qDebug() << "setLive called here and channel: " << this->getName() + << " status: " << newLiveStatus; + + bool gotNewLiveStatus = false; + { + auto guard = this->streamStatus_.access(); + if (guard->live != newLiveStatus) { + gotNewLiveStatus = true; + guard->live = newLiveStatus; + + if (getApp()->toasts->isEnabled(this->getName()) && + guard->live == true) { + int i = 0; + getApp()->toasts->sendChannelNotification(this->getName(), i); + } + } + } + + if (gotNewLiveStatus) { + this->liveStatusChanged.invoke(); + } +} +*/ void TwitchChannel::refreshLiveStatus() { auto roomID = this->getRoomId(); @@ -391,10 +440,17 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) { auto status = this->streamStatus_.access(); - if (!status->live /*&&*/) { + /* + if (!status->live == false && + getApp()->toasts->isEnabled(this->getName())) { + int i = 0; + getApp()->toasts->sendChannelNotification(this->getName(), i); // notifcation send } status->live = true; + */ + this->setLive(true); + // status->live = true; status->viewerCount = stream["viewers"].GetUint(); status->game = stream["game"].GetString(); status->title = streamChannel["status"].GetString(); diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index fa5746bf7..000b1bbec 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -118,6 +118,8 @@ private: void loadRecentMessages(); Outcome parseRecentMessages(const QJsonObject &jsonRoot); + bool toastIsEnabled(); + void setLive(bool newLiveStatus); void loadBadges(); diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index e49bdccf6..31f9931ee 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -14,10 +14,12 @@ namespace chatterino { +/* Toasts::Toasts() { } - +*/ +/* void Toasts::initialize(Settings &settings, Paths &paths) { getApp()->twitch2->forEachChannel([this](ChannelPtr chn) { @@ -67,12 +69,12 @@ bool Toasts::wasChannelLive(const QString &channelName) } return false; } - -void Toasts::sendChannelNotification(const QString &channelName) +*/ +void Toasts::sendChannelNotification(const QString &channelName, int &platform) { #ifdef Q_OS_WIN if (WinToastLib::WinToast::isCompatible()) { - sendWindowsNotification(channelName); + sendWindowsNotification(channelName, platform); } #endif // OSX @@ -125,7 +127,7 @@ public: } }; -void Toasts::sendWindowsNotification(const QString &channelName) +void Toasts::sendWindowsNotification(const QString &channelName, int &platform) { WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( WinToastLib::WinToastTemplate::ImageAndText02); diff --git a/src/singletons/Toasts.hpp b/src/singletons/Toasts.hpp index c47728dc0..0fc7dad29 100644 --- a/src/singletons/Toasts.hpp +++ b/src/singletons/Toasts.hpp @@ -3,17 +3,23 @@ #include "Application.hpp" #include "common/Singleton.hpp" -#include +//#include namespace chatterino { class Toasts final : public Singleton { public: + void sendChannelNotification(const QString &channelName, int &platform); + bool isEnabled(const QString &channelName); + /* Toasts(); virtual void initialize(Settings &settings, Paths &paths) override final; + */ private: + void sendWindowsNotification(const QString &channelName, int &platform); + /* void updateLiveChannels(const QString &channelName); void removeFromLiveChannels(const QString &channelName); @@ -24,5 +30,6 @@ private: void sendWindowsNotification(const QString &channelName); std::vector liveChannels; std::mutex mutex_; + */ }; } // namespace chatterino diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp index 77ba20d01..50e52725f 100644 --- a/src/widgets/settingspages/NotificationPage.cpp +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -38,14 +38,15 @@ NotificationPage::NotificationPage() settings->addStretch(1); } - auto channels = tabs.appendTab(new QVBoxLayout, "Channels"); + auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch"); { + int i = 0; EditableModelView *view = - channels + twitchChannels .emplace( - getApp()->notifications->createModel(nullptr)) + getApp()->notifications->createModel(nullptr, i)) .getElement(); - view->setTitles({"Channels"}); + view->setTitles({"Twitch channels"}); view->getTableView()->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed); @@ -58,8 +59,31 @@ NotificationPage::NotificationPage() }); view->addButtonPressed.connect([] { - getApp()->notifications->notificationVector.appendItem( - "channel"); + getApp()->notifications->twitchVector.appendItem("channel"); + }); + } + auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer"); + { + int i = 1; + EditableModelView *view = + mixerChannels + .emplace( + getApp()->notifications->createModel(nullptr, i)) + .getElement(); + view->setTitles({"Mixer channels"}); + + view->getTableView()->horizontalHeader()->setSectionResizeMode( + QHeaderView::Fixed); + view->getTableView()->horizontalHeader()->setSectionResizeMode( + 0, QHeaderView::Stretch); + + QTimer::singleShot(1, [view] { + view->getTableView()->resizeColumnsToContents(); + view->getTableView()->setColumnWidth(0, 200); + }); + + view->addButtonPressed.connect([] { + getApp()->notifications->mixerVector.appendItem("channel"); }); } } diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 4c12be61a..38682ad12 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -159,13 +159,16 @@ std::unique_ptr SplitHeader::createMainMenu() auto action = new QAction(this); action->setText("Notify when live"); action->setCheckable(true); + QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() { + int i = 0; action->setChecked(getApp()->notifications->isChannelNotified( - this->split_->getChannel()->getName())); + this->split_->getChannel()->getName(), i)); }); action->connect(action, &QAction::triggered, this, [this]() { + int i = 0; getApp()->notifications->updateChannelNotification( - this->split_->getChannel()->getName()); + this->split_->getChannel()->getName(), i); }); menu->addAction(action);