only backends should start the timeout

This commit is contained in:
Patrick von Reth 2014-01-19 19:09:01 +01:00
parent a3b2805d7b
commit 3494164dce
7 changed files with 40 additions and 38 deletions

View File

@ -68,35 +68,6 @@ const QString &SnorePlugin::name() const
return m_name;
}
void SnorePlugin::startTimeout(Notification &notification)
{
if(notification.isSticky())
{
return;
}
QTimer *timer = notification.data()->timeoutTimer();
timer->stop();
if(notification.isUpdate())
{
notification.old().data()->timeoutTimer()->stop();
}
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;
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
}
bool SnorePlugin::deinitialize()
{
if(m_initialized)

View File

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

View File

@ -173,3 +173,33 @@ bool SnoreBackend::deinitialize()
}
return false;
}
void SnoreBackend::startTimeout(Notification &notification)
{
if(notification.isSticky())
{
return;
}
QTimer *timer = notification.data()->timeoutTimer();
timer->stop();
if(notification.isUpdate())
{
notification.old().data()->timeoutTimer()->stop();
}
timer->setInterval(notification.timeout() * 1000);
connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut()));
timer->start();
}
void SnoreBackend::notificationTimedOut()
{
QTimer *timer = qobject_cast<QTimer*>(sender());
Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt());
if(n.isValid())
{
qDebug() << Q_FUNC_INFO << n;
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
}

View File

@ -56,11 +56,14 @@ public slots:
virtual void slotNotify ( Snore::Notification notification ) = 0;
virtual void slotCloseNotification ( Snore::Notification notification );
private slots:
void notificationTimedOut();
protected:
void startTimeout(Notification &notification);
void closeNotification(Snore::Notification,Snore::NotificationEnums::CloseReasons::closeReasons);
void setSupportsRichtext(bool b);
private:
QHash<uint,Notification> m_activeNotifications;

View File

@ -137,6 +137,7 @@ void Growl::slotNotify(Notification notification)
{
qWarning() << Q_FUNC_INFO << e.what();
}
startTimeout(notification);
}
void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data)

View File

@ -265,5 +265,7 @@ void SnarlBackend::slotCloseNotification(Notification notification)
qDebug() << Q_FUNC_INFO << "Unknown apllication: " << notification.application().name();
return;
}
m_applications.value(notification.application().name())->Hide(notification.hints().privateValue(this, "id").toUInt());
ULONG32 id = notification.hints().privateValue(this, "id").toUInt();
m_idMap.take(id);
m_applications.value(notification.application().name())->Hide(id);
}

View File

@ -143,13 +143,13 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
}
snore()->broadcastNotification(noti);
startTimeout(noti);
return noti.id();
}
void FreedesktopFrontend::CloseNotification(uint id){
void FreedesktopFrontend::CloseNotification(uint id)
{
Notification noti = snore()->getActiveNotificationByID(id);
if(noti.isValid())
{