From 2ab3040da0e42f4afdd282e34f0d8b089020a73d Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 4 Oct 2008 22:16:33 +0200 Subject: [PATCH] Add AbstractNotificationBackend to allow for a more modular approach to notifications 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 | 6 +++ src/client/quasselui.h | 11 +++-- src/qtui/qtui.cpp | 28 ++++++++++-- src/qtui/qtui.h | 7 +++ src/uisupport/CMakeLists.txt | 2 + src/uisupport/abstractnotificationbackend.cpp | 22 ++++++++++ src/uisupport/abstractnotificationbackend.h | 43 +++++++++++++++++++ 7 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 src/uisupport/abstractnotificationbackend.cpp create mode 100644 src/uisupport/abstractnotificationbackend.h diff --git a/src/client/quasselui.cpp b/src/client/quasselui.cpp index 6e0e0aa2..c559f169 100644 --- a/src/client/quasselui.cpp +++ b/src/client/quasselui.cpp @@ -20,4 +20,10 @@ #include "quasselui.h" +AbstractUi * AbstractUi::_instance = 0; bool AbstractUi::_visible = false; + +AbstractUi::AbstractUi() { + Q_ASSERT(!_instance); + _instance = this; +} diff --git a/src/client/quasselui.h b/src/client/quasselui.h index dac64be7..0a855fc2 100644 --- a/src/client/quasselui.h +++ b/src/client/quasselui.h @@ -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 diff --git a/src/qtui/qtui.cpp b/src/qtui/qtui.cpp index 85e6b1a6..14597604 100644 --- a/src/qtui/qtui.cpp +++ b/src/qtui/qtui.cpp @@ -20,21 +20,21 @@ #include "qtui.h" -#include - #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 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); +} diff --git a/src/qtui/qtui.h b/src/qtui/qtui.h index 9ac3b97b..33eb1b87 100644 --- a/src/qtui/qtui.h +++ b/src/qtui/qtui.h @@ -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 _notificationBackends; }; ActionCollection *QtUi::actionCollection() { return _actionCollection; } diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index 19befcac..f18aa0ef 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -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 index 00000000..31310321 --- /dev/null +++ b/src/uisupport/abstractnotificationbackend.cpp @@ -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 index 00000000..22c76003 --- /dev/null +++ b/src/uisupport/abstractnotificationbackend.h @@ -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 +#include + +#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 -- 2.20.1