diff --git a/src/core/snorenotificationinstance.cpp b/src/core/snorenotificationinstance.cpp
index 8e62a02..f1e6220 100644
--- a/src/core/snorenotificationinstance.cpp
+++ b/src/core/snorenotificationinstance.cpp
@@ -23,7 +23,6 @@ SnoreNotificationInstance::SnoreNotificationInstance()
}
SnoreNotificationInstance::SnoreNotificationInstance ( const QString &appname, SnoreServer *parent,const QString &icon ) :
- _appName ( appname ),
_app ( new Application ( appname ,icon) ),
_snore ( parent )
{
@@ -51,13 +50,12 @@ void SnoreNotificationInstance::registerWithBackends()
void SnoreNotificationInstance::unregisterWithBackends()
{
- _snore->removeApplication ( _appName );
+ _snore->removeApplication ( _app->name() );
}
int SnoreNotificationInstance::notify ( const QString &alert, const QString &title, const QString &text, const QString &icon, int timeout )
{
- qDebug() <<"Broadcasting"<
broadcastNotification ( QSharedPointer ( new Notification ( NULL,_appName,alert,title,text,icon,timeout ) ) );
+ return _snore->broadcastNotification ( QSharedPointer ( new Notification ( NULL,_app->name(),alert,title,text,icon,timeout ) ) );
}
#include "snorenotificationinstance.moc"
diff --git a/src/core/snorenotificationinstance.h b/src/core/snorenotificationinstance.h
index d1f6416..02b6b96 100644
--- a/src/core/snorenotificationinstance.h
+++ b/src/core/snorenotificationinstance.h
@@ -33,7 +33,6 @@ public:
int notify ( const QString &alert,const QString &title,const QString &text,const QString &icon = 0,int timeout = 10 );
private:
SnoreNotificationInstance();
- const QString _appName;
Application *_app;
SnoreServer *_snore;
diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp
index 333d3f0..db9aff0 100644
--- a/src/core/snoreserver.cpp
+++ b/src/core/snoreserver.cpp
@@ -51,6 +51,7 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
_defaultNotificationInterface = new SnoreNotificationInstance ( "Snore",this );
+
if ( trayIcon!=NULL )
{
publicatePlugin ( new TrayIconNotifer ( this,trayIcon ) );
@@ -107,10 +108,6 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
_notificationBackend=nb;
qDebug() <<"Primary NotificationBackend is"<name();
}
- else
- {
- connect ( this,SIGNAL ( notify ( QSharedPointer ) ),nb,SLOT ( notify ( QSharedPointer ) ) );
- }
}
else
{
@@ -121,9 +118,7 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
connect ( this,SIGNAL ( closeNotify ( QSharedPointer ) ),nb,SLOT ( closeNotification ( QSharedPointer ) ) );
connect ( this,SIGNAL ( applicationInitialized ( Application* ) ),nb,SLOT ( registerApplication ( Application* ) ) );
connect ( this,SIGNAL ( applicationRemoved ( Application* ) ),nb,SLOT ( unregisterApplication ( Application* ) ) );
- nb->setSnore ( this );
- nb->notify ( QSharedPointer ( new Notification ( NULL,"Snore","Default Alert","Welcome","Snore Notify succesfully registred "+pluginName,"" ) ) );
-
+ nb->setSnore ( this );
}
}
@@ -132,6 +127,7 @@ int SnoreServer::broadcastNotification ( QSharedPointer notificati
emit notify ( notification );
if ( _notificationBackend!=NULL )
{
+ qDebug()<<"Broadcasting";
notification->_id = _notificationBackend->notify ( notification );
std::cout<<"Notification ID: "<_id ).toLatin1().data() <_id;
@@ -186,10 +182,11 @@ const QHash &SnoreServer::primaryNotificationBack
return _primaryNotificationBackends;
}
-void SnoreServer::setNotificationBackend ( Notification_Backend *backend )
+void SnoreServer::setPrimaryNotificationBackend ( Notification_Backend *backend )
{
- connect ( this,SIGNAL ( notify ( QSharedPointer ) ),_notificationBackend,SLOT ( notify ( QSharedPointer ) ) );
- disconnect ( backend,SLOT ( notify ( QSharedPointer ) ) );
+ if(!backend->isPrimaryNotificationBackend())
+ return;
+ qDebug()<<"Setting Notification Backend to:"<name();
_notificationBackend=backend;
}
diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h
index 9d0eef5..ee40994 100644
--- a/src/core/snoreserver.h
+++ b/src/core/snoreserver.h
@@ -45,7 +45,7 @@ public:
const ApplicationsList &aplications() const;
const QHash &primaryNotificationBackends() const;
- void setNotificationBackend ( Notification_Backend *backend );
+ void setPrimaryNotificationBackend ( Notification_Backend *backend );
class SnoreNotificationInstance *defaultNotificationInterface();
diff --git a/src/core/trayiconnotifer.cpp b/src/core/trayiconnotifer.cpp
index bb451d7..6df4209 100644
--- a/src/core/trayiconnotifer.cpp
+++ b/src/core/trayiconnotifer.cpp
@@ -1,34 +1,59 @@
#include "trayiconnotifer.h"
#include
+#include
+#include
TrayIconNotifer::TrayIconNotifer ( SnoreServer *snore, QSystemTrayIcon *icon ) :
Notification_Backend ( "TrayiconNotifer",snore ),
_trayIcon ( icon ),
+ _noNotificationDisplayed(true),
_id ( 0 )
{}
void TrayIconNotifer::registerApplication ( Application *application )
{
Q_UNUSED ( application )
-}
+ }
void TrayIconNotifer::unregisterApplication ( Application *application )
{
Q_UNUSED ( application )
-}
+ }
int TrayIconNotifer::notify ( QSharedPointer notification )
{
- _trayIcon->showMessage ( notification->title(),notification->text(),QSystemTrayIcon::NoIcon,notification->timeout() *1000 );
+ _notificationQue.append(notification);
+ qDebug()<<"appending"<title();
+ if(_noNotificationDisplayed){
+ _noNotificationDisplayed = false;
+ displayNotification();
+ }
return _id++;
}
void TrayIconNotifer::closeNotification ( QSharedPointer notification )
{
Q_UNUSED ( notification )
-}
+ }
bool TrayIconNotifer::isPrimaryNotificationBackend()
{
- return false;
+ return true;
}
+//TODO:fix display of all notifications
+void TrayIconNotifer::displayNotification(){
+ qDebug()<<"Display"<<_notificationQue.size();
+ if(_notificationQue.isEmpty()){
+ _noNotificationDisplayed = true;
+ return;
+ }
+ QSharedPointer notification = _notificationQue.takeLast();
+ qDebug()<<"taking"<title();
+ _trayIcon->showMessage ( notification->title(),notification->text(),QSystemTrayIcon::NoIcon,notification->timeout() *1000 );
+ QTimer *t = new QTimer(notification.data());
+ t->setInterval(notification->timeout() *1000);
+ connect(t,SIGNAL(timeout()),this,SLOT(displayNotification()));
+ t->start();
+}
+
+#include "trayiconnotifer.moc"
diff --git a/src/core/trayiconnotifer.h b/src/core/trayiconnotifer.h
index 197f519..fc08b04 100644
--- a/src/core/trayiconnotifer.h
+++ b/src/core/trayiconnotifer.h
@@ -7,8 +7,9 @@
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:
@@ -19,7 +20,12 @@ public slots:
private:
class QSystemTrayIcon *_trayIcon;
+ QList > _notificationQue;
+ bool _noNotificationDisplayed;
int _id;
+
+private slots:
+ void displayNotification();
};
#endif // TRAYICONNOTIFER_H
diff --git a/src/plugins/snarl/snarl_backend.cpp b/src/plugins/snarl/snarl_backend.cpp
index 1b13cdc..7def199 100644
--- a/src/plugins/snarl/snarl_backend.cpp
+++ b/src/plugins/snarl/snarl_backend.cpp
@@ -30,98 +30,102 @@
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
- Snarl_Backend::Snarl_Backend(SnoreServer *snore):
+Snarl_Backend::Snarl_Backend(SnoreServer *snore):
Notification_Backend("SnarlBackend",snore)
{
- Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
- _applications.insert("SnoreNotify",snarlInterface);
- qDebug()<<"Initiating Snarl Backend, Snarl version: "<GetVersionExA();
- _defautSnarlinetrface = new Snarl::SnarlInterface();
- this->installEventFilter(this);
+ Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
+ _applications.insert("SnoreNotify",snarlInterface);
+ qDebug()<<"Initiating Snarl Backend, Snarl version: "<GetVersionExA();
+ _defautSnarlinetrface = new Snarl::SnarlInterface();
+ this->installEventFilter(this);
}
Snarl_Backend::~Snarl_Backend(){
- foreach(Application *a,this->snore()->aplications().values()){
- unregisterApplication(a);
- }
- delete _defautSnarlinetrface;
+ foreach(Application *a,this->snore()->aplications().values()){
+ unregisterApplication(a);
+ }
+ delete _defautSnarlinetrface;
}
void Snarl_Backend::registerApplication(Application *application){
- Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
- _applications.insert(application->name(),snarlInterface);
+ Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
+ _applications.insert(application->name(),snarlInterface);
- wchar_t *appName = toWchar(application->name());
- wchar_t *icon = toWchar(application->icon());
- snarlInterface->RegisterApp(appName,icon,icon);
+ wchar_t *appName = toWchar(application->name());
+ wchar_t *icon = toWchar(application->icon());
+ snarlInterface->RegisterApp(appName,icon,icon);
- foreach(Alert *alert,application->alerts()){
- wchar_t *alertName = toWchar(alert->name());
- snarlInterface->RegisterAlert(appName,alertName);
- delete [] alertName;
- }
- delete [] appName;
- delete [] icon;
+ foreach(Alert *alert,application->alerts()){
+ wchar_t *alertName = toWchar(alert->name());
+ snarlInterface->RegisterAlert(appName,alertName);
+ delete [] alertName;
+ }
+ delete [] appName;
+ delete [] icon;
}
void Snarl_Backend::unregisterApplication(Application *application){
- Snarl::SnarlInterface *snarlInterface = _applications.take(application->name());
- if(snarlInterface == NULL)
- return;
- snarlInterface->UnregisterApp();
- delete snarlInterface;
+ Snarl::SnarlInterface *snarlInterface = _applications.take(application->name());
+ if(snarlInterface == NULL)
+ return;
+ snarlInterface->UnregisterApp();
+ delete snarlInterface;
}
int Snarl_Backend::notify(QSharedPointernotification){
- Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
- if(snarlInterface == NULL)
- snarlInterface = _defautSnarlinetrface;
+ Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
+ if(snarlInterface == NULL)
+ snarlInterface = _defautSnarlinetrface;
- int id = notification->id();
- wchar_t *title = toWchar(Notification::toPlainText(notification->title()));
- wchar_t *text = toWchar(Notification::toPlainText(notification->text()));
- wchar_t *icon = toWchar(notification->icon());
+ int id = notification->id();
+ wchar_t *title = toWchar(Notification::toPlainText(notification->title()));
+ wchar_t *text = toWchar(Notification::toPlainText(notification->text()));
+ wchar_t *icon = toWchar(notification->icon());
- if(notification->id()==0){
- wprintf(L"Calling SnarlMessage\n"
- L"Title: \"%s\"\n"
- L"Text: \"%s\"\n"
- L"Timeout: \"%i\"\n"
- L"Icon: \"%s\"\n",title,text,notification->timeout(),icon);
- id = snarlInterface->ShowMessage(title,text,notification->timeout(), icon);
- }else{
- //update message
- wprintf(L"Updating SnarlMessage ID: \"%i\"\n"
- L"Title: \"%s\"\n"
- L"Text: \"%s\"\n"
- L"Icon: \"%s\"\n",notification->id(),title,text,icon);
- snarlInterface->UpdateMessage(notification->id(),title, text,icon);
- }
+ if(notification->id()==0){
+ wprintf(L"Calling SnarlMessage\n"
+ L"Title: \"%s\"\n"
+ L"Text: \"%s\"\n"
+ L"Timeout: \"%i\"\n"
+ L"Icon: \"%s\"\n",title,text,notification->timeout(),icon);
+ id = snarlInterface->ShowMessage(title,text,notification->timeout(), icon);
+ }else{
+ //update message
+ wprintf(L"Updating SnarlMessage ID: \"%i\"\n"
+ L"Title: \"%s\"\n"
+ L"Text: \"%s\"\n"
+ L"Icon: \"%s\"\n",notification->id(),title,text,icon);
+ snarlInterface->UpdateMessage(notification->id(),title, text,icon);
+ }
- delete[] title;
- delete[] text;
- delete[] icon;
- return id;
+ delete[] title;
+ delete[] text;
+ delete[] icon;
+ return id;
}
void Snarl_Backend::closeNotification(QSharedPointer notification){
- Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
- if(snarlInterface == NULL)
- return;
- snarlInterface->HideMessage(notification->id());
+ Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
+ if(snarlInterface == NULL)
+ return;
+ snarlInterface->HideMessage(notification->id());
}
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
- qDebug()<objectName();
- return true;
+ qDebug()<objectName();
+ return true;
}
wchar_t *Snarl_Backend::toWchar(const QString &string){
- wchar_t *wc = new wchar_t[string.length() + 1];
- wc[string.toWCharArray(wc)] = 0;
- return wc;
+ wchar_t *wc = new wchar_t[string.length() + 1];
+ wc[string.toWCharArray(wc)] = 0;
+ return wc;
+}
+
+bool Snarl_Backend::isPrimaryNotificationBackend(){
+ return true;
}
#include "snarl_backend.moc"
diff --git a/src/plugins/snarl/snarl_backend.h b/src/plugins/snarl/snarl_backend.h
index 2bdd00c..972a071 100644
--- a/src/plugins/snarl/snarl_backend.h
+++ b/src/plugins/snarl/snarl_backend.h
@@ -26,7 +26,7 @@ class Snarl_Backend:public Notification_Backend
public:
Snarl_Backend(class SnoreServer *snore=0);
~Snarl_Backend();
- bool isPrimaryNotificationBackend(){return true;}
+ bool isPrimaryNotificationBackend();
protected:
@@ -36,6 +36,7 @@ private:
wchar_t *toWchar(const QString &string);
QHash _applications;
Snarl::SnarlInterface* _defautSnarlinetrface;
+
public slots:
void registerApplication(Application *application);
void unregisterApplication(class Application *application);