From 2dcde7b37ab0b7fbf5936ed851871eeab9d10fe8 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 18 Apr 2015 13:58:10 +0200 Subject: [PATCH] cleanup the frontend code --- src/libsnore/notification/notification_p.cpp | 12 ----------- src/libsnore/notification/notification_p.h | 4 ---- src/libsnore/plugins/snorebackend.cpp | 1 + src/libsnore/plugins/snorefrontend.cpp | 21 +++++++++++++++++-- src/libsnore/plugins/snorefrontend.h | 9 ++++++-- src/libsnore/snore_p.cpp | 13 +++--------- src/libsnore/snore_p.h | 2 +- .../freedesktopnotificationfrontend.cpp | 5 ++--- .../freedesktopnotificationfrontend.h | 7 ++++--- src/plugins/frontends/snarlnetwork/parser.cpp | 1 - .../frontends/snarlnetwork/snarlnetwork.cpp | 4 ++-- .../frontends/snarlnetwork/snarlnetwork.h | 5 +++-- 12 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/libsnore/notification/notification_p.cpp b/src/libsnore/notification/notification_p.cpp index b3b7a0e..f47426d 100644 --- a/src/libsnore/notification/notification_p.cpp +++ b/src/libsnore/notification/notification_p.cpp @@ -33,7 +33,6 @@ NotificationData::NotificationData(const Snore::Application &application, const int timeout, Notification::Prioritys priority): m_id(m_idCount++), m_timeout(timeout), - m_source(NULL), m_application(application), m_alert(alert), m_title(title), @@ -49,7 +48,6 @@ NotificationData::NotificationData(const Snore::Application &application, const Snore::NotificationData::NotificationData(const Notification &old, const QString &title, const QString &text, const Icon &icon, int timeout, Notification::Prioritys priority): m_id(m_idCount++), m_timeout(timeout), - m_source(NULL), m_application(old.application()), m_alert(old.alert()), m_title(title), @@ -79,16 +77,6 @@ void NotificationData::setActionInvoked(const int &id) m_actionInvoked = m_actions[id]; } -void NotificationData::setSource(SnoreFrontend *source) -{ - m_source = source; -} - -SnoreFrontend *NotificationData::source() const -{ - return m_source; -} - void NotificationData::setCloseReason(Snore::Notification::CloseReasons r) { m_closeReason = r; diff --git a/src/libsnore/notification/notification_p.h b/src/libsnore/notification/notification_p.h index 6a3ee9f..67ed416 100644 --- a/src/libsnore/notification/notification_p.h +++ b/src/libsnore/notification/notification_p.h @@ -41,9 +41,6 @@ public: ~NotificationData(); - void setSource(class SnoreFrontend *source); - class SnoreFrontend *source() const; - void setActionInvoked(const Action &action); void setActionInvoked(const int &actionID); @@ -57,7 +54,6 @@ private: uint m_id; uint m_updateID; int m_timeout; - SnoreFrontend *m_source; Application m_application; Alert m_alert; QString m_title; diff --git a/src/libsnore/plugins/snorebackend.cpp b/src/libsnore/plugins/snorebackend.cpp index 72afdd4..db71aee 100644 --- a/src/libsnore/plugins/snorebackend.cpp +++ b/src/libsnore/plugins/snorebackend.cpp @@ -189,6 +189,7 @@ bool SnoreBackend::deinitialize() void SnoreBackend::startTimeout(Notification ¬ification) { if (thread() != QThread::currentThread()) { + snoreDebug(SNORE_WARNING) << "Plugin timeout in wrong thread."; metaObject()->invokeMethod(this, "startTimeout", Qt::QueuedConnection, Q_ARG(Notification, notification)); return; } diff --git a/src/libsnore/plugins/snorefrontend.cpp b/src/libsnore/plugins/snorefrontend.cpp index 023dc16..ca2dd47 100644 --- a/src/libsnore/plugins/snorefrontend.cpp +++ b/src/libsnore/plugins/snorefrontend.cpp @@ -19,8 +19,7 @@ #include "snorefrontend.h" #include "../snore.h" -namespace Snore -{ +using namespace Snore; SnoreFrontend::SnoreFrontend(const QString &name) : SnorePlugin(name) @@ -33,4 +32,22 @@ SnoreFrontend::~SnoreFrontend() snoreDebug(SNORE_DEBUG) << "Deleting" << name(); } +bool SnoreFrontend::initialize() +{ + if (!SnorePlugin::initialize()) { + return false; + } + connect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection); + connect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection); + return true; +} + +bool SnoreFrontend::deinitialize() +{ + if (SnorePlugin::deinitialize()) { + disconnect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed); + disconnect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked); + return true; + } + return false; } diff --git a/src/libsnore/plugins/snorefrontend.h b/src/libsnore/plugins/snorefrontend.h index 26425bb..a658e68 100644 --- a/src/libsnore/plugins/snorefrontend.h +++ b/src/libsnore/plugins/snorefrontend.h @@ -33,8 +33,13 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin public: SnoreFrontend(const QString &name); virtual ~SnoreFrontend(); - virtual void actionInvoked(Snore::Notification notification) = 0; - virtual void notificationClosed(Snore::Notification notification) = 0; + + virtual bool initialize() override; + virtual bool deinitialize() override; + +public slots: + virtual void slotActionInvoked(Snore::Notification notification) = 0; + virtual void slotNotificationClosed(Snore::Notification notification) = 0; }; } diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index 243124b..d6d92b4 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -59,13 +59,10 @@ Application SnoreCorePrivate::defaultApplication() return m_defaultApp; } -void SnoreCorePrivate::notificationActionInvoked(Notification notification) const +void SnoreCorePrivate::notificationActionInvoked(Notification notification) { - Q_Q(const SnoreCore); - emit const_cast(q)->actionInvoked(notification); - if (notification.data()->source()) { - notification.data()->source()->actionInvoked(notification); - } + Q_Q(SnoreCore); + emit q->actionInvoked(notification); } bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend) @@ -219,10 +216,6 @@ void SnoreCorePrivate::slotNotificationClosed(Notification n) { Q_Q(SnoreCore); emit q->notificationClosed(n); - if (n.data()->source()) { - //TODO: drop source and use signal aswell - n.data()->source()->notificationClosed(n); - } } void SnoreCorePrivate::slotAboutToQuit() diff --git a/src/libsnore/snore_p.h b/src/libsnore/snore_p.h index 37d15c0..e32c49a 100644 --- a/src/libsnore/snore_p.h +++ b/src/libsnore/snore_p.h @@ -49,7 +49,7 @@ public: ~SnoreCorePrivate(); Application defaultApplication(); - void notificationActionInvoked(Notification notification) const; + void notificationActionInvoked(Notification notification); bool setBackendIfAvailible(const QString &backend); diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 1faf623..c620656 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -68,14 +68,14 @@ bool FreedesktopFrontend::deinitialize() return false; } -void FreedesktopFrontend::actionInvoked(Notification notification) +void FreedesktopFrontend::slotActionInvoked(Notification notification) { if (notification.actionInvoked().isValid()) { emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id())); } } -void FreedesktopFrontend::notificationClosed(Notification notification) +void FreedesktopFrontend::slotNotificationClosed(Notification notification) { emit NotificationClosed(notification.id(), notification.closeReason()); } @@ -124,7 +124,6 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, } else { noti = Notification(app, *app.alerts().begin(), summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity); } - noti.data()->setSource(this); for (int i = 0; i < actions.length(); i += 2) { noti.addAction(Action(actions.at(i).toInt(), actions.at(i + 1))); } diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h index 14af551..99eeae0 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.h @@ -34,9 +34,6 @@ public: virtual bool initialize() override; virtual bool deinitialize() override; - void actionInvoked(Snore::Notification notification) override; - void notificationClosed(Snore::Notification notification) override; - uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout); void CloseNotification(uint id); @@ -47,6 +44,10 @@ signals: void NotificationClosed(uint id, uint reason); void ActionInvoked(uint id, const QString &actionKey); +public slots: + void slotActionInvoked(Snore::Notification notification) override; + void slotNotificationClosed(Snore::Notification notification) override; + private: Snore::Alert m_alert; Snore::Icon m_icon; diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index c629ff0..4e2e81f 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -116,7 +116,6 @@ void Parser::parse(Notification &sNotification, const QString &msg, QTcpSocket * break; } sNotification = Notification(app, alert, title, text, icon, timeout); - sNotification.data()->setSource(snarl); sNotification.hints().setPrivateValue(snarl, "clientSocket", client); break; } diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index a3d298c..cad30cb 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -62,13 +62,13 @@ bool SnarlNetworkFrontend::deinitialize() return false; } -void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification) +void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification) { snoreDebug(SNORE_DEBUG) << notification.closeReason(); callback(notification, "SNP/1.1/304/Notification acknowledged/"); } -void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) +void SnarlNetworkFrontend::slotNotificationClosed(Snore::Notification notification) { switch (notification.closeReason()) { case Notification::TIMED_OUT: diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.h b/src/plugins/frontends/snarlnetwork/snarlnetwork.h index 385fbd8..abfdce5 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.h +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.h @@ -40,8 +40,9 @@ public: virtual bool initialize() override; virtual bool deinitialize() override; - void actionInvoked(Snore::Notification notification) override; - void notificationClosed(Snore::Notification notification) override; +public slots: + void slotActionInvoked(Snore::Notification notification) override; + void slotNotificationClosed(Snore::Notification notification) override; private slots: void handleConnection();