mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-21 12:38:06 +00:00
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 )
|
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 );
|
emit closeNotify ( notification );
|
||||||
Notification_Frontend *nf= notification.source();
|
Notification_Frontend *nf= notification.source();
|
||||||
if ( nf != 0 )
|
if ( nf != NULL )
|
||||||
{
|
{
|
||||||
nf->notificationClosed ( notification );
|
nf->notificationClosed ( notification );
|
||||||
}
|
}
|
||||||
@ -157,8 +156,9 @@ void SnoreServer::closeNotification ( Notification notification,const Notificati
|
|||||||
|
|
||||||
void SnoreServer::notificationActionInvoked ( Notification notification )
|
void SnoreServer::notificationActionInvoked ( Notification notification )
|
||||||
{
|
{
|
||||||
|
emit actionInvoked(notification);
|
||||||
Notification_Frontend *nf= notification.source();
|
Notification_Frontend *nf= notification.source();
|
||||||
if ( nf!=0 )
|
if ( nf != NULL )
|
||||||
{
|
{
|
||||||
nf->actionInvoked ( notification );
|
nf->actionInvoked ( notification );
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
int broadcastNotification ( Notification notification );
|
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 notificationActionInvoked ( Notification notification );
|
||||||
|
|
||||||
void addApplication ( Application *application );
|
void addApplication ( Application *application );
|
||||||
@ -67,6 +67,7 @@ signals:
|
|||||||
void applicationInitialized ( Application* );
|
void applicationInitialized ( Application* );
|
||||||
void applicationRemoved ( Application* );
|
void applicationRemoved ( Application* );
|
||||||
void notify ( Notification noti );
|
void notify ( Notification noti );
|
||||||
|
void actionInvoked( Notification );
|
||||||
void closeNotify ( Notification );
|
void closeNotify ( Notification );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -1,31 +1,33 @@
|
|||||||
#include "trayiconnotifer.h"
|
#include "trayiconnotifer.h"
|
||||||
|
#include "snoreserver.h"
|
||||||
|
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) :
|
TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) :
|
||||||
Notification_Backend ( "TrayiconNotifer",snore ),
|
Notification_Backend ( "TrayiconNotifer",snore ),
|
||||||
_trayIcon ( icon ),
|
_trayIcon ( icon ),
|
||||||
_noNotificationDisplayed(true),
|
_id ( 0 ),
|
||||||
_id ( 0 )
|
_displayed(-1)
|
||||||
{}
|
{
|
||||||
|
connect(_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
|
||||||
|
}
|
||||||
|
|
||||||
void TrayIconNotifer::registerApplication ( Application *application )
|
void TrayIconNotifer::registerApplication ( Application *application )
|
||||||
{
|
{
|
||||||
Q_UNUSED ( application )
|
Q_UNUSED ( application )
|
||||||
}
|
}
|
||||||
void TrayIconNotifer::unregisterApplication ( Application *application )
|
void TrayIconNotifer::unregisterApplication ( Application *application )
|
||||||
{
|
{
|
||||||
Q_UNUSED ( application )
|
Q_UNUSED ( application )
|
||||||
}
|
}
|
||||||
|
|
||||||
int TrayIconNotifer::notify ( Notification notification )
|
int TrayIconNotifer::notify ( Notification notification )
|
||||||
{
|
{
|
||||||
_notificationQue.append(notification);
|
_notificationQue.append(notification);
|
||||||
qDebug()<<"appending"<<notification.title();
|
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||||
if(_noNotificationDisplayed){
|
|
||||||
_noNotificationDisplayed = false;
|
|
||||||
displayNotification();
|
displayNotification();
|
||||||
}
|
}
|
||||||
return _id++;
|
return _id++;
|
||||||
@ -34,26 +36,47 @@ int TrayIconNotifer::notify ( Notification notification )
|
|||||||
void TrayIconNotifer::closeNotification ( Notification notification )
|
void TrayIconNotifer::closeNotification ( Notification notification )
|
||||||
{
|
{
|
||||||
Q_UNUSED ( notification )
|
Q_UNUSED ( notification )
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TrayIconNotifer::isPrimaryNotificationBackend()
|
bool TrayIconNotifer::isPrimaryNotificationBackend()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//TODO:fix display of all notifications
|
|
||||||
void TrayIconNotifer::displayNotification(){
|
void TrayIconNotifer::displayNotification(){
|
||||||
qDebug()<<"Display"<<_notificationQue.size();
|
qDebug()<<"Display"<<_notificationQue.size();
|
||||||
if(_notificationQue.isEmpty()){
|
Notification notification = _notificationQue.takeFirst();
|
||||||
_noNotificationDisplayed = true;
|
if(!_notificationQue.isEmpty()){
|
||||||
return;
|
QTimer::singleShot(notification.timeout()*1000,this,SLOT(closeNotification()));
|
||||||
}
|
}
|
||||||
Notification notification = _notificationQue.takeLast();
|
|
||||||
qDebug()<<"taking"<<notification.title();
|
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 );
|
_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||||
//QTimer *t = new QTimer(notification);
|
_lastNotify.restart();
|
||||||
//t->setInterval(notification.timeout() *1000);
|
}
|
||||||
//connect(t,SIGNAL(timeout()),this,SLOT(displayNotification()));
|
|
||||||
//t->start();
|
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"
|
#include "trayiconnotifer.moc"
|
||||||
|
@ -4,12 +4,14 @@
|
|||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
#include "notification/notification.h"
|
#include "notification/notification.h"
|
||||||
|
|
||||||
|
#include <QTime>
|
||||||
|
|
||||||
class TrayIconNotifer:public Notification_Backend
|
class TrayIconNotifer:public Notification_Backend
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(Notification_Backend)
|
Q_INTERFACES(Notification_Backend)
|
||||||
public:
|
public:
|
||||||
TrayIconNotifer ( class SnoreServer *snore=0,class QSystemTrayIcon *icon=0 );
|
TrayIconNotifer ( class SnoreServer *snore=0,class QSystemTrayIcon *icon=0 );
|
||||||
bool isPrimaryNotificationBackend();
|
bool isPrimaryNotificationBackend();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
@ -21,11 +23,14 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
class QSystemTrayIcon *_trayIcon;
|
class QSystemTrayIcon *_trayIcon;
|
||||||
QList<Notification > _notificationQue;
|
QList<Notification > _notificationQue;
|
||||||
bool _noNotificationDisplayed;
|
QTime _lastNotify;
|
||||||
int _id;
|
uint _id;
|
||||||
|
uint _displayed;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void displayNotification();
|
void displayNotification();
|
||||||
|
void actionInvoked();
|
||||||
|
void closeNotification();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TRAYICONNOTIFER_H
|
#endif // TRAYICONNOTIFER_H
|
||||||
|
@ -105,8 +105,7 @@ int Snarl_Backend::notify(Notification notification){
|
|||||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
||||||
notification.priority());
|
notification.priority());
|
||||||
|
|
||||||
foreach(const Notification::Action *a, notification.actions()){
|
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());
|
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
|
||||||
}
|
}
|
||||||
//add ack stuff
|
//add ack stuff
|
||||||
@ -164,6 +163,7 @@ bool SnarlWidget::winEvent(MSG * msg, long * result){
|
|||||||
case SnarlEnums::NotifyAction:
|
case SnarlEnums::NotifyAction:
|
||||||
reason = NotificationEnums::CloseReasons::CLOSED;
|
reason = NotificationEnums::CloseReasons::CLOSED;
|
||||||
notification.setActionInvoked(data);
|
notification.setActionInvoked(data);
|
||||||
|
qDebug()<<"_snarl->snore()->notificationActionInvoked(notification);";
|
||||||
_snarl->snore()->notificationActionInvoked(notification);
|
_snarl->snore()->notificationActionInvoked(notification);
|
||||||
break;
|
break;
|
||||||
case SnarlEnums::CallbackClosed:
|
case SnarlEnums::CallbackClosed:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user