Revert "moved timeout code"

This reverts commit f8bd3fad8a.
This commit is contained in:
Patrick von Reth 2014-01-18 18:40:26 +01:00
parent f8bd3fad8a
commit 8b57c2a41b
4 changed files with 48 additions and 46 deletions

View File

@ -67,6 +67,48 @@ const QString &SnorePlugin::name() const
return m_name; return m_name;
} }
void SnorePlugin::startTimeout(Notification &notification)
{
if(notification.sticky())
{
return;
}
uint id = notification.id();
QTimer *timer = qvariant_cast<QTimer*>(notification.hints().privateValue(this, "timeout"));
if(notification.updateID() != (uint)-1)
{
id = notification.updateID();
}
if(timer)
{
timer->stop();
}
else
{
timer = new QTimer(this);
timer->setSingleShot(true);
timer->setProperty("notificationID", id);
}
timer->setInterval(notification.timeout() * 1000);
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
timer->start();
}
void SnorePlugin::notificationTimedOut()
{
QTimer *timer = qobject_cast<QTimer*>(sender());
Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt());
if(n.isValid())
{
qDebug() << Q_FUNC_INFO << n;
timer->deleteLater();
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
timer->deleteLater();
}
bool SnorePlugin::deinitialize() bool SnorePlugin::deinitialize()
{ {
if(m_initialized) if(m_initialized)

View File

@ -54,6 +54,11 @@ public:
SnoreCore* snore(); SnoreCore* snore();
const QString &name() const; const QString &name() const;
protected:
void startTimeout(Notification &notification);
private slots:
void notificationTimedOut();
private: private:
SnorePlugin() {} SnorePlugin() {}
QString m_name; QString m_name;

View File

@ -167,45 +167,3 @@ bool SnoreBackend::deinitialize()
} }
return false; return false;
} }
void SnoreBackend::startTimeout(Notification &notification)
{
if(notification.sticky())
{
return;
}
uint id = notification.id();
QTimer *timer = qvariant_cast<QTimer*>(notification.hints().privateValue(this, "timeout"));
if(notification.updateID() != (uint)-1)
{
id = notification.updateID();
}
if(timer)
{
timer->stop();
}
else
{
timer = new QTimer(this);
timer->setSingleShot(true);
timer->setProperty("notificationID", id);
}
timer->setInterval(notification.timeout() * 1000);
connect(timer,SIGNAL(timeout()),this,SLOT(slotNotificationTimedOut()));
timer->start();
}
void SnoreBackend::slotNotificationTimedOut()
{
QTimer *timer = qobject_cast<QTimer*>(sender());
Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt());
if(n.isValid())
{
qDebug() << Q_FUNC_INFO << n;
timer->deleteLater();
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
timer->deleteLater();
}

View File

@ -56,12 +56,9 @@ public slots:
virtual void slotNotify ( Snore::Notification notification ) = 0; virtual void slotNotify ( Snore::Notification notification ) = 0;
virtual void slotCloseNotification ( Snore::Notification notification ); virtual void slotCloseNotification ( Snore::Notification notification );
private slots:
void slotNotificationTimedOut();
protected: protected:
void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons); void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons);
void startTimeout(Notification &notification);
private: private:
QHash<uint,Notification> m_activeNotifications; QHash<uint,Notification> m_activeNotifications;