diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp index 4a91573..c71c1a5 100644 --- a/src/core/notification/notification_p.cpp +++ b/src/core/notification/notification_p.cpp @@ -50,6 +50,10 @@ NotificationData::NotificationData (const Snore::Application &application, const NotificationData::~NotificationData() { + if(!m_timeoutTimer.isNull()) + { + m_timeoutTimer->deleteLater(); + } notificationCount--; qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason; } @@ -80,3 +84,14 @@ void NotificationData::setCloseReason(const NotificationEnums::CloseReasons::clo m_closeReason = r; } +QTimer *NotificationData::timeoutTimer() +{ + if(m_timeoutTimer.isNull()) + { + m_timeoutTimer = new QTimer(); + m_timeoutTimer->setSingleShot(true); + m_timeoutTimer->setProperty("notificationID", m_id); + } + return m_timeoutTimer; +} + diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 7b975f4..9ad09d2 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -27,6 +27,8 @@ #include "../hint.h" #include +#include +#include namespace Snore{ @@ -49,6 +51,8 @@ public: void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); + QTimer *timeoutTimer(); + private: Q_DISABLE_COPY(NotificationData) @@ -67,6 +71,7 @@ private: QHash m_actions; Hint m_hints; Notification m_toReplace; + QPointer m_timeoutTimer; diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index 1133eb5..9cd2af2 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -20,6 +20,7 @@ #include "../snore.h" #include "snorebackend.h" #include "snorefrontend.h" +#include "../notification/notification_p.h" #include #include @@ -73,29 +74,12 @@ void SnorePlugin::startTimeout(Notification ¬ification) { return; } - uint id = notification.id(); - QTimer *timer = myQVariantCast(notification.hints().privateValue(this, "timeout")); + QTimer *timer = notification.data()->timeoutTimer(); + timer->stop(); if(notification.isUpdate()) { - id = notification.notificationToReplace().id(); - QTimer *old = myQVariantCast(notification.notificationToReplace().hints().privateValue(this, "timeout")); - if(old) - { - old->deleteLater(); - } + notification.notificationToReplace().data()->timeoutTimer()->stop(); } - if(timer) - { - timer->stop(); - } - else - { - timer = new QTimer(this); - timer->setSingleShot(true); - timer->setProperty("notificationID", id); - notification.hints().setPrivateValue(this, "timeout", myQVariantFromValue(timer)); - } - timer->setInterval(notification.timeout() * 1000); connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut())); timer->start(); @@ -109,10 +93,8 @@ void SnorePlugin::notificationTimedOut() if(n.isValid()) { qDebug() << Q_FUNC_INFO << n; - timer->deleteLater(); snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT); } - timer->deleteLater(); } bool SnorePlugin::deinitialize()