From b68c7ded5f2e48d19dfd9d5f9164dbe94e3b7259 Mon Sep 17 00:00:00 2001 From: apa420 Date: Thu, 9 Aug 2018 15:41:03 +0200 Subject: [PATCH] WIP notification settings, doesn't actually work --- chatterino.pro | 18 ++++- src/Application.cpp | 2 + src/Application.hpp | 2 + .../notifications/NotificationController.cpp | 62 +++++++++++++++++ .../notifications/NotificationController.hpp | 37 +++++++++++ src/providers/twitch/TwitchChannel.cpp | 3 + src/singletons/Settings.hpp | 6 ++ src/widgets/dialogs/SettingsDialog.cpp | 2 + .../settingspages/NotificationPage.cpp | 66 +++++++++++++++++++ .../settingspages/NotificationPage.hpp | 20 ++++++ src/widgets/splits/SplitHeader.cpp | 15 +++++ 11 files changed, 230 insertions(+), 3 deletions(-) create mode 100644 src/controllers/notifications/NotificationController.cpp create mode 100644 src/controllers/notifications/NotificationController.hpp create mode 100644 src/widgets/settingspages/NotificationPage.cpp create mode 100644 src/widgets/settingspages/NotificationPage.hpp diff --git a/chatterino.pro b/chatterino.pro index 1c2145ea0..b9798f6ab 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -123,6 +123,7 @@ SOURCES += \ src/controllers/highlights/UserHighlightModel.cpp \ src/controllers/ignores/IgnoreController.cpp \ src/controllers/ignores/IgnoreModel.cpp \ + src/controllers/notifications/NotificationController.cpp \ src/controllers/taggedusers/TaggedUser.cpp \ src/controllers/taggedusers/TaggedUsersController.cpp \ src/controllers/taggedusers/TaggedUsersModel.cpp \ @@ -206,6 +207,7 @@ SOURCES += \ src/widgets/settingspages/KeyboardSettingsPage.cpp \ src/widgets/settingspages/LogsPage.cpp \ src/widgets/settingspages/ModerationPage.cpp \ + src/widgets/settingspages/NotificationPage.cpp \ src/widgets/settingspages/SettingsPage.cpp \ src/widgets/settingspages/SpecialChannelsPage.cpp \ src/widgets/splits/Split.cpp \ @@ -228,6 +230,7 @@ SOURCES += \ src/singletons/Updates.cpp \ src/singletons/Theme.cpp \ src/controllers/moderationactions/ModerationActionModel.cpp \ + src/widgets/settingspages/NotificationPage.cpp \ src/widgets/settingspages/LookPage.cpp \ src/widgets/settingspages/FeelPage.cpp \ src/util/InitUpdateButton.cpp \ @@ -250,7 +253,10 @@ SOURCES += \ src/RunGui.cpp \ src/BrowserExtension.cpp \ src/util/FormatTime.cpp \ - src/util/FunctionEventFilter.cpp + src/util/FunctionEventFilter.cpp \ + src/controllers/notifications/notificationcontroller.cpp \ + src/widgets/settingspages/NotificationPage.cpp \ + src/controllers/notifications/NotificationModel.cpp HEADERS += \ src/Application.hpp \ @@ -290,6 +296,7 @@ HEADERS += \ src/controllers/ignores/IgnoreController.hpp \ src/controllers/ignores/IgnoreModel.hpp \ src/controllers/ignores/IgnorePhrase.hpp \ + src/controllers/notifications/NotificationController.hpp \ src/controllers/taggedusers/TaggedUser.hpp \ src/controllers/taggedusers/TaggedUsersController.hpp \ src/controllers/taggedusers/TaggedUsersModel.hpp \ @@ -395,6 +402,7 @@ HEADERS += \ src/widgets/settingspages/KeyboardSettingsPage.hpp \ src/widgets/settingspages/LogsPage.hpp \ src/widgets/settingspages/ModerationPage.hpp \ + src/widgets/settingspages/NotificationPage.hpp \ src/widgets/settingspages/SettingsPage.hpp \ src/widgets/settingspages/SpecialChannelsPage.hpp \ src/widgets/splits/Split.hpp \ @@ -423,6 +431,7 @@ HEADERS += \ src/widgets/dialogs/LogsPopup.hpp \ src/common/Singleton.hpp \ src/controllers/moderationactions/ModerationActionModel.hpp \ + src/widgets/settingspages/NotificationPage.hpp \ src/widgets/settingspages/LookPage.hpp \ src/widgets/settingspages/FeelPage.hpp \ src/util/InitUpdateButton.hpp \ @@ -448,9 +457,12 @@ HEADERS += \ src/RunGui.hpp \ src/BrowserExtension.hpp \ src/util/FormatTime.hpp \ - src/util/FunctionEventFilter.hpp + src/util/FunctionEventFilter.hpp \ + src/widgets/settingspages/NotificationPage.hpp \ + src/controllers/notifications/NotificationModel.hpp \ + src/controllers/notifications/NotificationPhrase.hpp -RESOURCES += \ +RESOURCES += \ resources/resources.qrc \ resources/resources_autogenerated.qrc diff --git a/src/Application.cpp b/src/Application.cpp index c912597c8..f7ed93102 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -5,6 +5,7 @@ #include "controllers/highlights/HighlightController.hpp" #include "controllers/ignores/IgnoreController.hpp" #include "controllers/moderationactions/ModerationActions.hpp" +#include "controllers/notifications/NotificationController.hpp" #include "controllers/taggedusers/TaggedUsersController.hpp" #include "messages/MessageBuilder.hpp" #include "providers/bttv/BttvEmotes.hpp" @@ -47,6 +48,7 @@ Application::Application(Settings &_settings, Paths &_paths) , accounts(&this->emplace()) , commands(&this->emplace()) , highlights(&this->emplace()) + , notifications(&this->emplace()) , ignores(&this->emplace()) , taggedUsers(&this->emplace()) , moderationActions(&this->emplace()) diff --git a/src/Application.hpp b/src/Application.hpp index 2a62503bf..64045980a 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -17,6 +17,7 @@ class IgnoreController; class TaggedUsersController; class AccountController; class ModerationActions; +class NotificationController; class Theme; class WindowManager; @@ -59,6 +60,7 @@ public: AccountController *const accounts{}; CommandController *const commands{}; HighlightController *const highlights{}; + NotificationController *const notifications{}; IgnoreController *const ignores{}; TaggedUsersController *const taggedUsers{}; ModerationActions *const moderationActions{}; diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp new file mode 100644 index 000000000..984363f0f --- /dev/null +++ b/src/controllers/notifications/NotificationController.cpp @@ -0,0 +1,62 @@ +#include "NotificationController.hpp" + +#include "Application.hpp" +#include "controllers/notifications/NotificationModel.hpp" + +namespace chatterino { + +NotificationController::NotificationController() +{ +} +void NotificationController::initialize(Settings &settings, Paths &paths) +{ + this->initialized_ = true; + for (const QString &channelName : this->notificationSetting_.getValue()) { + this->notificationVector.appendItem(channelName); + } + + this->notificationVector.delayedItemsChanged.connect([this] { // + this->notificationSetting_.setValue( + this->notificationVector.getVector()); + }); +} + +void NotificationController::updateChannelNotification( + const QString &channelName) +{ + if (isChannelNotified(channelName)) { + removeChannelNotification(channelName); + } else { + addChannelNotification(channelName); + } +} + +bool NotificationController::isChannelNotified(const QString &channelName) +{ + const auto &vector = notificationSetting_.getValue(); + return std::find(vector.begin(), vector.end(), channelName) != vector.end(); +} + +void NotificationController::addChannelNotification(const QString &channelName) +{ + auto vector = notificationSetting_.getValue(); + vector.push_back(channelName); + notificationSetting_.setValue(vector); +} + +void NotificationController::removeChannelNotification( + const QString &channelName) +{ + auto vector = notificationSetting_.getValue(); + vector.erase(std::find(vector.begin(), vector.end(), channelName)); + notificationSetting_.setValue(vector); +} + +NotificationModel *NotificationController::createModel(QObject *parent) +{ + NotificationModel *model = new NotificationModel(parent); + model->init(&this->notificationVector); + return model; +} + +} // namespace chatterino diff --git a/src/controllers/notifications/NotificationController.hpp b/src/controllers/notifications/NotificationController.hpp new file mode 100644 index 000000000..593897772 --- /dev/null +++ b/src/controllers/notifications/NotificationController.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include "common/SignalVector.hpp" +#include "singletons/Settings.hpp" + +namespace chatterino { + +class Settings; +class Paths; + +class NotificationModel; + +class NotificationController final : public Singleton +{ +public: + NotificationController(); + + virtual void initialize(Settings &settings, Paths &paths) override; + + bool isChannelNotified(const QString &channelName); + + void updateChannelNotification(const QString &channelName); + void addChannelNotification(const QString &channelName); + void removeChannelNotification(const QString &channelName); + + UnsortedSignalVector notificationVector; + + NotificationModel *createModel(QObject *parent); + +private: + bool initialized_ = false; + + ChatterinoSetting> notificationSetting_ = { + "/notifications/channels"}; +}; + +} // namespace chatterino diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 7753f2668..8ec998774 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -391,6 +391,9 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document) { auto status = this->streamStatus_.access(); + if (!status->live /*&&*/) { + // notifcation send + } status->live = true; status->viewerCount = stream["viewers"].GetUint(); status->game = stream["game"].GetString(); diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3db58f9c2..501c43287 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -139,6 +139,12 @@ public: BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true}; + /// Notifications + BoolSetting notificationFlashTaskbar = {"/notifications/enableFlashTaskbar", + false}; + BoolSetting notificationPlaySound = {"/notifications/enablePlaySound", + false}; + /// External tools // Streamlink BoolSetting streamlinkUseCustomPath = {"/external/streamlink/useCustomPath", diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index 8f0746ccb..cf9c77bb8 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -16,6 +16,7 @@ #include "widgets/settingspages/LogsPage.hpp" #include "widgets/settingspages/LookPage.hpp" #include "widgets/settingspages/ModerationPage.hpp" +#include "widgets/settingspages/NotificationPage.hpp" #include "widgets/settingspages/SpecialChannelsPage.hpp" #include @@ -100,6 +101,7 @@ void SettingsDialog::addTabs() this->addTab(new KeyboardSettingsPage); // this->addTab(new LogsPage); this->addTab(new ModerationPage); + this->addTab(new NotificationPage); // this->addTab(new SpecialChannelsPage); this->addTab(new BrowserExtensionPage); this->addTab(new ExternalToolsPage); diff --git a/src/widgets/settingspages/NotificationPage.cpp b/src/widgets/settingspages/NotificationPage.cpp new file mode 100644 index 000000000..5da0a8296 --- /dev/null +++ b/src/widgets/settingspages/NotificationPage.cpp @@ -0,0 +1,66 @@ +#include "NotificationPage.hpp" + +#include "Application.hpp" +#include "singletons/Settings.hpp" +#include "src/controllers/notifications/NotificationController.hpp" +#include "util/LayoutCreator.hpp" +#include "widgets/helper/EditableModelView.hpp" + +#include +#include +#include +#include +#include +#include +#include + +namespace chatterino { + +NotificationPage::NotificationPage() + : SettingsPage("Notifications", "") +{ + LayoutCreator layoutCreator(this); + + auto layout = layoutCreator.emplace().withoutMargin(); + { + auto tabs = layout.emplace(); + { + auto settings = tabs.appendTab(new QVBoxLayout, "Options"); + { + settings.emplace( + "Enable for channel next to channel name"); + settings.append(this->createCheckBox( + "Flash taskbar", + getApp()->settings->notificationFlashTaskbar)); + settings.append(this->createCheckBox( + "Playsound", getApp()->settings->notificationPlaySound)); + + settings->addStretch(1); + } + auto channels = tabs.appendTab(new QVBoxLayout, "Channels"); + { + EditableModelView *view = + channels + .emplace( + getApp()->notifications->createModel(nullptr)) + .getElement(); + view->setTitles({"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->addChannelNotification("channel"); + }); + } + } + } +} +} // namespace chatterino diff --git a/src/widgets/settingspages/NotificationPage.hpp b/src/widgets/settingspages/NotificationPage.hpp new file mode 100644 index 000000000..d0e8c12a2 --- /dev/null +++ b/src/widgets/settingspages/NotificationPage.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "widgets/settingspages/SettingsPage.hpp" + +class QPushButton; +class QListWidget; + +class QVBoxLayout; + +namespace chatterino { + +class NotificationPage : public SettingsPage +{ +public: + NotificationPage(); + +private: +}; + +} // namespace chatterino diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index c27014080..4c12be61a 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -2,6 +2,7 @@ #include "Application.hpp" #include "controllers/accounts/AccountController.hpp" +#include "controllers/notifications/NotificationController.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchServer.hpp" #include "singletons/Resources.hpp" @@ -154,6 +155,20 @@ std::unique_ptr SplitHeader::createMainMenu() &Split::openInPopupPlayer); #endif menu->addAction("Open streamlink", this->split_, &Split::openInStreamlink); + + auto action = new QAction(this); + action->setText("Notify when live"); + action->setCheckable(true); + QObject::connect(menu.get(), &QMenu::aboutToShow, this, [action, this]() { + action->setChecked(getApp()->notifications->isChannelNotified( + this->split_->getChannel()->getName())); + }); + action->connect(action, &QAction::triggered, this, [this]() { + getApp()->notifications->updateChannelNotification( + this->split_->getChannel()->getName()); + }); + menu->addAction(action); + menu->addSeparator(); menu->addAction("Reload channel emotes", this, SLOT(menuReloadChannelEmotes()));