Fixing the issues with the NotificationsSettingspage
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 18 Nov 2008 13:49:06 +0000 (14:49 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 18 Nov 2008 13:49:06 +0000 (14:49 +0100)
src/qtui/desktopnotificationbackend.cpp
src/qtui/desktopnotificationbackend.h
src/qtui/settingsdlg.h
src/qtui/settingspages/notificationssettingspage.cpp
src/qtui/systraynotificationbackend.cpp
src/qtui/systraynotificationbackend.h
src/qtui/taskbarnotificationbackend.cpp
src/qtui/taskbarnotificationbackend.h
src/uisupport/abstractnotificationbackend.h

index d2cf9ed..e959f52 100644 (file)
@@ -26,9 +26,9 @@
 #include "clientsettings.h"
 #include "networkmodel.h"
 
 #include "clientsettings.h"
 #include "networkmodel.h"
 
-DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
-  _configWidget = new ConfigWidget();
-
+DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent)
+  : AbstractNotificationBackend(parent)
+{
   _dbusInterface = new org::freedesktop::Notifications(
     "org.freedesktop.Notifications",
     "/org/freedesktop/Notifications",
   _dbusInterface = new org::freedesktop::Notifications(
     "org.freedesktop.Notifications",
     "/org/freedesktop/Notifications",
@@ -59,10 +59,6 @@ DesktopNotificationBackend::DesktopNotificationBackend(QObject *parent) : Abstra
   notificationSettings.notify("DesktopNotification/QueueNotifications", this, SLOT(queueNotificationsChanged(const QVariant &)));
 }
 
   notificationSettings.notify("DesktopNotification/QueueNotifications", this, SLOT(queueNotificationsChanged(const QVariant &)));
 }
 
-DesktopNotificationBackend::~DesktopNotificationBackend() {
-  delete _configWidget;
-}
-
 void DesktopNotificationBackend::enabledChanged(const QVariant &v) {
   _enabled = v.toBool();
 }
 void DesktopNotificationBackend::enabledChanged(const QVariant &v) {
   _enabled = v.toBool();
 }
@@ -154,8 +150,8 @@ void DesktopNotificationBackend::desktopNotificationInvoked(uint id, const QStri
   Q_UNUSED(id); Q_UNUSED(action);
 }
 
   Q_UNUSED(id); Q_UNUSED(action);
 }
 
-SettingsPage *DesktopNotificationBackend::configWidget() const {
-  return _configWidget;
+SettingsPage *DesktopNotificationBackend::createConfigWidget() const {
+  return new ConfigWidget();
 }
 
 /***************************************************************************/
 }
 
 /***************************************************************************/
index 4427afe..74c25ca 100644 (file)
@@ -41,11 +41,10 @@ class DesktopNotificationBackend : public AbstractNotificationBackend {
 
 public:
   DesktopNotificationBackend(QObject *parent = 0);
 
 public:
   DesktopNotificationBackend(QObject *parent = 0);
-  ~DesktopNotificationBackend();
 
   void notify(const Notification &);
   void close(uint notificationId);
 
   void notify(const Notification &);
   void close(uint notificationId);
-  SettingsPage *configWidget() const;
+  virtual SettingsPage *createConfigWidget() const;
 
 private slots:
   void desktopNotificationClosed(uint id, uint reason);
 
 private slots:
   void desktopNotificationClosed(uint id, uint reason);
@@ -61,7 +60,6 @@ private slots:
 
 private:
   class ConfigWidget;
 
 private:
   class ConfigWidget;
-  SettingsPage *_configWidget;
 
   org::freedesktop::Notifications *_dbusInterface;
   bool _daemonSupportsMarkup;
 
   org::freedesktop::Notifications *_dbusInterface;
   bool _daemonSupportsMarkup;
@@ -78,23 +76,23 @@ private:
 class DesktopNotificationBackend::ConfigWidget : public SettingsPage {
   Q_OBJECT
 
 class DesktopNotificationBackend::ConfigWidget : public SettingsPage {
   Q_OBJECT
 
-  public:
-    ConfigWidget(QWidget *parent = 0);
-    void save();
-    void load();
-    bool hasDefaults() const;
-    void defaults();
-
-  private slots:
-    void widgetChanged();
-
-  private:
-    Ui::DesktopNotificationConfigWidget ui;
-    int xHint, yHint;
-    bool useHints, queueNotifications;
-    int timeout;
-    bool useTimeout;
-    bool enabled;
+public:
+  ConfigWidget(QWidget *parent = 0);
+  void save();
+  void load();
+  bool hasDefaults() const;
+  void defaults();
+
+private slots:
+  void widgetChanged();
+
+private:
+  Ui::DesktopNotificationConfigWidget ui;
+  int xHint, yHint;
+  bool useHints, queueNotifications;
+  int timeout;
+  bool useTimeout;
+  bool enabled;
 };
 
 #endif
 };
 
 #endif
index ba47da3..a5543d5 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _SETTINGSDLG_H_
-#define _SETTINGSDLG_H_
+#ifndef SETTINGSDLG_H
+#define SETTINGSDLG_H
 
 #include <QtGui>
 #include "ui_settingsdlg.h"
 
 #include <QtGui>
 #include "ui_settingsdlg.h"
index 2c9585e..3f4f789 100644 (file)
@@ -29,8 +29,9 @@ NotificationsSettingsPage::NotificationsSettingsPage(QWidget *parent)
 
   QVBoxLayout *layout = new QVBoxLayout(this);
   foreach(AbstractNotificationBackend *backend, QtUi::notificationBackends()) {
 
   QVBoxLayout *layout = new QVBoxLayout(this);
   foreach(AbstractNotificationBackend *backend, QtUi::notificationBackends()) {
-    SettingsPage *cw = backend->configWidget();
+    SettingsPage *cw = backend->createConfigWidget();
     if(cw) {
     if(cw) {
+      cw->setParent(this);
       _configWidgets.append(cw);
       layout->addWidget(cw);
       connect(cw, SIGNAL(changed(bool)), SLOT(widgetHasChanged()));
       _configWidgets.append(cw);
       layout->addWidget(cw);
       connect(cw, SIGNAL(changed(bool)), SLOT(widgetHasChanged()));
index 219a981..e992980 100644 (file)
@@ -29,7 +29,9 @@
 #include "networkmodel.h"
 #include "qtui.h"
 
 #include "networkmodel.h"
 #include "qtui.h"
 
-SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
+SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
+  : AbstractNotificationBackend(parent)
+{
   NotificationSettings notificationSettings;
   _showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool();
   _animate = notificationSettings.value("Systray/Animate", true).toBool();
   NotificationSettings notificationSettings;
   _showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool();
   _animate = notificationSettings.value("Systray/Animate", true).toBool();
@@ -37,15 +39,10 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) : Abstra
   notificationSettings.notify("Systray/ShowBubble", this, SLOT(showBubbleChanged(const QVariant &)));
   notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &)));
 
   notificationSettings.notify("Systray/ShowBubble", this, SLOT(showBubbleChanged(const QVariant &)));
   notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &)));
 
-  _configWidget = new ConfigWidget();
   _iconActive = false;
   connect(&_animationTimer, SIGNAL(timeout()), SLOT(blink()));
 }
 
   _iconActive = false;
   connect(&_animationTimer, SIGNAL(timeout()), SLOT(blink()));
 }
 
-SystrayNotificationBackend::~SystrayNotificationBackend() {
-  delete _configWidget;
-}
-
 void SystrayNotificationBackend::notify(const Notification &notification) {
   /* fancy stuff to be implemented later: show notifications in order
   _notifications.append(notification);
 void SystrayNotificationBackend::notify(const Notification &notification) {
   /* fancy stuff to be implemented later: show notifications in order
   _notifications.append(notification);
@@ -116,8 +113,8 @@ void SystrayNotificationBackend::animateChanged(const QVariant &v) {
   _animate = v.toBool();
 }
 
   _animate = v.toBool();
 }
 
-SettingsPage *SystrayNotificationBackend::configWidget() const {
-  return _configWidget;
+SettingsPage *SystrayNotificationBackend::createConfigWidget() const {
+  return new ConfigWidget();
 }
 
 /***************************************************************************/
 }
 
 /***************************************************************************/
index dc5fbb5..eaaf427 100644 (file)
@@ -32,11 +32,10 @@ class SystrayNotificationBackend : public AbstractNotificationBackend {
 
 public:
   SystrayNotificationBackend(QObject *parent = 0);
 
 public:
   SystrayNotificationBackend(QObject *parent = 0);
-  ~SystrayNotificationBackend();
 
   void notify(const Notification &);
   void close(uint notificationId);
 
   void notify(const Notification &);
   void close(uint notificationId);
-  SettingsPage *configWidget() const;
+  virtual SettingsPage *createConfigWidget() const;
 
 private slots:
   void showBubble();
 
 private slots:
   void showBubble();
@@ -51,7 +50,6 @@ private slots:
 private:
   class ConfigWidget;
 
 private:
   class ConfigWidget;
 
-  SettingsPage *_configWidget;
   bool _showBubble;
   bool _animate;
   bool _iconActive;
   bool _showBubble;
   bool _animate;
   bool _iconActive;
index 9b2e2be..26a3761 100644 (file)
 #include "mainwin.h"
 #include "qtui.h"
 
 #include "mainwin.h"
 #include "qtui.h"
 
-TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) {
+TaskbarNotificationBackend::TaskbarNotificationBackend(QObject *parent)
+  : AbstractNotificationBackend(parent)
+{
   NotificationSettings notificationSettings;
   _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
   _timeout = notificationSettings.value("Taskbar/Timeout", 0).toBool();
 
   notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
   notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
   NotificationSettings notificationSettings;
   _enabled = notificationSettings.value("Taskbar/Enabled", true).toBool();
   _timeout = notificationSettings.value("Taskbar/Timeout", 0).toBool();
 
   notificationSettings.notify("Taskbar/Enabled", this, SLOT(enabledChanged(const QVariant &)));
   notificationSettings.notify("Taskbar/Timeout", this, SLOT(timeoutChanged(const QVariant &)));
-
-  _configWidget = new ConfigWidget();
-}
-
-TaskbarNotificationBackend::~TaskbarNotificationBackend() {
-  delete _configWidget;
 }
 
 void TaskbarNotificationBackend::notify(const Notification &notification) {
 }
 
 void TaskbarNotificationBackend::notify(const Notification &notification) {
@@ -60,8 +56,8 @@ void TaskbarNotificationBackend::timeoutChanged(const QVariant &v) {
   _timeout = v.toInt();
 }
 
   _timeout = v.toInt();
 }
 
-SettingsPage *TaskbarNotificationBackend::configWidget() const {
-  return _configWidget;
+SettingsPage *TaskbarNotificationBackend::createConfigWidget() const {
+  return new ConfigWidget();
 }
 
 /***************************************************************************/
 }
 
 /***************************************************************************/
index e8d0887..a90d5ec 100644 (file)
@@ -33,11 +33,10 @@ class TaskbarNotificationBackend : public AbstractNotificationBackend {
 
 public:
   TaskbarNotificationBackend(QObject *parent = 0);
 
 public:
   TaskbarNotificationBackend(QObject *parent = 0);
-  ~TaskbarNotificationBackend();
 
   void notify(const Notification &);
   void close(uint notificationId);
 
   void notify(const Notification &);
   void close(uint notificationId);
-  SettingsPage *configWidget() const;
+  virtual SettingsPage *createConfigWidget() const;
 
 private slots:
   void enabledChanged(const QVariant &);
 
 private slots:
   void enabledChanged(const QVariant &);
@@ -46,7 +45,6 @@ private slots:
 private:
   class ConfigWidget;
 
 private:
   class ConfigWidget;
 
-  SettingsPage *_configWidget;
   bool _enabled;
   int _timeout;
 };
   bool _enabled;
   int _timeout;
 };
index c7112af..cc9941b 100644 (file)
@@ -31,24 +31,29 @@ class SettingsPage;
 class AbstractNotificationBackend : public QObject {
   Q_OBJECT
 
 class AbstractNotificationBackend : public QObject {
   Q_OBJECT
 
-  public:
-    struct Notification {
-      uint notificationId;
-      BufferId bufferId;
-      QString sender;
-      QString message;
-
-      Notification(uint id_, BufferId buf_, const QString &sender_, const QString &msg_)
+public:
+  struct Notification {
+    uint notificationId;
+    BufferId bufferId;
+    QString sender;
+    QString message;
+
+    Notification(uint id_, BufferId buf_, const QString &sender_, const QString &msg_)
       : notificationId(id_), bufferId(buf_), sender(sender_), message(msg_) {};
       : notificationId(id_), bufferId(buf_), sender(sender_), message(msg_) {};
-    };
+  };
 
 
-    inline AbstractNotificationBackend(QObject *parent) : QObject(parent) {};
-    virtual ~AbstractNotificationBackend() {};
+  inline AbstractNotificationBackend(QObject *parent) : QObject(parent) {};
+  virtual ~AbstractNotificationBackend() {};
 
 
-    virtual void notify(const Notification &) = 0;
-    virtual void close(uint notificationId) { Q_UNUSED(notificationId); }
-    virtual SettingsPage *configWidget() const = 0;
+  virtual void notify(const Notification &) = 0;
+  virtual void close(uint notificationId) { Q_UNUSED(notificationId); }
 
 
+  //! factory to create a configuration widget suitable for a specific notification backend
+  /**
+   * AbstractNotification will not take owner ship of that configWidget!
+   * in case you need to communicate with the configWidget directly, make your connections here
+   */
+  virtual SettingsPage *createConfigWidget() const = 0;
 };
 
 #endif
 };
 
 #endif