added unregister of applications

This commit is contained in:
Patrick von Reth 2010-07-22 17:48:33 +02:00
parent 6652fd1add
commit b4bf83a880
11 changed files with 79 additions and 25 deletions

View File

@ -47,8 +47,9 @@ public:
public slots: public slots:
virtual void registerApplication(class Application *application)=0; virtual void registerApplication(class Application *application)=0;
virtual void unregisterApplication(class Application *application)=0;
virtual int notify(QSharedPointer<Notification> notification)=0; virtual int notify(QSharedPointer<Notification> notification)=0;
virtual void closeNotification(int id)=0; virtual void closeNotification(QSharedPointer<Notification> notification)=0;
// virtual void update // virtual void update

View File

@ -93,8 +93,9 @@ void SnoreServer::publicatePlugin(SnorePlugin *plugin){
} }
_notyfier.insert(pluginName,nb); _notyfier.insert(pluginName,nb);
connect(this,SIGNAL(notify(QSharedPointer<Notification>)),nb,SLOT(notify(QSharedPointer<Notification>))); connect(this,SIGNAL(notify(QSharedPointer<Notification>)),nb,SLOT(notify(QSharedPointer<Notification>)));
connect(this,SIGNAL(closeNotify(int)),nb,SLOT(closeNotification(int))); connect(this,SIGNAL(closeNotify(QSharedPointer<Notification>)),nb,SLOT(closeNotification(QSharedPointer<Notification>)));
connect(this,SIGNAL(applicationInitialized(Application*)),nb,SLOT(registerApplication(Application*))); connect(this,SIGNAL(applicationInitialized(Application*)),nb,SLOT(registerApplication(Application*)));
connect(this,SIGNAL(applicationRemoved(Application*)),nb,SLOT(unregisterApplication(Application*)));
nb->setSnore(this); nb->setSnore(this);
nb->notify(QSharedPointer<Notification>(new Notification(NULL,"SnoreNotify","","Welcome","Snore Notify succesfully registred "+pluginName,""))); nb->notify(QSharedPointer<Notification>(new Notification(NULL,"SnoreNotify","","Welcome","Snore Notify succesfully registred "+pluginName,"")));
@ -113,7 +114,7 @@ int SnoreServer::broadcastNotification(QSharedPointer<Notification> notification
} }
void SnoreServer::closeNotification(QSharedPointer<Notification> notification){ void SnoreServer::closeNotification(QSharedPointer<Notification> notification){
emit closeNotify(notification->_id); emit closeNotify(notification);
Notification_Frontend *nf= notification->_source; Notification_Frontend *nf= notification->_source;
if(nf!=0){ if(nf!=0){
nf->notificationClosed(notification); nf->notificationClosed(notification);

View File

@ -64,7 +64,7 @@ signals:
void applicationInitialized(Application*); void applicationInitialized(Application*);
void applicationRemoved(Application*); void applicationRemoved(Application*);
void notify(QSharedPointer<Notification> noti); void notify(QSharedPointer<Notification> noti);
void closeNotify(int id); void closeNotify(QSharedPointer<Notification>);
}; };

View File

@ -10,6 +10,9 @@ TrayIconNotifer::TrayIconNotifer(SnoreServer *snore, QSystemTrayIcon *icon):
void TrayIconNotifer::registerApplication(Application *application){ void TrayIconNotifer::registerApplication(Application *application){
}
void TrayIconNotifer::unregisterApplication(Application *application){
} }
int TrayIconNotifer::notify(QSharedPointer<Notification> notification){ int TrayIconNotifer::notify(QSharedPointer<Notification> notification){
@ -17,6 +20,6 @@ int TrayIconNotifer::notify(QSharedPointer<Notification> notification){
return _id++; return _id++;
} }
void TrayIconNotifer::closeNotification(int id){ void TrayIconNotifer::closeNotification(QSharedPointer<Notification> notification){
} }

View File

@ -13,8 +13,9 @@ public:
public slots: public slots:
void registerApplication(Application *application); void registerApplication(Application *application);
void unregisterApplication(class Application *application);
int notify(QSharedPointer<Notification> notification); int notify(QSharedPointer<Notification> notification);
void closeNotification(int id); void closeNotification(QSharedPointer<Notification> notification);
private: private:
class QSystemTrayIcon *_trayIcon; class QSystemTrayIcon *_trayIcon;

View File

@ -15,7 +15,11 @@
****************************************************************************************/ ****************************************************************************************/
#include "growl_backend.h" #include "growl_backend.h"
#include "core/snoreserver.h"
#include <growl++.hpp> #include <growl++.hpp>
#include <QtCore> #include <QtCore>
Q_EXPORT_PLUGIN2(growl_backend,Growl_Backend) Q_EXPORT_PLUGIN2(growl_backend,Growl_Backend)
@ -25,12 +29,14 @@ Notification_Backend("Growl",snore),
id(0) id(0)
{ {
const char *n[1] = { "SnoreNotification"}; const char *n[1] = { "SnoreNotification"};
growl = new Growl(GROWL_TCP,NULL,"SnoreNotify",n,1); Growl *growl = new Growl(GROWL_TCP,NULL,"SnoreNotify",n,1);
_applications.insert("SnoreNotify",growl); _applications.insert("SnoreNotify",growl);
} }
Growl_Backend::~Growl_Backend(){ Growl_Backend::~Growl_Backend(){
delete growl; foreach(Application *a,this->snore()->aplications().values()){
unregisterApplication(a);
}
} }
void Growl_Backend::registerApplication(Application *application){ void Growl_Backend::registerApplication(Application *application){
@ -39,30 +45,41 @@ void Growl_Backend::registerApplication(Application *application){
char **n = new char*[alertCount]; char **n = new char*[alertCount];
for (int i = 0 ; i < alertCount; ++i){ for (int i = 0 ; i < alertCount; ++i){
QString name = aList.at(i)->name(); QString name = aList.at(i)->name();
n[i] = new char[name.length()]; qDebug()<<name;
n[i] = name.toLatin1().data(); n[i] = new char[name.length()+1];
strcpy(n[i],name.toLatin1().data());
qDebug()<<"Add alert to growl"<<n[i];
} }
_applications.insert(application->name(),new Growl(GROWL_TCP,NULL,application->name().toLatin1().data(),(const char**)n,application->alerts().count())); _applications.insert(application->name(),new Growl(GROWL_TCP,NULL,application->name().toLatin1().data(),(const char**)n,application->alerts().count()));
for (int i = 0 ; i < alertCount; ++i){ for (int i = 0 ; i < alertCount; ++i){
qDebug()<<"Delete"<<n[i];
delete [] n[i]; delete [] n[i];
} }
delete [] n; delete [] n;
} }
void Growl_Backend::unregisterApplication(Application *application){
Growl *growl = _applications.take(application->name());
if(growl == NULL)
return;
delete growl;
}
int Growl_Backend::notify(QSharedPointer<Notification> notification){ int Growl_Backend::notify(QSharedPointer<Notification> notification){
Growl *g = _applications.value(notification->application()); Growl *growl = _applications.value(notification->application());
if(g==NULL) if(growl == NULL)
g=growl; return -1;
QString title=Notification::toPlainText(notification->title()); QString title=Notification::toPlainText(notification->title());
QString text=Notification::toPlainText(notification->text()); QString text=Notification::toPlainText(notification->text());
qDebug()<<notification->application()<<title<<text; qDebug()<<notification->application()<<title<<text;
g->Notify(notification->application().toLatin1().data(),title.toLatin1().data(),text.toLatin1().data(),NULL,notification->icon().toLatin1().data()); growl->Notify(notification->application().toLatin1().data(),title.toLatin1().data(),text.toLatin1().data(),NULL,notification->icon().toLatin1().data());
return ++id; return ++id;
} }
void Growl_Backend::closeNotification(int nr){ void Growl_Backend::closeNotification(QSharedPointer<Notification> notification){
} }

View File

@ -30,12 +30,12 @@ public:
bool isPrimaryNotificationBackend(){return true;} bool isPrimaryNotificationBackend(){return true;}
private: private:
uint id; uint id;
class Growl *growl;
QHash<QString,class Growl*> _applications; QHash<QString,class Growl*> _applications;
public slots: public slots:
void registerApplication(Application *application); void registerApplication(Application *application);
void unregisterApplication(class Application *application);
int notify(QSharedPointer<Notification>notification); int notify(QSharedPointer<Notification>notification);
void closeNotification(int nr); void closeNotification(QSharedPointer<Notification> notification);
}; };

View File

@ -15,8 +15,12 @@
****************************************************************************************/ ****************************************************************************************/
#include "snarl_backend.h" #include "snarl_backend.h"
#include "core/snoreserver.h"
#include <QtCore> #include <QtCore>
#include <QTextEdit> #include <QTextEdit>
#include <iostream> #include <iostream>
#include <wchar.h> #include <wchar.h>
@ -28,16 +32,23 @@ Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
Snarl_Backend::Snarl_Backend(SnoreServer *snore): Snarl_Backend::Snarl_Backend(SnoreServer *snore):
Notification_Backend("SnarlBackend",snore) Notification_Backend("SnarlBackend",snore)
{ {
snarlInterface=new Snarl::SnarlInterface(); Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA(); qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA();
this->installEventFilter(this); this->installEventFilter(this);
} }
Snarl_Backend::~Snarl_Backend(){ Snarl_Backend::~Snarl_Backend(){
delete snarlInterface;
foreach(Application *a,this->snore()->aplications().values()){
unregisterApplication(a);
}
} }
void Snarl_Backend::registerApplication(Application *application){ void Snarl_Backend::registerApplication(Application *application){
Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
_applications.insert(application->name(),snarlInterface);
wchar_t *appName = toWchar(application->name()); wchar_t *appName = toWchar(application->name());
snarlInterface->RegisterApp(appName,L"",L""); snarlInterface->RegisterApp(appName,L"",L"");
wprintf(L"Registering %s with Snarl.",appName); wprintf(L"Registering %s with Snarl.",appName);
@ -51,7 +62,18 @@ void Snarl_Backend::registerApplication(Application *application){
delete [] appName; delete [] appName;
} }
void Snarl_Backend::unregisterApplication(Application *application){
Snarl::SnarlInterface *snarlInterface = _applications.take(application->name());
if(snarlInterface == NULL)
return;
snarlInterface->UnregisterApp();
delete snarlInterface;
}
int Snarl_Backend::notify(QSharedPointer<Notification>notification){ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
if(snarlInterface == NULL)
return -1;
wchar_t *title = toWchar(Notification::toPlainText(notification->title())); wchar_t *title = toWchar(Notification::toPlainText(notification->title()));
wchar_t *text = toWchar(Notification::toPlainText(notification->text())); wchar_t *text = toWchar(Notification::toPlainText(notification->text()));
wchar_t *icon = toWchar(notification->icon()); wchar_t *icon = toWchar(notification->icon());
@ -77,8 +99,11 @@ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
delete[] icon; delete[] icon;
} }
void Snarl_Backend::closeNotification(int nr){ void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
snarlInterface->HideMessage(nr); Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
if(snarlInterface == NULL)
return;
snarlInterface->HideMessage(notification->id());
} }
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){ bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){

View File

@ -34,11 +34,12 @@ protected:
private: private:
//returns a wchart_t aray has to deleted after use //returns a wchart_t aray has to deleted after use
wchar_t *toWchar(const QString &string); wchar_t *toWchar(const QString &string);
Snarl::SnarlInterface *snarlInterface; QHash<QString,Snarl::SnarlInterface*> _applications;
public slots: public slots:
void registerApplication(Application *application); void registerApplication(Application *application);
void unregisterApplication(class Application *application);
int notify(QSharedPointer<Notification>notification); int notify(QSharedPointer<Notification>notification);
void closeNotification(int nr); void closeNotification(QSharedPointer<Notification> notification);
}; };

View File

@ -33,6 +33,10 @@ void WebPoster::registerApplication(Application *application){
} }
void WebPoster::unregisterApplication(Application *application){
}
int WebPoster::notify(QSharedPointer<Notification>notification){ int WebPoster::notify(QSharedPointer<Notification>notification){
QByteArray byte(Utils::notificationToSNTPString(notification).toLatin1().data()); QByteArray byte(Utils::notificationToSNTPString(notification).toLatin1().data());
QUrl url("http://www.pro-zeit.ch/index.php"); QUrl url("http://www.pro-zeit.ch/index.php");
@ -49,7 +53,7 @@ int WebPoster::notify(QSharedPointer<Notification>notification){
} }
void WebPoster::closeNotification(int id){ void WebPoster::closeNotification(QSharedPointer<Notification> notification){
//not supportted //not supportted
} }

View File

@ -30,8 +30,9 @@ public:
public slots: public slots:
void registerApplication(Application *application); void registerApplication(Application *application);
void unregisterApplication(class Application *application);
int notify(QSharedPointer<Notification>notification); int notify(QSharedPointer<Notification>notification);
void closeNotification(int id); void closeNotification(QSharedPointer<Notification> notification);
private: private:
QNetworkAccessManager *manager; QNetworkAccessManager *manager;