1 /***************************************************************************
2 * Copyright (C) 2005-2019 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "taskbarnotificationbackend.h"
23 #include <QApplication>
25 #include <QHBoxLayout>
28 #include "clientsettings.h"
33 TaskbarNotificationBackend::TaskbarNotificationBackend(QObject* parent)
34 : AbstractNotificationBackend(parent)
36 NotificationSettings notificationSettings;
37 _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
38 _timeout = notificationSettings.value("Taskbar/Timeout", 0).toInt();
40 notificationSettings.notify("Taskbar/Enabled", this, &TaskbarNotificationBackend::enabledChanged);
41 notificationSettings.notify("Taskbar/Timeout", this, &TaskbarNotificationBackend::timeoutChanged);
44 void TaskbarNotificationBackend::notify(const Notification& notification)
46 if (_enabled && (notification.type == Highlight || notification.type == PrivMsg)) {
47 QApplication::alert(QtUi::mainWindow(), _timeout);
51 void TaskbarNotificationBackend::close(uint notificationId)
53 Q_UNUSED(notificationId);
56 void TaskbarNotificationBackend::enabledChanged(const QVariant& v)
58 _enabled = v.toBool();
61 void TaskbarNotificationBackend::timeoutChanged(const QVariant& v)
66 SettingsPage* TaskbarNotificationBackend::createConfigWidget() const
68 return new ConfigWidget();
71 /***************************************************************************/
73 TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget* parent)
74 : SettingsPage("Internal", "TaskbarNotification", parent)
76 auto* layout = new QHBoxLayout(this);
78 layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
80 layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
82 enabledBox->setIcon(icon::get("flag-blue"));
83 enabledBox->setEnabled(true);
85 timeoutBox = new QSpinBox(this);
86 timeoutBox->setMinimum(0);
87 timeoutBox->setMaximum(99);
88 timeoutBox->setSpecialValueText(tr("Unlimited"));
89 timeoutBox->setSuffix(tr(" seconds"));
90 layout->addWidget(timeoutBox);
91 layout->addStretch(20);
93 connect(enabledBox, &QAbstractButton::toggled, this, &ConfigWidget::widgetChanged);
94 connect(enabledBox, &QAbstractButton::toggled, timeoutBox, &QWidget::setEnabled);
95 connect(timeoutBox, selectOverload<int>(&QSpinBox::valueChanged), this, &ConfigWidget::widgetChanged);
98 void TaskbarNotificationBackend::ConfigWidget::widgetChanged()
100 bool changed = (enabled != enabledBox->isChecked() || timeout / 1000 != timeoutBox->value());
101 if (changed != hasChanged())
102 setChangedState(changed);
105 bool TaskbarNotificationBackend::ConfigWidget::hasDefaults() const
110 void TaskbarNotificationBackend::ConfigWidget::defaults()
112 enabledBox->setChecked(true);
113 timeoutBox->setValue(0);
117 void TaskbarNotificationBackend::ConfigWidget::load()
119 NotificationSettings s;
120 enabled = s.value("Taskbar/Enabled", true).toBool();
121 timeout = s.value("Taskbar/Timeout", 0).toInt();
123 enabledBox->setChecked(enabled);
124 timeoutBox->setValue(timeout / 1000);
126 setChangedState(false);
129 void TaskbarNotificationBackend::ConfigWidget::save()
131 NotificationSettings s;
132 s.setValue("Taskbar/Enabled", enabledBox->isChecked());
133 s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);