fixed tray icon

This commit is contained in:
Patrick von Reth 2014-01-16 09:41:05 +01:00
parent 39191c146b
commit 2171ed455b
2 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,13 @@ Q_EXPORT_PLUGIN2(trayicon,TrayIconNotifer)
TrayIconNotifer::TrayIconNotifer () :
SnoreBackend ( "SystemTray",false,false ),
m_trayIcon(NULL),
m_displayed(-1)
m_displayed(-1),
m_currentlyDisplaying(false)
{
}
TrayIconNotifer::~TrayIconNotifer()
{
}
@ -46,25 +52,26 @@ bool TrayIconNotifer::deinitialize()
void TrayIconNotifer::slotNotify( Notification notification )
{
m_notificationQue.append(notification);
if(m_lastNotify.elapsed()> Notification::defaultTimeout() * 1000)
qDebug() << notification << m_currentlyDisplaying;
if(!m_currentlyDisplaying)
{
m_currentlyDisplaying = true;
displayNotification();
}
}
void TrayIconNotifer::displayNotification()
{
qDebug()<<"Display"<<m_notificationQue.size();
Notification notification = m_notificationQue.takeFirst();
if(!m_notificationQue.isEmpty())
if(m_notificationQue.isEmpty())
{
QTimer::singleShot(notification.timeout()*1000,this,SLOT(slotCloseNotificationByTimeout()));
m_currentlyDisplaying = false;
return;
}
qDebug()<<"taking"<<notification.title();
m_currentlyDisplaying = true;
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 );
m_lastNotify.restart();
QTimer::singleShot(notification.timeout()*1000,this,SLOT(slotCloseNotificationByTimeout()));
}
void TrayIconNotifer::slotCloseNotificationByTimeout()

View File

@ -3,7 +3,6 @@
#include "core/plugins/snorebackend.h"
#include <QTime>
namespace Snore{
class SnoreCore;
@ -18,6 +17,7 @@ class TrayIconNotifer:public Snore::SnoreBackend
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
public:
TrayIconNotifer ();
virtual ~TrayIconNotifer();
virtual bool initialize(Snore::SnoreCore *snore);
virtual bool deinitialize();
@ -27,8 +27,8 @@ public slots:
private:
QSystemTrayIcon *m_trayIcon;
QList<Snore::Notification > m_notificationQue;
QTime m_lastNotify;
uint m_displayed;
bool m_currentlyDisplaying;
private slots:
void displayNotification();