rewroite startTimer
This commit is contained in:
parent
f438c2a15c
commit
63f98fa638
|
@ -78,7 +78,7 @@ void Notification::setUpdateID(uint id)
|
|||
d->m_updateID = id;
|
||||
}
|
||||
|
||||
const uint &Notification::updateID() const
|
||||
uint Notification::updateID() const
|
||||
{
|
||||
return d->m_updateID;
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
const int &timeout() const;
|
||||
|
||||
void setUpdateID(uint id);
|
||||
const uint &updateID() const;
|
||||
uint updateID() const;
|
||||
|
||||
const Action &actionInvoked() const;
|
||||
const Application &application() const;
|
||||
|
|
|
@ -34,7 +34,7 @@ uint NotificationData::m_idCount = 1;
|
|||
NotificationData::NotificationData (const Snore::Application &application, const Snore::Alert &alert, const QString &title, const QString &text, const Icon &icon,
|
||||
int timeout, NotificationEnums::Prioritys::prioritys priority ):
|
||||
m_id ( m_idCount++ ),
|
||||
m_updateID(0),
|
||||
m_updateID((uint)-1),
|
||||
m_timeout( timeout ),
|
||||
m_source( NULL),
|
||||
m_application ( application ),
|
||||
|
|
|
@ -67,36 +67,46 @@ const QString &SnorePlugin::name() const
|
|||
return m_name;
|
||||
}
|
||||
|
||||
void SnorePlugin::startTimeout(uint id,int timeout){
|
||||
if(timeout == -1)//sticky
|
||||
void SnorePlugin::startTimeout(Notification ¬ification)
|
||||
{
|
||||
if(notification.sticky())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(m_timeouts.contains(id)){
|
||||
QTimer *t = m_timeouts.take(id);
|
||||
t->stop();
|
||||
t->deleteLater();
|
||||
m_timeout_order.removeOne(id);
|
||||
uint id = notification.id();
|
||||
QTimer *timer = qvariant_cast<QTimer*>(notification.hints().privateValue(this, "timeout"));
|
||||
if(notification.updateID() != (uint)-1)
|
||||
{
|
||||
id = notification.updateID();
|
||||
}
|
||||
QTimer *timer= new QTimer(this);
|
||||
timer->setInterval(timeout*1000);
|
||||
timer->setSingleShot(true);
|
||||
m_timeouts.insert(id,timer);
|
||||
m_timeout_order.append(id);
|
||||
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()
|
||||
{
|
||||
uint id = m_timeout_order.takeFirst();
|
||||
m_timeouts.take(id)->deleteLater();
|
||||
Notification n = snore()->getActiveNotificationByID(id);
|
||||
|
||||
QTimer *timer = qobject_cast<QTimer*>(sender());
|
||||
Notification n = snore()->getActiveNotificationByID(timer->property("notificationID").toUInt());
|
||||
if(n.isValid())
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO ;
|
||||
qDebug() << Q_FUNC_INFO << n;
|
||||
timer->deleteLater();
|
||||
snore()->requestCloseNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
timer->deleteLater();
|
||||
}
|
||||
|
||||
bool SnorePlugin::deinitialize()
|
||||
|
|
|
@ -20,12 +20,14 @@
|
|||
#ifndef SNORE_PLUGINS_H
|
||||
#define SNORE_PLUGINS_H
|
||||
#include "../snore_exports.h"
|
||||
#include "../notification/notification.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QHash>
|
||||
#include <QTimer>
|
||||
#include <QtPlugin>
|
||||
|
||||
|
||||
namespace Snore{
|
||||
class Application;
|
||||
class SnoreCore;
|
||||
|
@ -53,7 +55,7 @@ public:
|
|||
const QString &name() const;
|
||||
|
||||
protected:
|
||||
void startTimeout(uint id,int timeout);
|
||||
void startTimeout(Notification ¬ification);
|
||||
private slots:
|
||||
void notificationTimedOut();
|
||||
|
||||
|
@ -62,8 +64,6 @@ private:
|
|||
QString m_name;
|
||||
bool m_initialized;
|
||||
QPointer<SnoreCore> m_snore;
|
||||
QHash<uint,QTimer*> m_timeouts;
|
||||
QList<uint> m_timeout_order;
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -229,7 +229,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
break;
|
||||
}
|
||||
|
||||
if(notification.updateID() == 0)
|
||||
if(notification.updateID() == (uint)-1)
|
||||
{
|
||||
ULONG32 id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
|
||||
Snore::toPlainText(notification.title()).toUtf8().constData(),
|
||||
|
@ -244,7 +244,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
snarlInterface->AddAction(id,a.name().toUtf8().constData(),QString("@").append(QString::number(a.id())).toUtf8().constData());
|
||||
}
|
||||
m_idMap[notification.id()] = id;
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
startTimeout(notification);
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -259,7 +259,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
|||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||
priority);
|
||||
m_idMap[notification.id()] = m_idMap[notification.updateID()];
|
||||
startTimeout(notification.updateID(),notification.timeout());
|
||||
startTimeout(notification);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ void TrayIconNotifer::displayNotification()
|
|||
Notification notification = m_notificationQue.takeFirst();
|
||||
m_displayed = notification.id();
|
||||
m_trayIcon->showMessage ( Snore::toPlainText(notification.title()),Snore::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||
startTimeout(notification.id(),notification.timeout());
|
||||
startTimeout(notification);
|
||||
}
|
||||
|
||||
void TrayIconNotifer::actionInvoked()
|
||||
|
|
Loading…
Reference in New Issue