From 7713c61fdb752acbe0687da1546e4d7f1ec94799 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Fri, 10 Jul 2015 12:17:57 +0200 Subject: [PATCH] prevent notification loops --- src/libsnore/notification/notification_p.h | 14 ++++++++++++++ .../freedesktopnotification_backend.cpp | 4 ++++ src/plugins/frontends/pushover/plugin.json | 2 +- .../secondary_backends/pushover/pushover.cpp | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/libsnore/notification/notification_p.h b/src/libsnore/notification/notification_p.h index ea4d2eb..c22fed2 100644 --- a/src/libsnore/notification/notification_p.h +++ b/src/libsnore/notification/notification_p.h @@ -54,6 +54,19 @@ public: bool isBroadcasted() const; + /** + * Sets the source SnorePlugin. + * @see source() + */ + void setSource(const SnorePlugin *soure); + + + /** + * Returns the source SnorePlugin. + * This is used to prevent notification loops between the frontend and the backend. + */ + const SnorePlugin* source() const; + private: Q_DISABLE_COPY(NotificationData) @@ -74,6 +87,7 @@ private: QScopedPointer m_timeoutTimer; QSet m_activeIn; bool m_isBroadcasted = false; + SnorePlugin *m_source = nullptr; static uint notificationCount; static uint m_idCount; diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index c8fcc5e..7dcb2a5 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -52,6 +52,10 @@ bool FreedesktopBackend::canUpdateNotification() const void FreedesktopBackend::slotNotify(Notification noti) { + if(noti.data()->source()->name() == name()) { + return; + } + QStringList actions; foreach (int k, noti.actions().keys()) { actions << QString::number(k) << noti.actions()[k].name(); diff --git a/src/plugins/frontends/pushover/plugin.json b/src/plugins/frontends/pushover/plugin.json index 5c9a046..2612772 100644 --- a/src/plugins/frontends/pushover/plugin.json +++ b/src/plugins/frontends/pushover/plugin.json @@ -1 +1 @@ -{ "type" : "frontend", "name" : "Pushover Frontend" } \ No newline at end of file +{ "type" : "frontend", "name" : "Pushover" } \ No newline at end of file diff --git a/src/plugins/secondary_backends/pushover/pushover.cpp b/src/plugins/secondary_backends/pushover/pushover.cpp index 84cf50b..0e091d3 100644 --- a/src/plugins/secondary_backends/pushover/pushover.cpp +++ b/src/plugins/secondary_backends/pushover/pushover.cpp @@ -28,6 +28,10 @@ using namespace Snore; void Pushover::slotNotify(Notification notification) { + if(notification.data()->source()->name() == name()) { + return; + } + QString key = settingsValue(QLatin1String("UserKey")).toString(); if (key.isEmpty()) { return;