Add AbstractNotificationBackend to allow for a more modular approach to notifications
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 4 Oct 2008 20:16:33 +0000 (22:16 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Oct 2008 18:38:43 +0000 (20:38 +0200)
This is the first step of cleaning up MainWin. I intend to move most stuff out of that
old crufty class, mainly into QtUi or other modules.

src/client/quasselui.cpp
src/client/quasselui.h
src/qtui/qtui.cpp
src/qtui/qtui.h
src/uisupport/CMakeLists.txt
src/uisupport/abstractnotificationbackend.cpp [new file with mode: 0644]
src/uisupport/abstractnotificationbackend.h [new file with mode: 0644]

index 6e0e0aa..c559f16 100644 (file)
 
 #include "quasselui.h"
 
+AbstractUi * AbstractUi::_instance = 0;
 bool AbstractUi::_visible = false;
+
+AbstractUi::AbstractUi() {
+  Q_ASSERT(!_instance);
+  _instance = this;
+}
index dac64be..0a855fc 100644 (file)
@@ -31,12 +31,14 @@ class AbstractUi : public QObject {
   Q_OBJECT
 
   public:
+    AbstractUi();
+    virtual ~AbstractUi() {};
     virtual void init() {};  // called after the client is initialized
     virtual MessageModel *createMessageModel(QObject *parent) = 0;
     virtual AbstractMessageProcessor *createMessageProcessor(QObject *parent) = 0;
 
-  inline static bool isVisible() { return _visible; }
-  inline static void setVisible(bool visible) { _visible = visible; }
+    inline static bool isVisible() { return _visible; }
+    inline static void setVisible(bool visible) { _visible = visible; }
 
   protected slots:
     virtual void connectedToCore() {}
@@ -46,8 +48,9 @@ class AbstractUi : public QObject {
     void connectToCore(const QVariantMap &connInfo);
     void disconnectFromCore();
 
-private:
-  static bool _visible;
+  private:
+    static AbstractUi *_instance;
+    static bool _visible;
 };
 
 #endif
index 85e6b1a..1459760 100644 (file)
 
 #include "qtui.h"
 
-#include <QDebug>
-
 #include "actioncollection.h"
 #include "chatlinemodel.h"
 #include "mainwin.h"
+#include "abstractnotificationbackend.h"
 #include "qtuimessageprocessor.h"
 #include "qtuistyle.h"
+#include "types.h"
 #include "uisettings.h"
 #include "util.h"
 
 ActionCollection *QtUi::_actionCollection = 0;
+QSet<AbstractNotificationBackend *> QtUi::_notificationBackends;
 QtUiStyle *QtUi::_style = 0;
 
-QtUi::QtUi() : AbstractUi()
-{
+QtUi::QtUi() : AbstractUi() {
   if(_style != 0) {
     qWarning() << "QtUi has been instantiated again!";
     return;
@@ -52,6 +52,7 @@ QtUi::QtUi() : AbstractUi()
 }
 
 QtUi::~QtUi() {
+  unregisterAllNotificationBackends();
   delete _style;
   delete mainWin;
 }
@@ -75,3 +76,22 @@ void QtUi::connectedToCore() {
 void QtUi::disconnectedFromCore() {
   mainWin->disconnectedFromCore();
 }
+
+void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
+  if(!_notificationBackends.contains(backend)) {
+    _notificationBackends.insert(backend);
+  }
+}
+
+void QtUi::unregisterNotificationBackend(AbstractNotificationBackend *backend) {
+  _notificationBackends.remove(backend);
+}
+
+void QtUi::unregisterAllNotificationBackends() {
+  _notificationBackends.clear();
+}
+
+void QtUi::notify(BufferId id, const QString &sender, const QString &text) {
+  foreach(AbstractNotificationBackend *backend, _notificationBackends)
+    backend->notify(id, sender, text);
+}
index 9ac3b97..33eb1b8 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "quasselui.h"
 
+class AbstractNotificationBackend;
 class ActionCollection;
 class MainWin;
 class MessageModel;
@@ -52,6 +53,11 @@ public:
    */
   inline static ActionCollection *actionCollection();
 
+  static void registerNotificationBackend(AbstractNotificationBackend *);
+  static void unregisterNotificationBackend(AbstractNotificationBackend *);
+  static void unregisterAllNotificationBackends();
+  static void notify(BufferId bufId, const QString &sender, const QString &text);
+
 public slots:
   void init();
 
@@ -63,6 +69,7 @@ private:
   MainWin *mainWin;
   static ActionCollection *_actionCollection;
   static QtUiStyle *_style;
+  static QSet<AbstractNotificationBackend *> _notificationBackends;
 };
 
 ActionCollection *QtUi::actionCollection() { return _actionCollection; }
index 19befca..f18aa0e 100644 (file)
@@ -7,6 +7,7 @@ include(${QT_USE_FILE})
 set(SOURCES
     abstractbuffercontainer.cpp
     abstractitemview.cpp
+    abstractnotificationbackend.cpp
     action.cpp
     actioncollection.cpp
     bufferview.cpp
@@ -27,6 +28,7 @@ set(SOURCES
 set(MOC_HDRS
     abstractbuffercontainer.h
     abstractitemview.h
+    abstractnotificationbackend.h
     action.h
     actioncollection.h
     bufferview.h
diff --git a/src/uisupport/abstractnotificationbackend.cpp b/src/uisupport/abstractnotificationbackend.cpp
new file mode 100644 (file)
index 0000000..3131032
--- /dev/null
@@ -0,0 +1,22 @@
+/***************************************************************************
+*   Copyright (C) 2005-08 by the Quassel Project                          *
+*   devel@quassel-irc.org                                                 *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) version 3.                                           *
+*                                                                         *
+*   This program is distributed in the hope that it will be useful,       *
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+*   GNU General Public License for more details.                          *
+*                                                                         *
+*   You should have received a copy of the GNU General Public License     *
+*   along with this program; if not, write to the                         *
+*   Free Software Foundation, Inc.,                                       *
+*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+***************************************************************************/
+
+#include "abstractnotificationbackend.h"
+
diff --git a/src/uisupport/abstractnotificationbackend.h b/src/uisupport/abstractnotificationbackend.h
new file mode 100644 (file)
index 0000000..22c7600
--- /dev/null
@@ -0,0 +1,43 @@
+/***************************************************************************
+*   Copyright (C) 2005-08 by the Quassel Project                          *
+*   devel@quassel-irc.org                                                 *
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) version 3.                                           *
+*                                                                         *
+*   This program is distributed in the hope that it will be useful,       *
+*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+*   GNU General Public License for more details.                          *
+*                                                                         *
+*   You should have received a copy of the GNU General Public License     *
+*   along with this program; if not, write to the                         *
+*   Free Software Foundation, Inc.,                                       *
+*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+***************************************************************************/
+
+#ifndef ABSTRACTNOTIFICATIONBACKEND_H_
+#define ABSTRACTNOTIFICATIONBACKEND_H_
+
+#include <QObject>
+#include <QString>
+
+#include "bufferinfo.h"
+
+class SettingsPage;
+
+class AbstractNotificationBackend : public QObject {
+  Q_OBJECT
+
+  public:
+    //AbstractNotificationBackend(QObject *parent);
+    //virtual ~AbstractNotificationBackend();
+
+    virtual void notify(BufferId bufId, const QString &sender, const QString &text) = 0;
+    virtual SettingsPage *configWidget() const = 0;
+
+};
+
+#endif