Change NotificationsSettingsPage such that it plugs in the registered backends'
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 10 Oct 2008 15:03:02 +0000 (17:03 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Oct 2008 18:38:43 +0000 (20:38 +0200)
configWidgets() rather than specifying its own UI.

src/qtui/settingspages/notificationssettingspage.cpp
src/qtui/settingspages/notificationssettingspage.h
src/qtui/settingspages/notificationssettingspage.ui [deleted file]
src/qtui/settingspages/settingspages.inc

index fa2e727..2c9585e 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
+#include <QVBoxLayout>
+
 #include "notificationssettingspage.h"
 
 #include "qtui.h"
 #include "notificationssettingspage.h"
 
 #include "qtui.h"
-#include "uisettings.h"
-#include "buffersettings.h"
 
 NotificationsSettingsPage::NotificationsSettingsPage(QWidget *parent)
   : SettingsPage(tr("Behaviour"), tr("Notifications"), parent) {
 
 NotificationsSettingsPage::NotificationsSettingsPage(QWidget *parent)
   : SettingsPage(tr("Behaviour"), tr("Notifications"), parent) {
-  ui.setupUi(this);
-
-  connect(ui.animateTrayIcon, SIGNAL(clicked(bool)), this, SLOT(widgetHasChanged()));
-  connect(ui.showBubble, SIGNAL(toggled(bool)), this, SLOT(widgetHasChanged()));
-  connect(ui.desktopBox, SIGNAL(toggled(bool)), this, SLOT(widgetHasChanged()));
-  connect(ui.timeout_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
-  connect(ui.x_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
-  connect(ui.y_value, SIGNAL(valueChanged(int)), this, SLOT(widgetHasChanged()));
 
 
-#ifndef HAVE_DBUS
-  ui.desktopBox->setVisible(false);
-#endif
+  QVBoxLayout *layout = new QVBoxLayout(this);
+  foreach(AbstractNotificationBackend *backend, QtUi::notificationBackends()) {
+    SettingsPage *cw = backend->configWidget();
+    if(cw) {
+      _configWidgets.append(cw);
+      layout->addWidget(cw);
+      connect(cw, SIGNAL(changed(bool)), SLOT(widgetHasChanged()));
+    }
+  }
+  layout->addStretch(1);
 }
 
 bool NotificationsSettingsPage::hasDefaults() const {
 }
 
 bool NotificationsSettingsPage::hasDefaults() const {
@@ -45,65 +44,30 @@ bool NotificationsSettingsPage::hasDefaults() const {
 }
 
 void NotificationsSettingsPage::defaults() {
 }
 
 void NotificationsSettingsPage::defaults() {
-  ui.animateTrayIcon->setChecked(true);
-  ui.showBubble->setChecked(true);
-  ui.desktopBox->setChecked(false);
-  ui.timeout_value->setValue(5000);
-  ui.x_value->setValue(0);
-  ui.y_value->setValue(0);
-
+  foreach(SettingsPage *cw, _configWidgets)
+    cw->defaults();
   widgetHasChanged();
 }
 
 void NotificationsSettingsPage::load() {
   widgetHasChanged();
 }
 
 void NotificationsSettingsPage::load() {
-  // uiSettings:
-  UiSettings uiSettings;
-
-  settings["AnimateTrayIcon"] = uiSettings.value("AnimateTrayIcon", QVariant(true));
-  ui.animateTrayIcon->setChecked(settings["AnimateTrayIcon"].toBool());
-
-  settings["NotificationBubble"] = uiSettings.value("NotificationBubble", QVariant(true));
-  ui.showBubble->setChecked(settings["NotificationBubble"].toBool());
-
-  settings["NotificationDesktop"] = uiSettings.value("NotificationDesktop", QVariant(false));
-  ui.desktopBox->setChecked(settings["NotificationDesktop"].toBool());
-  settings["NotificationDesktopTimeout"] = uiSettings.value("NotificationDesktopTimeout", QVariant(5000));
-  ui.timeout_value->setValue(settings["NotificationDesktopTimeout"].toInt());
-  settings["NotificationDesktopHintX"] = uiSettings.value("NotificationDesktopHintX", QVariant(0));
-  ui.x_value->setValue(settings["NotificationDesktopHintX"].toInt());
-  settings["NotificationDesktopHintY"] = uiSettings.value("NotificationDesktopHintY", QVariant(0));
-  ui.y_value->setValue(settings["NotificationDesktopHintY"].toInt());
-
+  foreach(SettingsPage *cw, _configWidgets)
+    cw->load();
   setChangedState(false);
 }
 
 void NotificationsSettingsPage::save() {
   setChangedState(false);
 }
 
 void NotificationsSettingsPage::save() {
-  UiSettings uiSettings;
-
-  uiSettings.setValue("AnimateTrayIcon", ui.animateTrayIcon->isChecked());
-
-  uiSettings.setValue("NotificationBubble", ui.showBubble->isChecked());
-  uiSettings.setValue("NotificationDesktop", ui.desktopBox->isChecked());
-  uiSettings.setValue("NotificationDesktopTimeout", ui.timeout_value->value());
-  uiSettings.setValue("NotificationDesktopHintX", ui.x_value->value());
-  uiSettings.setValue("NotificationDesktopHintY", ui.y_value->value());
-
-  load();
+  foreach(SettingsPage *cw, _configWidgets)
+    cw->save();
   setChangedState(false);
 }
 
 void NotificationsSettingsPage::widgetHasChanged() {
   setChangedState(false);
 }
 
 void NotificationsSettingsPage::widgetHasChanged() {
-  bool changed = testHasChanged();
+  bool changed = false;
+  foreach(SettingsPage *cw, _configWidgets) {
+    if(cw->hasChanged()) {
+      changed = true;
+      break;
+    }
+  }
   if(changed != hasChanged()) setChangedState(changed);
 }
   if(changed != hasChanged()) setChangedState(changed);
 }
-
-bool NotificationsSettingsPage::testHasChanged() {
-  if(settings["AnimateTrayIcon"].toBool() != ui.animateTrayIcon->isChecked()) return true;
-  if(settings["NotificationBubble"].toBool() != ui.showBubble->isChecked()) return true;
-  if(settings["NotificationDesktop"].toBool() != ui.desktopBox->isChecked()) return true;
-  if(settings["NotificationDesktopTimeout"].toInt() != ui.timeout_value->value()) return true;
-  if(settings["NotificationDesktopHintX"].toInt() != ui.x_value->value()) return true;
-  if(settings["NotificationDesktopHintY"].toInt() != ui.y_value->value()) return true;
-
-  return false;
-}
index d155914..653c097 100644 (file)
 #include <QHash>
 
 #include "settingspage.h"
 #include <QHash>
 
 #include "settingspage.h"
-#include "ui_notificationssettingspage.h"
 
 
+//! A settings page for configuring notifications
+/** This class just vertically stacks the ConfigWidgets of the registered notification backends.
+ *  \NOTE: When this is called, all backends need to be already registered. No dynamic changes
+ *         are tracked or reacted to!
+ */
 class NotificationsSettingsPage : public SettingsPage {
   Q_OBJECT
 
 class NotificationsSettingsPage : public SettingsPage {
   Q_OBJECT
 
@@ -43,10 +47,7 @@ class NotificationsSettingsPage : public SettingsPage {
     void widgetHasChanged();
 
   private:
     void widgetHasChanged();
 
   private:
-    Ui::NotificationsSettingsPage ui;
-    QHash<QString, QVariant> settings;
-
-    bool testHasChanged();
+    QList<SettingsPage *> _configWidgets;
 };
 
 #endif
 };
 
 #endif
diff --git a/src/qtui/settingspages/notificationssettingspage.ui b/src/qtui/settingspages/notificationssettingspage.ui
deleted file mode 100644 (file)
index 17ffed9..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-<ui version="4.0" >
- <class>NotificationsSettingsPage</class>
- <widget class="QWidget" name="NotificationsSettingsPage" >
-  <property name="geometry" >
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>422</width>
-    <height>386</height>
-   </rect>
-  </property>
-  <property name="windowTitle" >
-   <string>Form</string>
-  </property>
-  <layout class="QVBoxLayout" name="verticalLayout" >
-   <item>
-    <widget class="QGroupBox" name="groupBox_3" >
-     <property name="title" >
-      <string>System Tray</string>
-     </property>
-     <layout class="QGridLayout" >
-      <item row="1" column="0" >
-       <widget class="QCheckBox" name="animateTrayIcon" >
-        <property name="text" >
-         <string>Animate tray icon</string>
-        </property>
-        <property name="checked" >
-         <bool>true</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="0" >
-       <widget class="QCheckBox" name="showBubble" >
-        <property name="text" >
-         <string>Show Bubble</string>
-        </property>
-       </widget>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item>
-    <widget class="QGroupBox" name="desktopBox" >
-     <property name="toolTip" >
-      <string>Sends Quassel's notifications to a notification daemon compliant to Freedesktop's Notification specification (org.freedesktop.Notification).</string>
-     </property>
-     <property name="title" >
-      <string>Desktop Notification (via DBus)</string>
-     </property>
-     <property name="checkable" >
-      <bool>true</bool>
-     </property>
-     <layout class="QHBoxLayout" name="horizontalLayout" >
-      <item>
-       <layout class="QGridLayout">
-        <item row="0" column="0" >
-         <widget class="QLabel" name="timeout_label" >
-          <property name="text" >
-           <string>Timeout</string>
-          </property>
-         </widget>
-        </item>
-        <item row="0" column="1" >
-         <widget class="QSpinBox" name="timeout_value" >
-          <property name="minimum" >
-           <number>-1</number>
-          </property>
-          <property name="maximum" >
-           <number>100000</number>
-          </property>
-          <property name="value" >
-           <number>5000</number>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="0" >
-         <widget class="QLabel" name="x_label" >
-          <property name="text" >
-           <string>X</string>
-          </property>
-         </widget>
-        </item>
-        <item row="1" column="1" >
-         <widget class="QSpinBox" name="x_value" >
-          <property name="maximum" >
-           <number>10000</number>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="0" >
-         <widget class="QLabel" name="y_label" >
-          <property name="text" >
-           <string>Y</string>
-          </property>
-         </widget>
-        </item>
-        <item row="2" column="1" >
-         <widget class="QSpinBox" name="y_value" >
-          <property name="maximum" >
-           <number>10000</number>
-          </property>
-         </widget>
-        </item>
-       </layout>
-      </item>
-      <item>
-       <spacer name="horizontalSpacer" >
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0" >
-         <size>
-          <width>261</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item>
-    <spacer name="verticalSpacer" >
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeHint" stdset="0" >
-      <size>
-       <width>20</width>
-       <height>143</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
index d207234..9549d99 100644 (file)
@@ -1,9 +1,9 @@
 # Putting $FOO in SETTINGSPAGES automatically includes
 # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui
 
 # Putting $FOO in SETTINGSPAGES automatically includes
 # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui
 
-set(SETTINGSPAGES aliases appearance bufferview color fonts general highlight identities networks notifications)
+set(SETTINGSPAGES aliases appearance bufferview color fonts general highlight identities networks)
 
 # Specify additional files (e.g. for subdialogs) here!
 
 # Specify additional files (e.g. for subdialogs) here!
-set(SP_SOURCES aliasesmodel.cpp)
-set(SP_HEADERS aliasesmodel.h)
+set(SP_SOURCES aliasesmodel.cpp notificationssettingspage.cpp)
+set(SP_HEADERS aliasesmodel.h notificationssettingspage.h)
 set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui saveidentitiesdlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui)
 set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui saveidentitiesdlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui)