prevent notification loops

This commit is contained in:
Patrick von Reth 2015-07-10 12:39:52 +02:00
parent 7713c61fdb
commit a586ca60e3
6 changed files with 32 additions and 4 deletions

View File

@ -113,3 +113,22 @@ bool NotificationData::isBroadcasted() const
return m_isBroadcasted;
}
void NotificationData::setSource(SnorePlugin *soure)
{
m_source = soure;
}
const SnorePlugin *NotificationData::source() const
{
return m_source;
}
bool NotificationData::sourceAndTargetAreSimilar(const SnorePlugin *target)
{
if(source() && source()->name() == target->name()) {
snoreDebug(SNORE_DEBUG) << "Source" << source() << "and Target" << target << "are the same.";
return true;
}
return false;
}

View File

@ -58,7 +58,7 @@ public:
* Sets the source SnorePlugin.
* @see source()
*/
void setSource(const SnorePlugin *soure);
void setSource(SnorePlugin *soure);
/**
@ -67,6 +67,12 @@ public:
*/
const SnorePlugin* source() const;
/**
* Returns true if the source->name() and the target->name() are the same.
* @todo rename
*/
bool sourceAndTargetAreSimilar(const SnorePlugin *target);
private:
Q_DISABLE_COPY(NotificationData)

View File

@ -52,7 +52,7 @@ bool FreedesktopBackend::canUpdateNotification() const
void FreedesktopBackend::slotNotify(Notification noti)
{
if(noti.data()->source()->name() == name()) {
if(noti.data()->sourceAndTargetAreSimilar(this)) {
return;
}

View File

@ -126,6 +126,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
}
noti.addActiveIn(this);
noti.data()->setSource(this);
SnoreCore::instance().broadcastNotification(noti);
return noti.id();
}

View File

@ -263,6 +263,7 @@ void PushoverFrontend::getMessages()
if (notification.value(QLatin1String("html")).toInt() == 1) {
n.hints().setValue("use-markup", true) ;
}
n.data()->setSource(this);
SnoreCore::instance().broadcastNotification(n);
}
if (latestID != -1) {

View File

@ -18,7 +18,8 @@
#include "pushover.h"
#include "pushoversettings.h"
#include"libsnore/utils.h"
#include "libsnore/utils.h"
#include "libsnore/notification/notification_p.h"
#include <QNetworkReply>
#include <QNetworkRequest>
@ -28,7 +29,7 @@ using namespace Snore;
void Pushover::slotNotify(Notification notification)
{
if(notification.data()->source()->name() == name()) {
if(notification.data()->sourceAndTargetAreSimilar(this)) {
return;
}