Some tweaking of NotificationsSettingsPage
[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 #ifndef HAVE_DBUS
39   ui.desktopBox->setEnabled(false);
40 #endif
41 }
42
43 bool NotificationsSettingsPage::hasDefaults() const {
44   return true;
45 }
46
47 void NotificationsSettingsPage::defaults() {
48   ui.animateTrayIcon->setChecked(true);
49   ui.showBubble->setChecked(true);
50   ui.desktopBox->setChecked(false);
51   ui.timeout_value->setValue(5000);
52   ui.x_value->setValue(0);
53   ui.y_value->setValue(0);
54
55   widgetHasChanged();
56 }
57
58 void NotificationsSettingsPage::load() {
59   // uiSettings:
60   UiSettings uiSettings;
61
62   settings["AnimateTrayIcon"] = uiSettings.value("AnimateTrayIcon", QVariant(true));
63   ui.animateTrayIcon->setChecked(settings["AnimateTrayIcon"].toBool());
64
65   settings["NotificationBubble"] = uiSettings.value("NotificationBubble", QVariant(true));
66   ui.showBubble->setChecked(settings["NotificationBubble"].toBool());
67
68   settings["NotificationDesktop"] = uiSettings.value("NotificationDesktop", QVariant(false));
69   ui.desktopBox->setChecked(settings["NotificationDesktop"].toBool());
70   settings["NotificationDesktopTimeout"] = uiSettings.value("NotificationDesktopTimeout", QVariant(5000));
71   ui.timeout_value->setValue(settings["NotificationDesktopTimeout"].toInt());
72   settings["NotificationDesktopHintX"] = uiSettings.value("NotificationDesktopHintX", QVariant(0));
73   ui.x_value->setValue(settings["NotificationDesktopHintX"].toInt());
74   settings["NotificationDesktopHintY"] = uiSettings.value("NotificationDesktopHintY", QVariant(0));
75   ui.y_value->setValue(settings["NotificationDesktopHintY"].toInt());
76
77   setChangedState(false);
78 }
79
80 void NotificationsSettingsPage::save() {
81   UiSettings uiSettings;
82
83   uiSettings.setValue("AnimateTrayIcon", ui.animateTrayIcon->isChecked());
84
85   uiSettings.setValue("NotificationBubble", ui.showBubble->isChecked());
86   uiSettings.setValue("NotificationDesktop", ui.desktopBox->isChecked());
87   uiSettings.setValue("NotificationDesktopTimeout", ui.timeout_value->value());
88   uiSettings.setValue("NotificationDesktopHintX", ui.x_value->value());
89   uiSettings.setValue("NotificationDesktopHintY", ui.y_value->value());
90
91   load();
92   setChangedState(false);
93 }
94
95 void NotificationsSettingsPage::widgetHasChanged() {
96   bool changed = testHasChanged();
97   if(changed != hasChanged()) setChangedState(changed);
98 }
99
100 bool NotificationsSettingsPage::testHasChanged() {
101   if(settings["AnimateTrayIcon"].toBool() != ui.animateTrayIcon->isChecked()) return true;
102   if(settings["NotificationBubble"].toBool() != ui.showBubble->isChecked()) return true;
103   if(settings["NotificationDesktop"].toBool() != ui.desktopBox->isChecked()) return true;
104   if(settings["NotificationDesktopTimeout"].toInt() != ui.timeout_value->value()) return true;
105   if(settings["NotificationDesktopHintX"].toInt() != ui.x_value->value()) return true;
106   if(settings["NotificationDesktopHintY"].toInt() != ui.y_value->value()) return true;
107
108   return false;
109 }