1 /***************************************************************************
2 * Copyright (C) 2005-09 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "taskbarnotificationbackend.h"
25 #include "clientsettings.h"
29 TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent)
30 : AbstractNotificationBackend(parent)
32 NotificationSettings notificationSettings;
33 _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
34 _timeout = notificationSettings.value("Taskbar/Timeout", 0).toBool();
36 notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
37 notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
40 void TaskbarNotificationBackend::notify(const Notification ¬ification) {
41 Q_UNUSED(notification)
43 QApplication::alert(QtUi::mainWindow(), _timeout);
47 void TaskbarNotificationBackend::close(uint notificationId) {
48 Q_UNUSED(notificationId);
51 void TaskbarNotificationBackend::enabledChanged(const QVariant &v) {
52 _enabled = v.toBool();
55 void TaskbarNotificationBackend::timeoutChanged(const QVariant &v) {
59 SettingsPage *TaskbarNotificationBackend::createConfigWidget() const {
60 return new ConfigWidget();
63 /***************************************************************************/
65 TaskbarNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "TaskbarNotification", parent) {
66 QHBoxLayout *layout = new QHBoxLayout(this);
68 layout->addWidget(enabledBox = new QCheckBox(tr("Activate dock entry, timeout:"), this));
70 layout->addWidget(enabledBox = new QCheckBox(tr("Mark taskbar entry, timeout:"), this));
72 timeoutBox = new QSpinBox(this);
73 timeoutBox->setMinimum(0);
74 timeoutBox->setMaximum(99);
75 timeoutBox->setSpecialValueText(tr("Unlimited"));
76 timeoutBox->setSuffix(tr(" s"));
77 layout->addWidget(timeoutBox);
78 layout->addStretch(1);
80 connect(enabledBox, SIGNAL(toggled(bool)), SLOT(widgetChanged()));
81 connect(timeoutBox, SIGNAL(valueChanged(int)), SLOT(widgetChanged()));
84 void TaskbarNotificationBackend::ConfigWidget::widgetChanged() {
85 bool changed = (enabled != enabledBox->isChecked() || timeout/1000 != timeoutBox->value());
86 if(changed != hasChanged()) setChangedState(changed);
89 bool TaskbarNotificationBackend::ConfigWidget::hasDefaults() const {
93 void TaskbarNotificationBackend::ConfigWidget::defaults() {
94 enabledBox->setChecked(true);
95 timeoutBox->setValue(0);
99 void TaskbarNotificationBackend::ConfigWidget::load() {
100 NotificationSettings s;
101 enabled = s.value("Taskbar/Enabled", true).toBool();
102 timeout = s.value("Taskbar/Timeout", 0).toInt();
104 enabledBox->setChecked(enabled);
105 timeoutBox->setValue(timeout/1000);
107 setChangedState(false);
110 void TaskbarNotificationBackend::ConfigWidget::save() {
111 NotificationSettings s;
112 s.setValue("Taskbar/Enabled", enabledBox->isChecked());
113 s.setValue("Taskbar/Timeout", timeoutBox->value() * 1000);