cleanup, fixed clsoe notification in snarl, closing a notification doesnt need to be connected to a special program, dont use wchar for snarl

This commit is contained in:
Patrick von Reth 2010-10-30 13:21:09 +02:00
parent 6125a63eb7
commit 098ee04d03
5 changed files with 23 additions and 37 deletions

View File

@ -99,13 +99,14 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
Notification_Backend * nb=qobject_cast<Notification_Backend *> ( plugin );
if ( nb )
{
nb->setSnore ( this );
qDebug() <<pluginName<<"is a Notification_Backend";
if ( nb->isPrimaryNotificationBackend() )
{
_primaryNotificationBackends.insert ( pluginName,nb );
if ( _notificationBackend==NULL )
if ( _notificationBackend == NULL )
{
_notificationBackend=nb;
_notificationBackend = nb;
qDebug() <<"Primary NotificationBackend is"<<nb->name();
}
}
@ -118,7 +119,6 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
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 );
}
}

View File

@ -59,6 +59,7 @@ void FreedesktopNotification_Frontend::notificationClosed(QSharedPointer<Notific
reason=4;
}
qDebug()<<"Closinf Dbus notification"<<QString::number(notification->id());
emit NotificationClosed(notification->id(),reason);
}

View File

@ -1,4 +1,4 @@
#ifndef SNARL_INTERFACE
#ifndef SNARL_INTERFACE
#define SNARL_INTERFACE
#include <tchar.h>

View File

@ -23,7 +23,6 @@
#include <iostream>
#include <wchar.h>
@ -37,10 +36,8 @@ Notification_Backend("SnarlBackend",snore)
_applications.insert("SnoreNotify",snarlInterface);
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA();
_defautSnarlinetrface = new Snarl::SnarlInterface();
this->installEventFilter(this);
}
Snarl_Backend::~Snarl_Backend(){
foreach(Application *a,this->snore()->aplications().values()){
@ -53,14 +50,12 @@ 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 *icon = toWchar(application->icon());
const char *appName = strdup(application->name().toAscii().constData());
const char *icon = strdup(application->icon().toAscii().constData());
snarlInterface->RegisterApp(appName,icon,icon);
foreach(Alert *alert,application->alerts()){
wchar_t *alertName = toWchar(alert->name());
snarlInterface->RegisterAlert(appName,alertName);
delete [] alertName;
snarlInterface->RegisterAlert(appName,alert->name().toAscii().constData());
}
delete [] appName;
delete [] icon;
@ -76,27 +71,28 @@ void Snarl_Backend::unregisterApplication(Application *application){
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
qDebug()<<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());
const char *title = strdup(Notification::toPlainText(notification->title()).toAscii().constData());
const char *text = strdup(Notification::toPlainText(notification->text()).toAscii().constData());
const char *icon = strdup(notification->icon().toAscii().constData());
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);
printf("Calling SnarlMessage\n"
"Title: \"%s\"\n"
"Text: \"%s\"\n"
"Timeout: \"%i\"\n"
"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);
printf("Updating SnarlMessage ID: \"%i\"\n"
"Title: \"%s\"\n"
"Text: \"%s\"\n"
"Icon: \"%s\"\n",notification->id(),title,text,icon);
snarlInterface->UpdateMessage(notification->id(),title, text,icon);
}
@ -107,10 +103,7 @@ int Snarl_Backend::notify(QSharedPointer<Notification>notification){
}
void Snarl_Backend::closeNotification(QSharedPointer<Notification> notification){
Snarl::SnarlInterface *snarlInterface = _applications.value(notification->application());
if(snarlInterface == NULL)
return;
snarlInterface->HideMessage(notification->id());
_defautSnarlinetrface->HideMessage(notification->id());
}
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
@ -118,12 +111,6 @@ bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
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;
}
bool Snarl_Backend::isPrimaryNotificationBackend(){
return true;
}

View File

@ -32,8 +32,6 @@ public:
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
//returns a wchart_t aray has to deleted after use
wchar_t *toWchar(const QString &string);
QHash<QString,Snarl::SnarlInterface*> _applications;
Snarl::SnarlInterface* _defautSnarlinetrface;