better timeout stuff
This commit is contained in:
parent
dccaf09ff1
commit
0a4093ecda
|
@ -50,6 +50,10 @@ NotificationData::NotificationData (const Snore::Application &application, const
|
||||||
|
|
||||||
NotificationData::~NotificationData()
|
NotificationData::~NotificationData()
|
||||||
{
|
{
|
||||||
|
if(!m_timeoutTimer.isNull())
|
||||||
|
{
|
||||||
|
m_timeoutTimer->deleteLater();
|
||||||
|
}
|
||||||
notificationCount--;
|
notificationCount--;
|
||||||
qDebug() << "Deleting Notification: ActiveNotifications" << notificationCount << "id" << m_id << "Close Reason:" << m_closeReason;
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include "../hint.h"
|
#include "../hint.h"
|
||||||
|
|
||||||
#include <QSharedData>
|
#include <QSharedData>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
|
|
||||||
namespace Snore{
|
namespace Snore{
|
||||||
|
@ -49,6 +51,8 @@ public:
|
||||||
|
|
||||||
void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r);
|
void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r);
|
||||||
|
|
||||||
|
QTimer *timeoutTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(NotificationData)
|
Q_DISABLE_COPY(NotificationData)
|
||||||
|
|
||||||
|
@ -67,6 +71,7 @@ private:
|
||||||
QHash<int,Action> m_actions;
|
QHash<int,Action> m_actions;
|
||||||
Hint m_hints;
|
Hint m_hints;
|
||||||
Notification m_toReplace;
|
Notification m_toReplace;
|
||||||
|
QPointer<QTimer> m_timeoutTimer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "../snore.h"
|
#include "../snore.h"
|
||||||
#include "snorebackend.h"
|
#include "snorebackend.h"
|
||||||
#include "snorefrontend.h"
|
#include "snorefrontend.h"
|
||||||
|
#include "../notification/notification_p.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
|
@ -73,29 +74,12 @@ void SnorePlugin::startTimeout(Notification ¬ification)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
uint id = notification.id();
|
QTimer *timer = notification.data()->timeoutTimer();
|
||||||
QTimer *timer = myQVariantCast<QTimer*>(notification.hints().privateValue(this, "timeout"));
|
timer->stop();
|
||||||
if(notification.isUpdate())
|
if(notification.isUpdate())
|
||||||
{
|
{
|
||||||
id = notification.notificationToReplace().id();
|
notification.notificationToReplace().data()->timeoutTimer()->stop();
|
||||||
QTimer *old = myQVariantCast<QTimer*>(notification.notificationToReplace().hints().privateValue(this, "timeout"));
|
|
||||||
if(old)
|
|
||||||
{
|
|
||||||
old->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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);
|
timer->setInterval(notification.timeout() * 1000);
|
||||||
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
|
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
|
||||||
timer->start();
|
timer->start();
|
||||||
|
@ -109,10 +93,8 @@ void SnorePlugin::notificationTimedOut()
|
||||||
if(n.isValid())
|
if(n.isValid())
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << n;
|
qDebug() << Q_FUNC_INFO << n;
|
||||||
timer->deleteLater();
|
|
||||||
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
|
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||||
}
|
}
|
||||||
timer->deleteLater();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnorePlugin::deinitialize()
|
bool SnorePlugin::deinitialize()
|
||||||
|
|
Loading…
Reference in New Issue