diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp index 65b8682..8c72ff5 100644 --- a/src/core/snoreserver.cpp +++ b/src/core/snoreserver.cpp @@ -145,11 +145,10 @@ int SnoreServer::broadcastNotification ( Notification notification ) void SnoreServer::closeNotification ( Notification notification,const NotificationEnums::CloseReasons::closeReasons &reason ) { - qDebug()<<"closing notification"<notificationClosed ( notification ); } @@ -157,8 +156,9 @@ void SnoreServer::closeNotification ( Notification notification,const Notificati void SnoreServer::notificationActionInvoked ( Notification notification ) { + emit actionInvoked(notification); Notification_Frontend *nf= notification.source(); - if ( nf!=0 ) + if ( nf != NULL ) { nf->actionInvoked ( notification ); } diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h index 0c68b08..945ec05 100644 --- a/src/core/snoreserver.h +++ b/src/core/snoreserver.h @@ -38,7 +38,7 @@ public: int broadcastNotification ( Notification notification ); - void closeNotification ( Notification notification, const NotificationEnums::CloseReasons::closeReasons &reason ); + void closeNotification ( Notification notification, const NotificationEnums::CloseReasons::closeReasons &reason ); void notificationActionInvoked ( Notification notification ); void addApplication ( Application *application ); @@ -67,6 +67,7 @@ signals: void applicationInitialized ( Application* ); void applicationRemoved ( Application* ); void notify ( Notification noti ); + void actionInvoked( Notification ); void closeNotify ( Notification ); }; diff --git a/src/core/trayiconnotifer.cpp b/src/core/trayiconnotifer.cpp index bffca2d..d5e7540 100644 --- a/src/core/trayiconnotifer.cpp +++ b/src/core/trayiconnotifer.cpp @@ -1,31 +1,33 @@ #include "trayiconnotifer.h" +#include "snoreserver.h" #include #include +#include #include TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) : - Notification_Backend ( "TrayiconNotifer",snore ), - _trayIcon ( icon ), - _noNotificationDisplayed(true), - _id ( 0 ) -{} + Notification_Backend ( "TrayiconNotifer",snore ), + _trayIcon ( icon ), + _id ( 0 ), + _displayed(-1) +{ + connect(_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked())); +} void TrayIconNotifer::registerApplication ( Application *application ) { Q_UNUSED ( application ) - } +} void TrayIconNotifer::unregisterApplication ( Application *application ) { Q_UNUSED ( application ) - } +} int TrayIconNotifer::notify ( Notification notification ) { _notificationQue.append(notification); - qDebug()<<"appending"< Notification::DefaultTimeout * 1000){ displayNotification(); } return _id++; @@ -34,26 +36,47 @@ int TrayIconNotifer::notify ( Notification notification ) void TrayIconNotifer::closeNotification ( Notification notification ) { Q_UNUSED ( notification ) - } +} bool TrayIconNotifer::isPrimaryNotificationBackend() { return true; } -//TODO:fix display of all notifications + void TrayIconNotifer::displayNotification(){ qDebug()<<"Display"<<_notificationQue.size(); - if(_notificationQue.isEmpty()){ - _noNotificationDisplayed = true; - return; + Notification notification = _notificationQue.takeFirst(); + if(!_notificationQue.isEmpty()){ + QTimer::singleShot(notification.timeout()*1000,this,SLOT(closeNotification())); } - Notification notification = _notificationQue.takeLast(); + qDebug()<<"taking"<showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 ); - //QTimer *t = new QTimer(notification); - //t->setInterval(notification.timeout() *1000); - //connect(t,SIGNAL(timeout()),this,SLOT(displayNotification())); - //t->start(); + _lastNotify.restart(); +} + +void TrayIconNotifer::closeNotification(){ + if(activeNotifications.contains(_displayed)){ + Notification noti = activeNotifications.take(_displayed); + snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT); + } + displayNotification(); +} + +void TrayIconNotifer::actionInvoked(){ + qDebug()<<"Traicon invoked"<<_displayed; + if(activeNotifications.contains(_displayed)){ + Notification noti = activeNotifications.take(_displayed); + if(noti.actions().isEmpty()){ + noti.setActionInvoked(noti.actions().keys().first()); + snore()->notificationActionInvoked(noti); + } + snore()->closeNotification(noti,NotificationEnums::CloseReasons::CLOSED); + + } + } #include "trayiconnotifer.moc" diff --git a/src/core/trayiconnotifer.h b/src/core/trayiconnotifer.h index 6804170..6148216 100644 --- a/src/core/trayiconnotifer.h +++ b/src/core/trayiconnotifer.h @@ -4,12 +4,14 @@ #include "interface.h" #include "notification/notification.h" +#include + class TrayIconNotifer:public Notification_Backend { Q_OBJECT Q_INTERFACES(Notification_Backend) public: - TrayIconNotifer ( class SnoreServer *snore=0,class QSystemTrayIcon *icon=0 ); + TrayIconNotifer ( class SnoreServer *snore=0,class QSystemTrayIcon *icon=0 ); bool isPrimaryNotificationBackend(); public slots: @@ -21,11 +23,14 @@ public slots: private: class QSystemTrayIcon *_trayIcon; QList _notificationQue; - bool _noNotificationDisplayed; - int _id; + QTime _lastNotify; + uint _id; + uint _displayed; private slots: void displayNotification(); + void actionInvoked(); + void closeNotification(); }; #endif // TRAYICONNOTIFER_H diff --git a/src/plugins/snarl/snarl_backend.cpp b/src/plugins/snarl/snarl_backend.cpp index 60d953c..a48b2d4 100644 --- a/src/plugins/snarl/snarl_backend.cpp +++ b/src/plugins/snarl/snarl_backend.cpp @@ -105,8 +105,7 @@ int Snarl_Backend::notify(Notification notification){ !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, notification.priority()); - foreach(const Notification::Action *a, notification.actions()){ - qDebug()<<"snarl add action"<id<name; + foreach(const Notification::Action *a, notification.actions()){ snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData()); } //add ack stuff @@ -164,6 +163,7 @@ bool SnarlWidget::winEvent(MSG * msg, long * result){ case SnarlEnums::NotifyAction: reason = NotificationEnums::CloseReasons::CLOSED; notification.setActionInvoked(data); + qDebug()<<"_snarl->snore()->notificationActionInvoked(notification);"; _snarl->snore()->notificationActionInvoked(notification); break; case SnarlEnums::CallbackClosed: