From 05d5709bb99635a48d6f5a9dfb982abea00eddaf Mon Sep 17 00:00:00 2001 From: apa420 Date: Sun, 12 Aug 2018 18:54:32 +0200 Subject: [PATCH] stuff does compile --- .../notifications/NotificationController.cpp | 27 ++++--- .../notifications/NotificationController.hpp | 14 +++- src/providers/twitch/TwitchChannel.cpp | 73 +++++-------------- src/singletons/Settings.hpp | 1 + src/singletons/Toasts.cpp | 21 ++++-- src/singletons/Toasts.hpp | 8 +- .../settingspages/NotificationPage.cpp | 11 ++- src/widgets/splits/SplitHeader.cpp | 6 +- 8 files changed, 73 insertions(+), 88 deletions(-) diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index e6f6fac1d..72624991f 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -32,18 +32,16 @@ void NotificationController::initialize(Settings &settings, Paths &paths) } void NotificationController::updateChannelNotification( - const QString &channelName, int &i) + const QString &channelName, Platform p) { - if (i == 0) { - int j = 0; - if (isChannelNotified(channelName, j)) { + if (p == Platform::Twitch) { + if (isChannelNotified(channelName, Platform::Twitch)) { removeChannelNotification(channelName, twitchVector); } else { addChannelNotification(channelName, twitchVector); } - } else if (i == 1) { - int k = 1; - if (isChannelNotified(channelName, k)) { + } else if (p == Platform::Mixer) { + if (isChannelNotified(channelName, Platform::Mixer)) { removeChannelNotification(channelName, mixerVector); } else { addChannelNotification(channelName, mixerVector); @@ -52,7 +50,7 @@ void NotificationController::updateChannelNotification( } bool NotificationController::isChannelNotified(const QString &channelName, - int &i) + Platform p) { /* for (std::vector::size_type i = 0; @@ -62,15 +60,15 @@ bool NotificationController::isChannelNotified(const QString &channelName, << " vectorsize:" << notificationVector.getVector().size(); } */ - qDebug() << channelName << " channel and now i: " << i; - if (i == 0) { + // qDebug() << channelName << " channel and now i: " << i; + if (p == Platform::Twitch) { for (std::vector::size_type i = 0; i != twitchVector.getVector().size(); i++) { if (twitchVector.getVector()[i] == channelName) { return true; } } - } else if (i == 1) { + } else if (p == Platform::Mixer) { for (std::vector::size_type i = 0; i != mixerVector.getVector().size(); i++) { if (mixerVector.getVector()[i] == channelName) { @@ -164,12 +162,13 @@ void NotificationController::removeChannelNotification( } } -NotificationModel *NotificationController::createModel(QObject *parent, int &i) +NotificationModel *NotificationController::createModel(QObject *parent, + Platform p) { NotificationModel *model = new NotificationModel(parent); - if (i == 0) { + if (p == Platform::Twitch) { model->init(&this->twitchVector); - } else if (i == 1) { + } else if (p == Platform::Mixer) { model->init(&this->mixerVector); } return model; diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp index d2fc87e36..8e7a5c974 100644 --- a/src/controllers/notifications/NotificationController.hpp +++ b/src/controllers/notifications/NotificationController.hpp @@ -10,25 +10,31 @@ class Paths; class NotificationModel; +enum class Platform : uint8_t { + Twitch = 0, // 0 + Mixer = 1, // 1 + HitBox = 2, // 2 +}; + class NotificationController final : public Singleton { public: virtual void initialize(Settings &settings, Paths &paths) override; - bool isChannelNotified(const QString &channelName, int &i); + bool isChannelNotified(const QString &channelName, Platform p); - void updateChannelNotification(const QString &channelName, int &i); + void updateChannelNotification(const QString &channelName, Platform p); void addChannelNotification(const QString &channelName, UnsortedSignalVector &vector); void removeChannelNotification(const QString &channelName, UnsortedSignalVector &vector); - UnsortedSignalVector getVector(int &i); + UnsortedSignalVector getVector(Platform p); UnsortedSignalVector twitchVector; UnsortedSignalVector mixerVector; - NotificationModel *createModel(QObject *parent, int &i); + NotificationModel *createModel(QObject *parent, Platform p); private: bool initialized_ = false; diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index ce4324388..49147c071 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -305,19 +305,6 @@ 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; @@ -325,41 +312,21 @@ void TwitchChannel::setLive(bool newLiveStatus) auto guard = this->streamStatus_.access(); if (guard->live != newLiveStatus) { gotNewLiveStatus = true; - guard->live = newLiveStatus; - } - } - - if (gotNewLiveStatus) { - this->liveStatusChanged.invoke(); - } -} - -/* -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 (Toasts::isEnabled() && + getApp()->notifications->isChannelNotified(this->getName(), + Platform::Twitch)) { + getApp()->toasts->sendChannelNotification(this->getName(), + Platform::Twitch); } + /* + if (!guard->live && Toasts::isEnabled() && + getApp()->notifications->isChannelNotified( this->getName(), + Platform::Twitch)) { + getApp()->toasts->sendChannelNotification(this->getName(), + Platform::Twitch); + } + */ + guard->live = newLiveStatus; } } @@ -367,7 +334,7 @@ void TwitchChannel::setLive(bool newLiveStatus) this->liveStatusChanged.invoke(); } } -*/ + void TwitchChannel::refreshLiveStatus() { auto roomID = this->getRoomId(); @@ -441,15 +408,13 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) { auto status = this->streamStatus_.access(); /* - if (!status->live == false && - getApp()->toasts->isEnabled(this->getName())) { + if (!(status->live) && getApp()->toasts->isEnabled(this->getName())) { + qDebug() << " NaM xd NaM "; 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(); @@ -479,7 +444,7 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) } } } - + setLive(true); // Signal all listeners that the stream status has been updated this->liveStatusChanged.invoke(); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 501c43287..f23189e11 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -144,6 +144,7 @@ public: false}; BoolSetting notificationPlaySound = {"/notifications/enablePlaySound", false}; + BoolSetting notificationToast = {"/notifications/enableToast", false}; /// External tools // Streamlink diff --git a/src/singletons/Toasts.cpp b/src/singletons/Toasts.cpp index 31f9931ee..54285e009 100644 --- a/src/singletons/Toasts.cpp +++ b/src/singletons/Toasts.cpp @@ -5,8 +5,12 @@ #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchServer.hpp" +#ifdef Q_OS_WIN + #include +#endif + #include #include @@ -70,12 +74,19 @@ bool Toasts::wasChannelLive(const QString &channelName) return false; } */ -void Toasts::sendChannelNotification(const QString &channelName, int &platform) +bool Toasts::isEnabled() +{ + return WinToastLib::WinToast::isCompatible() && + getApp()->settings->notificationToast; +} + +void Toasts::sendChannelNotification(const QString &channelName, Platform p) { #ifdef Q_OS_WIN - if (WinToastLib::WinToast::isCompatible()) { - sendWindowsNotification(channelName, platform); - } + + sendWindowsNotification(channelName, p); + return; + #endif // OSX @@ -127,7 +138,7 @@ public: } }; -void Toasts::sendWindowsNotification(const QString &channelName, int &platform) +void Toasts::sendWindowsNotification(const QString &channelName, Platform p) { WinToastLib::WinToastTemplate templ = WinToastLib::WinToastTemplate( WinToastLib::WinToastTemplate::ImageAndText02); diff --git a/src/singletons/Toasts.hpp b/src/singletons/Toasts.hpp index 0fc7dad29..68f7a8875 100644 --- a/src/singletons/Toasts.hpp +++ b/src/singletons/Toasts.hpp @@ -7,18 +7,20 @@ namespace chatterino { +enum class Platform : uint8_t; + class Toasts final : public Singleton { public: - void sendChannelNotification(const QString &channelName, int &platform); - bool isEnabled(const QString &channelName); + void sendChannelNotification(const QString &channelName, Platform p); /* Toasts(); virtual void initialize(Settings &settings, Paths &paths) override final; */ + static bool isEnabled(); private: - void sendWindowsNotification(const QString &channelName, int &platform); + void sendWindowsNotification(const QString &channelName, Platform p); /* void updateLiveChannels(const QString &channelName); void removeFromLiveChannels(const QString &channelName); diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp index 50e52725f..269c1ae1e 100644 --- a/src/widgets/settingspages/NotificationPage.cpp +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -35,16 +35,19 @@ NotificationPage::NotificationPage() getApp()->settings->notificationFlashTaskbar)); settings.append(this->createCheckBox( "Playsound", getApp()->settings->notificationPlaySound)); + settings.append(this->createCheckBox( + "Enable toasts (currently only for windows)", + getApp()->settings->notificationToast)); settings->addStretch(1); } auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch"); { - int i = 0; EditableModelView *view = twitchChannels .emplace( - getApp()->notifications->createModel(nullptr, i)) + getApp()->notifications->createModel( + nullptr, Platform::Twitch)) .getElement(); view->setTitles({"Twitch channels"}); @@ -64,11 +67,11 @@ NotificationPage::NotificationPage() } auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer"); { - int i = 1; EditableModelView *view = mixerChannels .emplace( - getApp()->notifications->createModel(nullptr, i)) + getApp()->notifications->createModel( + nullptr, Platform::Mixer)) .getElement(); view->setTitles({"Mixer channels"}); diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 38682ad12..e97f4faa1 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -161,14 +161,12 @@ std::unique_ptr SplitHeader::createMainMenu() action->setCheckable(true); QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() { - int i = 0; action->setChecked(getApp()->notifications->isChannelNotified( - this->split_->getChannel()->getName(), i)); + this->split_->getChannel()->getName(), Platform::Twitch)); }); action->connect(action, &QAction::triggered, this, [this]() { - int i = 0; getApp()->notifications->updateChannelNotification( - this->split_->getChannel()->getName(), i); + this->split_->getChannel()->getName(), Platform::Twitch); }); menu->addAction(action);