moved timeout code
This commit is contained in:
parent
63f98fa638
commit
f8bd3fad8a
|
@ -67,48 +67,6 @@ const QString &SnorePlugin::name() const
|
|||
return m_name;
|
||||
}
|
||||
|
||||
void SnorePlugin::startTimeout(Notification ¬ification)
|
||||
{
|
||||
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()
|
||||
{
|
||||
if(m_initialized)
|
||||
|
|
|
@ -54,11 +54,6 @@ public:
|
|||
SnoreCore* snore();
|
||||
const QString &name() const;
|
||||
|
||||
protected:
|
||||
void startTimeout(Notification ¬ification);
|
||||
private slots:
|
||||
void notificationTimedOut();
|
||||
|
||||
private:
|
||||
SnorePlugin() {}
|
||||
QString m_name;
|
||||
|
|
|
@ -167,3 +167,45 @@ bool SnoreBackend::deinitialize()
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SnoreBackend::startTimeout(Notification ¬ification)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -56,9 +56,12 @@ public slots:
|
|||
virtual void slotNotify ( Snore::Notification notification ) = 0;
|
||||
virtual void slotCloseNotification ( Snore::Notification notification );
|
||||
|
||||
private slots:
|
||||
void slotNotificationTimedOut();
|
||||
|
||||
protected:
|
||||
void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons);
|
||||
|
||||
void startTimeout(Notification ¬ification);
|
||||
|
||||
private:
|
||||
QHash<uint,Notification> m_activeNotifications;
|
||||
|
|
Loading…
Reference in New Issue