Move DBus- and other notification-related settings to their own SettingsPage
[quassel.git] / src / qtui / settingspages / notificationssettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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) any later version.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "notificationssettingspage.h"
22
23 #include "qtui.h"
24 #include "uisettings.h"
25 #include "buffersettings.h"
26
27 NotificationsSettingsPage::NotificationsSettingsPage(QWidget *parent)
28   : SettingsPage(tr("Behaviour"), tr("Notifications"), parent) {
29   ui.setupUi(this);
30
31   connect(ui.animateTrayIcon, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
32   connect(ui.showBubble, SIGNAL(toggled(bool)), this, SLOT(widgetHasChanged()));
33   connect(ui.desktopBox, SIGNAL(toggled(bool)), this, SLOT(widgetHasChanged()));
34   connect(ui.timeout_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
35   connect(ui.x_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
36   connect(ui.y_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
37
38 }
39
40 bool NotificationsSettingsPage::hasDefaults() const {
41   return true;
42 }
43
44 void NotificationsSettingsPage::defaults() {
45   ui.animateTrayIcon->setChecked(true);
46   ui.showBubble->setChecked(true);
47   ui.desktopBox->setChecked(true);
48   ui.timeout_value->setValue(5000);
49   ui.x_value->setValue(0);
50   ui.y_value->setValue(0);
51
52   widgetHasChanged();
53 }
54
55 void NotificationsSettingsPage::load() {
56   // uiSettings:
57   UiSettings uiSettings;
58
59   settings["AnimateTrayIcon"] = uiSettings.value("AnimateTrayIcon", QVariant(true));
60   ui.animateTrayIcon->setChecked(settings["AnimateTrayIcon"].toBool());
61
62   settings["NotificationBubble"] = uiSettings.value("NotificationBubble", QVariant(true));
63   ui.showBubble->setChecked(settings["NotificationBubble"].toBool());
64
65   settings["NotificationDesktop"] = uiSettings.value("NotificationDesktop", QVariant(true));
66   ui.desktopBox->setChecked(settings["NotificationDesktop"].toBool());
67   settings["NotificationDesktopTimeout"] = uiSettings.value("NotificationDesktopTimeout", QVariant(5000));
68   ui.timeout_value->setValue(settings["NotificationDesktopTimeout"].toInt());
69   settings["NotificationDesktopHintX"] = uiSettings.value("NotificationDesktopHintX", QVariant(0));
70   ui.x_value->setValue(settings["NotificationDesktopHintX"].toInt());
71   settings["NotificationDesktopHintY"] = uiSettings.value("NotificationDesktopHintY", QVariant(0));
72   ui.y_value->setValue(settings["NotificationDesktopHintY"].toInt());
73
74   setChangedState(false);
75 }
76
77 void NotificationsSettingsPage::save() {
78   UiSettings uiSettings;
79
80   uiSettings.setValue("AnimateTrayIcon", ui.animateTrayIcon->isChecked());
81
82   uiSettings.setValue("NotificationBubble", ui.showBubble->isChecked());
83   uiSettings.setValue("NotificationDesktop", ui.desktopBox->isChecked());
84   uiSettings.setValue("NotificationDesktopTimeout", ui.timeout_value->value());
85   uiSettings.setValue("NotificationDesktopHintX", ui.x_value->value());
86   uiSettings.setValue("NotificationDesktopHintY", ui.y_value->value());
87
88   load();
89   setChangedState(false);
90 }
91
92 void NotificationsSettingsPage::widgetHasChanged() {
93   bool changed = testHasChanged();
94   if(changed != hasChanged()) setChangedState(changed);
95 }
96
97 bool NotificationsSettingsPage::testHasChanged() {
98   if(settings["AnimateTrayIcon"].toBool() != ui.animateTrayIcon->isChecked()) return true;
99   if(settings["NotificationBubble"].toBool() != ui.showBubble->isChecked()) return true;
100   if(settings["NotificationDesktop"].toBool() != ui.desktopBox->isChecked()) return true;
101   if(settings["NotificationDesktopTimeout"].toInt() != ui.timeout_value->value()) return true;
102   if(settings["NotificationDesktopHintX"].toInt() != ui.x_value->value()) return true;
103   if(settings["NotificationDesktopHintY"].toInt() != ui.y_value->value()) return true;
104
105   return false;
106 }