this and that
This commit is contained in:
parent
6cdd6504a5
commit
8961a58a94
|
@ -145,11 +145,10 @@ int SnoreServer::broadcastNotification ( Notification notification )
|
|||
|
||||
void SnoreServer::closeNotification ( Notification notification,const NotificationEnums::CloseReasons::closeReasons &reason )
|
||||
{
|
||||
qDebug()<<"closing notification"<<notification.id()<<"reason"<<reason;
|
||||
notification.setCloseReason(reason);
|
||||
emit closeNotify ( notification );
|
||||
Notification_Frontend *nf= notification.source();
|
||||
if ( nf != 0 )
|
||||
if ( nf != NULL )
|
||||
{
|
||||
nf->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 );
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ signals:
|
|||
void applicationInitialized ( Application* );
|
||||
void applicationRemoved ( Application* );
|
||||
void notify ( Notification noti );
|
||||
void actionInvoked( Notification );
|
||||
void closeNotify ( Notification );
|
||||
|
||||
};
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
#include "trayiconnotifer.h"
|
||||
#include "snoreserver.h"
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
|
||||
TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) :
|
||||
Notification_Backend ( "TrayiconNotifer",snore ),
|
||||
_trayIcon ( icon ),
|
||||
_noNotificationDisplayed(true),
|
||||
_id ( 0 )
|
||||
{}
|
||||
_id ( 0 ),
|
||||
_displayed(-1)
|
||||
{
|
||||
connect(_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
|
||||
}
|
||||
|
||||
void TrayIconNotifer::registerApplication ( Application *application )
|
||||
{
|
||||
|
@ -23,9 +27,7 @@ void TrayIconNotifer::unregisterApplication ( Application *application )
|
|||
int TrayIconNotifer::notify ( Notification notification )
|
||||
{
|
||||
_notificationQue.append(notification);
|
||||
qDebug()<<"appending"<<notification.title();
|
||||
if(_noNotificationDisplayed){
|
||||
_noNotificationDisplayed = false;
|
||||
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
displayNotification();
|
||||
}
|
||||
return _id++;
|
||||
|
@ -40,20 +42,41 @@ 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"<<notification.title();
|
||||
_displayed = notification.id();
|
||||
activeNotifications.insert(notification.id(),notification);
|
||||
_trayIcon->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"
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "interface.h"
|
||||
#include "notification/notification.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
class TrayIconNotifer:public Notification_Backend
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -21,11 +23,14 @@ public slots:
|
|||
private:
|
||||
class QSystemTrayIcon *_trayIcon;
|
||||
QList<Notification > _notificationQue;
|
||||
bool _noNotificationDisplayed;
|
||||
int _id;
|
||||
QTime _lastNotify;
|
||||
uint _id;
|
||||
uint _displayed;
|
||||
|
||||
private slots:
|
||||
void displayNotification();
|
||||
void actionInvoked();
|
||||
void closeNotification();
|
||||
};
|
||||
|
||||
#endif // TRAYICONNOTIFER_H
|
||||
|
|
|
@ -106,7 +106,6 @@ int Snarl_Backend::notify(Notification notification){
|
|||
notification.priority());
|
||||
|
||||
foreach(const Notification::Action *a, notification.actions()){
|
||||
qDebug()<<"snarl add action"<<a->id<<a->name;
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue