better timeout stuff

This commit is contained in:
Patrick von Reth 2014-01-19 16:38:12 +01:00
parent dccaf09ff1
commit 0a4093ecda
3 changed files with 24 additions and 22 deletions

View File

@ -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;
}

View File

@ -27,6 +27,8 @@
#include "../hint.h"
#include <QSharedData>
#include <QTimer>
#include <QPointer>
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<int,Action> m_actions;
Hint m_hints;
Notification m_toReplace;
QPointer<QTimer> m_timeoutTimer;

View File

@ -20,6 +20,7 @@
#include "../snore.h"
#include "snorebackend.h"
#include "snorefrontend.h"
#include "../notification/notification_p.h"
#include <QTimer>
#include <QPluginLoader>
@ -73,29 +74,12 @@ void SnorePlugin::startTimeout(Notification &notification)
{
return;
}
uint id = notification.id();
QTimer *timer = myQVariantCast<QTimer*>(notification.hints().privateValue(this, "timeout"));
QTimer *timer = notification.data()->timeoutTimer();
timer->stop();
if(notification.isUpdate())
{
id = notification.notificationToReplace().id();
QTimer *old = myQVariantCast<QTimer*>(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()