WIP notification settings, doesn't actually work

This commit is contained in:
apa420 2018-08-09 15:41:03 +02:00
parent 7a9af4ae84
commit b68c7ded5f
11 changed files with 230 additions and 3 deletions

View file

@ -123,6 +123,7 @@ SOURCES += \
src/controllers/highlights/UserHighlightModel.cpp \ src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/ignores/IgnoreController.cpp \ src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \ src/controllers/ignores/IgnoreModel.cpp \
src/controllers/notifications/NotificationController.cpp \
src/controllers/taggedusers/TaggedUser.cpp \ src/controllers/taggedusers/TaggedUser.cpp \
src/controllers/taggedusers/TaggedUsersController.cpp \ src/controllers/taggedusers/TaggedUsersController.cpp \
src/controllers/taggedusers/TaggedUsersModel.cpp \ src/controllers/taggedusers/TaggedUsersModel.cpp \
@ -206,6 +207,7 @@ SOURCES += \
src/widgets/settingspages/KeyboardSettingsPage.cpp \ src/widgets/settingspages/KeyboardSettingsPage.cpp \
src/widgets/settingspages/LogsPage.cpp \ src/widgets/settingspages/LogsPage.cpp \
src/widgets/settingspages/ModerationPage.cpp \ src/widgets/settingspages/ModerationPage.cpp \
src/widgets/settingspages/NotificationPage.cpp \
src/widgets/settingspages/SettingsPage.cpp \ src/widgets/settingspages/SettingsPage.cpp \
src/widgets/settingspages/SpecialChannelsPage.cpp \ src/widgets/settingspages/SpecialChannelsPage.cpp \
src/widgets/splits/Split.cpp \ src/widgets/splits/Split.cpp \
@ -228,6 +230,7 @@ SOURCES += \
src/singletons/Updates.cpp \ src/singletons/Updates.cpp \
src/singletons/Theme.cpp \ src/singletons/Theme.cpp \
src/controllers/moderationactions/ModerationActionModel.cpp \ src/controllers/moderationactions/ModerationActionModel.cpp \
src/widgets/settingspages/NotificationPage.cpp \
src/widgets/settingspages/LookPage.cpp \ src/widgets/settingspages/LookPage.cpp \
src/widgets/settingspages/FeelPage.cpp \ src/widgets/settingspages/FeelPage.cpp \
src/util/InitUpdateButton.cpp \ src/util/InitUpdateButton.cpp \
@ -250,7 +253,10 @@ SOURCES += \
src/RunGui.cpp \ src/RunGui.cpp \
src/BrowserExtension.cpp \ src/BrowserExtension.cpp \
src/util/FormatTime.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 += \ HEADERS += \
src/Application.hpp \ src/Application.hpp \
@ -290,6 +296,7 @@ HEADERS += \
src/controllers/ignores/IgnoreController.hpp \ src/controllers/ignores/IgnoreController.hpp \
src/controllers/ignores/IgnoreModel.hpp \ src/controllers/ignores/IgnoreModel.hpp \
src/controllers/ignores/IgnorePhrase.hpp \ src/controllers/ignores/IgnorePhrase.hpp \
src/controllers/notifications/NotificationController.hpp \
src/controllers/taggedusers/TaggedUser.hpp \ src/controllers/taggedusers/TaggedUser.hpp \
src/controllers/taggedusers/TaggedUsersController.hpp \ src/controllers/taggedusers/TaggedUsersController.hpp \
src/controllers/taggedusers/TaggedUsersModel.hpp \ src/controllers/taggedusers/TaggedUsersModel.hpp \
@ -395,6 +402,7 @@ HEADERS += \
src/widgets/settingspages/KeyboardSettingsPage.hpp \ src/widgets/settingspages/KeyboardSettingsPage.hpp \
src/widgets/settingspages/LogsPage.hpp \ src/widgets/settingspages/LogsPage.hpp \
src/widgets/settingspages/ModerationPage.hpp \ src/widgets/settingspages/ModerationPage.hpp \
src/widgets/settingspages/NotificationPage.hpp \
src/widgets/settingspages/SettingsPage.hpp \ src/widgets/settingspages/SettingsPage.hpp \
src/widgets/settingspages/SpecialChannelsPage.hpp \ src/widgets/settingspages/SpecialChannelsPage.hpp \
src/widgets/splits/Split.hpp \ src/widgets/splits/Split.hpp \
@ -423,6 +431,7 @@ HEADERS += \
src/widgets/dialogs/LogsPopup.hpp \ src/widgets/dialogs/LogsPopup.hpp \
src/common/Singleton.hpp \ src/common/Singleton.hpp \
src/controllers/moderationactions/ModerationActionModel.hpp \ src/controllers/moderationactions/ModerationActionModel.hpp \
src/widgets/settingspages/NotificationPage.hpp \
src/widgets/settingspages/LookPage.hpp \ src/widgets/settingspages/LookPage.hpp \
src/widgets/settingspages/FeelPage.hpp \ src/widgets/settingspages/FeelPage.hpp \
src/util/InitUpdateButton.hpp \ src/util/InitUpdateButton.hpp \
@ -448,7 +457,10 @@ HEADERS += \
src/RunGui.hpp \ src/RunGui.hpp \
src/BrowserExtension.hpp \ src/BrowserExtension.hpp \
src/util/FormatTime.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.qrc \

View file

@ -5,6 +5,7 @@
#include "controllers/highlights/HighlightController.hpp" #include "controllers/highlights/HighlightController.hpp"
#include "controllers/ignores/IgnoreController.hpp" #include "controllers/ignores/IgnoreController.hpp"
#include "controllers/moderationactions/ModerationActions.hpp" #include "controllers/moderationactions/ModerationActions.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "controllers/taggedusers/TaggedUsersController.hpp" #include "controllers/taggedusers/TaggedUsersController.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "providers/bttv/BttvEmotes.hpp" #include "providers/bttv/BttvEmotes.hpp"
@ -47,6 +48,7 @@ Application::Application(Settings &_settings, Paths &_paths)
, accounts(&this->emplace<AccountController>()) , accounts(&this->emplace<AccountController>())
, commands(&this->emplace<CommandController>()) , commands(&this->emplace<CommandController>())
, highlights(&this->emplace<HighlightController>()) , highlights(&this->emplace<HighlightController>())
, notifications(&this->emplace<NotificationController>())
, ignores(&this->emplace<IgnoreController>()) , ignores(&this->emplace<IgnoreController>())
, taggedUsers(&this->emplace<TaggedUsersController>()) , taggedUsers(&this->emplace<TaggedUsersController>())
, moderationActions(&this->emplace<ModerationActions>()) , moderationActions(&this->emplace<ModerationActions>())

View file

@ -17,6 +17,7 @@ class IgnoreController;
class TaggedUsersController; class TaggedUsersController;
class AccountController; class AccountController;
class ModerationActions; class ModerationActions;
class NotificationController;
class Theme; class Theme;
class WindowManager; class WindowManager;
@ -59,6 +60,7 @@ public:
AccountController *const accounts{}; AccountController *const accounts{};
CommandController *const commands{}; CommandController *const commands{};
HighlightController *const highlights{}; HighlightController *const highlights{};
NotificationController *const notifications{};
IgnoreController *const ignores{}; IgnoreController *const ignores{};
TaggedUsersController *const taggedUsers{}; TaggedUsersController *const taggedUsers{};
ModerationActions *const moderationActions{}; ModerationActions *const moderationActions{};

View file

@ -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

View file

@ -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<QString> notificationVector;
NotificationModel *createModel(QObject *parent);
private:
bool initialized_ = false;
ChatterinoSetting<std::vector<QString>> notificationSetting_ = {
"/notifications/channels"};
};
} // namespace chatterino

View file

@ -391,6 +391,9 @@ Outcome TwitchChannel::parseLiveStatus(const rapidjson::Document &document)
{ {
auto status = this->streamStatus_.access(); auto status = this->streamStatus_.access();
if (!status->live /*&&*/) {
// notifcation send
}
status->live = true; status->live = true;
status->viewerCount = stream["viewers"].GetUint(); status->viewerCount = stream["viewers"].GetUint();
status->game = stream["game"].GetString(); status->game = stream["game"].GetString();

View file

@ -139,6 +139,12 @@ public:
BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true}; BoolSetting inlineWhispers = {"/whispers/enableInlineWhispers", true};
/// Notifications
BoolSetting notificationFlashTaskbar = {"/notifications/enableFlashTaskbar",
false};
BoolSetting notificationPlaySound = {"/notifications/enablePlaySound",
false};
/// External tools /// External tools
// Streamlink // Streamlink
BoolSetting streamlinkUseCustomPath = {"/external/streamlink/useCustomPath", BoolSetting streamlinkUseCustomPath = {"/external/streamlink/useCustomPath",

View file

@ -16,6 +16,7 @@
#include "widgets/settingspages/LogsPage.hpp" #include "widgets/settingspages/LogsPage.hpp"
#include "widgets/settingspages/LookPage.hpp" #include "widgets/settingspages/LookPage.hpp"
#include "widgets/settingspages/ModerationPage.hpp" #include "widgets/settingspages/ModerationPage.hpp"
#include "widgets/settingspages/NotificationPage.hpp"
#include "widgets/settingspages/SpecialChannelsPage.hpp" #include "widgets/settingspages/SpecialChannelsPage.hpp"
#include <QDialogButtonBox> #include <QDialogButtonBox>
@ -100,6 +101,7 @@ void SettingsDialog::addTabs()
this->addTab(new KeyboardSettingsPage); this->addTab(new KeyboardSettingsPage);
// this->addTab(new LogsPage); // this->addTab(new LogsPage);
this->addTab(new ModerationPage); this->addTab(new ModerationPage);
this->addTab(new NotificationPage);
// this->addTab(new SpecialChannelsPage); // this->addTab(new SpecialChannelsPage);
this->addTab(new BrowserExtensionPage); this->addTab(new BrowserExtensionPage);
this->addTab(new ExternalToolsPage); this->addTab(new ExternalToolsPage);

View file

@ -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 <QCheckBox>
#include <QGroupBox>
#include <QHeaderView>
#include <QLabel>
#include <QListView>
#include <QTableView>
#include <QTimer>
namespace chatterino {
NotificationPage::NotificationPage()
: SettingsPage("Notifications", "")
{
LayoutCreator<NotificationPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
{
auto tabs = layout.emplace<QTabWidget>();
{
auto settings = tabs.appendTab(new QVBoxLayout, "Options");
{
settings.emplace<QLabel>(
"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<EditableModelView>(
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

View file

@ -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

View file

@ -2,6 +2,7 @@
#include "Application.hpp" #include "Application.hpp"
#include "controllers/accounts/AccountController.hpp" #include "controllers/accounts/AccountController.hpp"
#include "controllers/notifications/NotificationController.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchServer.hpp" #include "providers/twitch/TwitchServer.hpp"
#include "singletons/Resources.hpp" #include "singletons/Resources.hpp"
@ -154,6 +155,20 @@ std::unique_ptr<QMenu> SplitHeader::createMainMenu()
&Split::openInPopupPlayer); &Split::openInPopupPlayer);
#endif #endif
menu->addAction("Open streamlink", this->split_, &Split::openInStreamlink); 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->addSeparator();
menu->addAction("Reload channel emotes", this, menu->addAction("Reload channel emotes", this,
SLOT(menuReloadChannelEmotes())); SLOT(menuReloadChannelEmotes()));