#include "NotificationPage.hpp" #include "Application.hpp" #include "controllers/notifications/NotificationController.hpp" #include "controllers/notifications/NotificationModel.hpp" #include "singletons/Settings.hpp" #include "singletons/Toasts.hpp" #include "util/LayoutCreator.hpp" #include "widgets/helper/EditableModelView.hpp" #include #include #include #include #include #include #include #include #include namespace chatterino { NotificationPage::NotificationPage() : SettingsPage("Notifications", ":/settings/notification2.svg") { LayoutCreator layoutCreator(this); auto layout = layoutCreator.emplace().withoutMargin(); { auto tabs = layout.emplace(); { auto settings = tabs.appendTab(new QVBoxLayout, "Options"); { settings.emplace("Enable for selected channels"); settings.append(this->createCheckBox( "Flash taskbar", getSettings()->notificationFlashTaskbar)); settings.append(this->createCheckBox( "Play sound", getSettings()->notificationPlaySound)); #ifdef Q_OS_WIN settings.append( this->createCheckBox("Enable toasts (Windows 8 or later)", getSettings()->notificationToast)); auto openIn = settings.emplace().withoutMargin(); { openIn.emplace("Open stream from Toast: ") ->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); // implementation of custom combobox done // because addComboBox only can handle strings-settings // int setting for the ToastReaction is desired openIn .append(this->createToastReactionComboBox( this->managedConnections_)) ->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); } openIn->setContentsMargins(40, 0, 0, 0); openIn->setSizeConstraint(QLayout::SetMaximumSize); #endif auto customSound = layout.emplace().withoutMargin(); { customSound.append(this->createCheckBox( "Custom sound", getSettings()->notificationCustomSound)); auto selectFile = customSound.emplace( "Select custom sound file"); QObject::connect( selectFile.getElement(), &QPushButton::clicked, this, [this] { auto fileName = QFileDialog::getOpenFileName( this, tr("Open Sound"), "", tr("Audio Files (*.mp3 *.wav)")); getSettings()->notificationPathSound = fileName; }); } settings->addStretch(1); } auto twitchChannels = tabs.appendTab(new QVBoxLayout, "Twitch"); { EditableModelView *view = twitchChannels .emplace( getApp()->notifications->createModel( nullptr, Platform::Twitch)) .getElement(); view->setTitles({"Twitch 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->channelMap[Platform::Twitch] .appendItem("channel"); }); } /* auto mixerChannels = tabs.appendTab(new QVBoxLayout, "Mixer"); { EditableModelView *view = mixerChannels .emplace( getApp()->notifications->createModel( nullptr, Platform::Mixer)) .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->channelMap[Platform::Mixer] .appendItem("channel"); }); } */ } } } QComboBox *NotificationPage::createToastReactionComboBox( std::vector managedConnections) { QComboBox *toastReactionOptions = new QComboBox(); for (int i = 0; i <= static_cast(ToastReactions::DontOpen); i++) { toastReactionOptions->insertItem( i, Toasts::findStringFromReaction(static_cast(i))); } // update when setting changes pajlada::Settings::Setting setting = getSettings()->openFromToast; setting.connect( [toastReactionOptions](const int &index, auto) { toastReactionOptions->setCurrentIndex(index); }, managedConnections); QObject::connect(toastReactionOptions, QOverload::of(&QComboBox::currentIndexChanged), [](const int &newValue) { getSettings()->openFromToast.setValue(newValue); }); return toastReactionOptions; } } // namespace chatterino