diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2e5b4..20876e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ include(GNUInstallDirs) ####################################################################### -option(WITH_WITH_KDE "Try to build with KDE support if availibe" ON) +option(WITH_KDE "Try to build with KDE support if availibe" ON) option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF) option(WITH_GROWL_BACKEND "Build the Growl backend" ON) option(WITH_SNORE_DEAMON "Build the Snore deamon, which redirects notifications" OFF) @@ -19,7 +19,7 @@ set(SNORE_VERSION_MAJOR 0) set(SNORE_VERSION_MINOR 5) set(SNORE_VERSION_SUFFIX "pre") -if(WITH_WITH_KDE) +if(WITH_KDE) find_package(KDE4) endif() diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index e3ee2b1..de2f8c2 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -73,14 +73,19 @@ const int &Notification::timeout() const return d->m_timeout; } -void Notification::setUpdateID(uint id) +void Notification::setNotificationToReplace(const Notification &n) { - d->m_updateID = id; + d->m_toReplace = n; } -uint Notification::updateID() const +Notification Notification::notificationToReplace() const { - return d->m_updateID; + return d->m_toReplace; +} + +bool Notification::isUpdate() const +{ + return d->m_toReplace.isValid(); } const Action &Notification::actionInvoked() const diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index 292a077..dfbe360 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -50,8 +50,9 @@ public: //0 means sticky const int &timeout() const; - void setUpdateID(uint id); - uint updateID() const; + void setNotificationToReplace(const Notification &n); + Notification notificationToReplace() const; + bool isUpdate() const; const Action &actionInvoked() const; const Application &application() const; diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp index 48f8528..4a91573 100644 --- a/src/core/notification/notification_p.cpp +++ b/src/core/notification/notification_p.cpp @@ -34,7 +34,6 @@ uint NotificationData::m_idCount = 1; NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon, int timeout, NotificationEnums::Prioritys::prioritys priority ): m_id ( m_idCount++ ), - m_updateID((uint)-1), m_timeout( timeout ), m_source( NULL), m_application ( application ), diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 06886f7..7b975f4 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -66,6 +66,7 @@ private: Action m_actionInvoked; QHash m_actions; Hint m_hints; + Notification m_toReplace; diff --git a/src/core/notification/notificationaction.cpp b/src/core/notification/notificationaction.cpp index 868e1ef..82f6697 100644 --- a/src/core/notification/notificationaction.cpp +++ b/src/core/notification/notificationaction.cpp @@ -41,7 +41,7 @@ QString Action::name() const bool Action::isValid() const { - return m_name.isNull(); + return !m_name.isNull(); } int Action::id() const diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index b671f11..1133eb5 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -75,9 +75,14 @@ void SnorePlugin::startTimeout(Notification ¬ification) } uint id = notification.id(); QTimer *timer = myQVariantCast(notification.hints().privateValue(this, "timeout")); - if(notification.updateID() != (uint)-1) + if(notification.isUpdate()) { - id = notification.updateID(); + id = notification.notificationToReplace().id(); + QTimer *old = myQVariantCast(notification.notificationToReplace().hints().privateValue(this, "timeout")); + if(old) + { + old->deleteLater(); + } } if(timer) { diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 52b8295..5678fca 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -88,6 +88,7 @@ void SnoreBackend::closeNotification(Notification n, NotificationEnums::CloseRea } n.data()->setCloseReason(reason); slotCloseNotification(n); + qDebug() << Q_FUNC_INFO << n; emit notificationClosed(n); } diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp index fbeeefd..0c2e9dd 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.cpp @@ -17,11 +17,12 @@ Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopBackend ) FreedesktopBackend::FreedesktopBackend () : - SnoreBackend ( "FreedesktopNotification_Backend",true,true) + SnoreBackend ( "FreedesktopNotification",true,true) { } -bool FreedesktopBackend::initialize(SnoreCore *snore){ +bool FreedesktopBackend::initialize(SnoreCore *snore) +{ m_interface = new org::freedesktop::Notifications( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", QDBusConnection::sessionBus(), this ); @@ -74,11 +75,10 @@ void FreedesktopBackend::slotNotify ( Notification noti ) } uint updateId = 0; - if(noti.updateID() != 0) + if(noti.isUpdate()) { - updateId = m_snoreIdMap[noti.updateID()]; - m_dbusIdMap[updateId] = noti.id(); - m_snoreIdMap[noti.id()] = updateId; + updateId = noti.notificationToReplace().id(); + m_dbusIdMap.take(updateId); } QString title = QString("%1 - %2").arg(noti.application().name(), noti.title()); @@ -91,14 +91,16 @@ void FreedesktopBackend::slotNotify ( Notification noti ) QDBusPendingReply id = m_interface->Notify(noti.application().name(), updateId, "", title, body, actions, hints, noti.sticky()?-1:noti.timeout()*1000); - if(noti.updateID() == 0) - { - id.waitForFinished(); - m_snoreIdMap[noti.id()] = id.value(); - m_dbusIdMap[id.value()] = noti.id(); - } + + id.waitForFinished(); + noti.hints().setPrivateValue(this, "id", id.value()); + m_dbusIdMap[id.value()] = noti.id(); + + qDebug() << Q_FUNC_INFO << noti.id() << "|" << id.value(); } -void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID){ +void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &actionID) +{ + qDebug() << Q_FUNC_INFO << id << m_dbusIdMap[id]; Notification noti = getActiveNotificationByID(m_dbusIdMap[id]); if(!noti.isValid()) { @@ -110,12 +112,8 @@ void FreedesktopBackend::slotActionInvoked(const uint &id, const QString &action void FreedesktopBackend::slotCloseNotification ( Notification notification ) { - if(!m_snoreIdMap.contains(notification.id())) - { - return; - } - uint id = m_snoreIdMap.take(notification.id()); - m_dbusIdMap.remove(id); + uint id = notification.hints().privateValue(this, "id").toUInt(); + qDebug() << Q_FUNC_INFO << notification.id() << id; m_interface->CloseNotification(id); } @@ -124,7 +122,7 @@ void FreedesktopBackend::slotCloseNotification ( Notification notification ) void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &reason ) { NotificationEnums::CloseReasons::closeReasons closeReason = NotificationEnums::CloseReasons::closeReasons(reason); - qDebug() << Q_FUNC_INFO << "Closed" << id << "|" << closeReason << reason; + qDebug() << Q_FUNC_INFO << id << "|" << closeReason << reason; if(id == 0) { return; @@ -132,7 +130,6 @@ void FreedesktopBackend::slotNotificationClosed ( const uint &id,const uint &rea Notification noti = getActiveNotificationByID(m_dbusIdMap.take(id)); if(noti.isValid()) { - m_snoreIdMap.remove(noti.id()); closeNotification(noti, closeReason); } } diff --git a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h index 458a465..716dcbb 100644 --- a/src/plugins/backends/freedesktop/freedesktopnotification_backend.h +++ b/src/plugins/backends/freedesktop/freedesktopnotification_backend.h @@ -24,7 +24,6 @@ public slots: private: org::freedesktop::Notifications* m_interface; QHash m_dbusIdMap; - QHash m_snoreIdMap; };