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);
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
|
||||
};
|
||||
|
|
|
@ -1,31 +1,33 @@
|
|||
#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 )
|
||||
{}
|
||||
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.title();
|
||||
if(_noNotificationDisplayed){
|
||||
_noNotificationDisplayed = false;
|
||||
if(_lastNotify.elapsed()> 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"<<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,12 +4,14 @@
|
|||
#include "interface.h"
|
||||
#include "notification/notification.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
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<Notification > _notificationQue;
|
||||
bool _noNotificationDisplayed;
|
||||
int _id;
|
||||
QTime _lastNotify;
|
||||
uint _id;
|
||||
uint _displayed;
|
||||
|
||||
private slots:
|
||||
void displayNotification();
|
||||
void actionInvoked();
|
||||
void closeNotification();
|
||||
};
|
||||
|
||||
#endif // TRAYICONNOTIFER_H
|
||||
|
|
|
@ -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"<<a->id<<a->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:
|
||||
|
|
Loading…
Reference in New Issue