added unregister of applications
This commit is contained in:
parent
6652fd1add
commit
b4bf83a880
|
@ -47,8 +47,9 @@ public:
|
|||
|
||||
public slots:
|
||||
virtual void registerApplication(class Application *application)=0;
|
||||
virtual void unregisterApplication(class Application *application)=0;
|
||||
virtual int notify(QSharedPointer<Notification> notification)=0;
|
||||
virtual void closeNotification(int id)=0;
|
||||
virtual void closeNotification(QSharedPointer<Notification> notification)=0;
|
||||
|
||||
// virtual void update
|
||||
|
||||
|
|
|
@ -93,8 +93,9 @@ void SnoreServer::publicatePlugin(SnorePlugin *plugin){
|
|||
}
|
||||
_notyfier.insert(pluginName,nb);
|
||||
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(applicationRemoved(Application*)),nb,SLOT(unregisterApplication(Application*)));
|
||||
nb->setSnore(this);
|
||||
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){
|
||||
emit closeNotify(notification->_id);
|
||||
emit closeNotify(notification);
|
||||
Notification_Frontend *nf= notification->_source;
|
||||
if(nf!=0){
|
||||
nf->notificationClosed(notification);
|
||||
|
|
|
@ -64,7 +64,7 @@ signals:
|
|||
void applicationInitialized(Application*);
|
||||
void applicationRemoved(Application*);
|
||||
void notify(QSharedPointer<Notification> noti);
|
||||
void closeNotify(int id);
|
||||
void closeNotify(QSharedPointer<Notification>);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@ TrayIconNotifer::TrayIconNotifer(SnoreServer *snore, QSystemTrayIcon *icon):
|
|||
|
||||
void TrayIconNotifer::registerApplication(Application *application){
|
||||
|
||||
}
|
||||
void TrayIconNotifer::unregisterApplication(Application *application){
|
||||
|
||||
}
|
||||
|
||||
int TrayIconNotifer::notify(QSharedPointer<Notification> notification){
|
||||
|
@ -17,6 +20,6 @@ int TrayIconNotifer::notify(QSharedPointer<Notification> notification){
|
|||
return _id++;
|
||||
}
|
||||
|
||||
void TrayIconNotifer::closeNotification(int id){
|
||||
void TrayIconNotifer::closeNotification(QSharedPointer<Notification> notification){
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
int notify(QSharedPointer<Notification> notification);
|
||||
void closeNotification(int id);
|
||||
void closeNotification(QSharedPointer<Notification> notification);
|
||||
|
||||
private:
|
||||
class QSystemTrayIcon *_trayIcon;
|
||||
|
|
|
@ -15,7 +15,11 @@
|
|||
****************************************************************************************/
|
||||
|
||||
#include "growl_backend.h"
|
||||
|
||||
#include "core/snoreserver.h"
|
||||
|
||||
#include <growl++.hpp>
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
Q_EXPORT_PLUGIN2(growl_backend,Growl_Backend)
|
||||
|
@ -25,12 +29,14 @@ Notification_Backend("Growl",snore),
|
|||
id(0)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
Growl_Backend::~Growl_Backend(){
|
||||
delete growl;
|
||||
foreach(Application *a,this->snore()->aplications().values()){
|
||||
unregisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
||||
void Growl_Backend::registerApplication(Application *application){
|
||||
|
@ -39,30 +45,41 @@ void Growl_Backend::registerApplication(Application *application){
|
|||
char **n = new char*[alertCount];
|
||||
for (int i = 0 ; i < alertCount; ++i){
|
||||
QString name = aList.at(i)->name();
|
||||
n[i] = new char[name.length()];
|
||||
n[i] = name.toLatin1().data();
|
||||
qDebug()<<name;
|
||||
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()));
|
||||
|
||||
for (int i = 0 ; i < alertCount; ++i){
|
||||
qDebug()<<"Delete"<<n[i];
|
||||
delete [] n[i];
|
||||
}
|
||||
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){
|
||||
Growl *g = _applications.value(notification->application());
|
||||
if(g==NULL)
|
||||
g=growl;
|
||||
Growl *growl = _applications.value(notification->application());
|
||||
if(growl == NULL)
|
||||
return -1;
|
||||
|
||||
QString title=Notification::toPlainText(notification->title());
|
||||
QString text=Notification::toPlainText(notification->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;
|
||||
}
|
||||
|
||||
void Growl_Backend::closeNotification(int nr){
|
||||
void Growl_Backend::closeNotification(QSharedPointer<Notification> notification){
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ public:
|
|||
bool isPrimaryNotificationBackend(){return true;}
|
||||
private:
|
||||
uint id;
|
||||
class Growl *growl;
|
||||
QHash<QString,class Growl*> _applications;
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
int notify(QSharedPointer<Notification>notification);
|
||||
void closeNotification(int nr);
|
||||
void closeNotification(QSharedPointer<Notification> notification);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -15,8 +15,12 @@
|
|||
****************************************************************************************/
|
||||
|
||||
#include "snarl_backend.h"
|
||||
|
||||
#include "core/snoreserver.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QTextEdit>
|
||||
|
||||
#include <iostream>
|
||||
#include <wchar.h>
|
||||
|
||||
|
@ -28,16 +32,23 @@ Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
|
|||
Snarl_Backend::Snarl_Backend(SnoreServer *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();
|
||||
this->installEventFilter(this);
|
||||
|
||||
}
|
||||
Snarl_Backend::~Snarl_Backend(){
|
||||
delete snarlInterface;
|
||||
|
||||
foreach(Application *a,this->snore()->aplications().values()){
|
||||
unregisterApplication(a);
|
||||
}
|
||||
}
|
||||
|
||||
void Snarl_Backend::registerApplication(Application *application){
|
||||
Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
|
||||
_applications.insert(application->name(),snarlInterface);
|
||||
|
||||
wchar_t *appName = toWchar(application->name());
|
||||
snarlInterface->RegisterApp(appName,L"",L"");
|
||||
wprintf(L"Registering %s with Snarl.",appName);
|
||||
|
@ -51,7 +62,18 @@ void Snarl_Backend::registerApplication(Application *application){
|
|||
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){
|
||||
Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
|
||||
if(snarlInterface == NULL)
|
||||
return -1;
|
||||
wchar_t *title = toWchar(Notification::toPlainText(notification->title()));
|
||||
wchar_t *text = toWchar(Notification::toPlainText(notification->text()));
|
||||
wchar_t *icon = toWchar(notification->icon());
|
||||
|
@ -77,8 +99,11 @@ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
|
|||
delete[] icon;
|
||||
}
|
||||
|
||||
void Snarl_Backend::closeNotification(int nr){
|
||||
snarlInterface->HideMessage(nr);
|
||||
void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
|
||||
Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
|
||||
if(snarlInterface == NULL)
|
||||
return;
|
||||
snarlInterface->HideMessage(notification->id());
|
||||
}
|
||||
|
||||
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
|
||||
|
|
|
@ -34,11 +34,12 @@ protected:
|
|||
private:
|
||||
//returns a wchart_t aray has to deleted after use
|
||||
wchar_t *toWchar(const QString &string);
|
||||
Snarl::SnarlInterface *snarlInterface;
|
||||
QHash<QString,Snarl::SnarlInterface*> _applications;
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
int notify(QSharedPointer<Notification>notification);
|
||||
void closeNotification(int nr);
|
||||
void closeNotification(QSharedPointer<Notification> notification);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ void WebPoster::registerApplication(Application *application){
|
|||
|
||||
}
|
||||
|
||||
void WebPoster::unregisterApplication(Application *application){
|
||||
|
||||
}
|
||||
|
||||
int WebPoster::notify(QSharedPointer<Notification>notification){
|
||||
QByteArray byte(Utils::notificationToSNTPString(notification).toLatin1().data());
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
int notify(QSharedPointer<Notification>notification);
|
||||
void closeNotification(int id);
|
||||
void closeNotification(QSharedPointer<Notification> notification);
|
||||
|
||||
private:
|
||||
QNetworkAccessManager *manager;
|
||||
|
|
Loading…
Reference in New Issue