more commit would be good

This commit is contained in:
Patrick von Reth 2010-09-26 17:09:56 +02:00
parent c06e3b9739
commit b591336d16
8 changed files with 115 additions and 85 deletions

View File

@ -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"<<title;
return _snore->broadcastNotification ( QSharedPointer<Notification> ( new Notification ( NULL,_appName,alert,title,text,icon,timeout ) ) );
return _snore->broadcastNotification ( QSharedPointer<Notification> ( new Notification ( NULL,_app->name(),alert,title,text,icon,timeout ) ) );
}
#include "snorenotificationinstance.moc"

View File

@ -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;

View File

@ -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"<<nb->name();
}
else
{
connect ( this,SIGNAL ( notify ( QSharedPointer<Notification> ) ),nb,SLOT ( notify ( QSharedPointer<Notification> ) ) );
}
}
else
{
@ -121,9 +118,7 @@ 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 );
nb->notify ( QSharedPointer<Notification> ( new Notification ( NULL,"Snore","Default Alert","Welcome","Snore Notify succesfully registred "+pluginName,"" ) ) );
nb->setSnore ( this );
}
}
@ -132,6 +127,7 @@ int SnoreServer::broadcastNotification ( QSharedPointer<Notification> notificati
emit notify ( notification );
if ( _notificationBackend!=NULL )
{
qDebug()<<"Broadcasting";
notification->_id = _notificationBackend->notify ( notification );
std::cout<<"Notification ID: "<<QString::number ( notification->_id ).toLatin1().data() <<std::endl;
return notification->_id;
@ -186,10 +182,11 @@ const QHash<QString,Notification_Backend*> &SnoreServer::primaryNotificationBack
return _primaryNotificationBackends;
}
void SnoreServer::setNotificationBackend ( Notification_Backend *backend )
void SnoreServer::setPrimaryNotificationBackend ( Notification_Backend *backend )
{
connect ( this,SIGNAL ( notify ( QSharedPointer<Notification> ) ),_notificationBackend,SLOT ( notify ( QSharedPointer<Notification> ) ) );
disconnect ( backend,SLOT ( notify ( QSharedPointer<Notification> ) ) );
if(!backend->isPrimaryNotificationBackend())
return;
qDebug()<<"Setting Notification Backend to:"<<backend->name();
_notificationBackend=backend;
}

View File

@ -45,7 +45,7 @@ public:
const ApplicationsList &aplications() const;
const QHash<QString,Notification_Backend*> &primaryNotificationBackends() const;
void setNotificationBackend ( Notification_Backend *backend );
void setPrimaryNotificationBackend ( Notification_Backend *backend );
class SnoreNotificationInstance *defaultNotificationInterface();

View File

@ -1,34 +1,59 @@
#include "trayiconnotifer.h"
#include <QSystemTrayIcon>
#include <QTimer>
#include <QDebug>
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> notification )
{
_trayIcon->showMessage ( notification->title(),notification->text(),QSystemTrayIcon::NoIcon,notification->timeout() *1000 );
_notificationQue.append(notification);
qDebug()<<"appending"<<notification->title();
if(_noNotificationDisplayed){
_noNotificationDisplayed = false;
displayNotification();
}
return _id++;
}
void TrayIconNotifer::closeNotification ( QSharedPointer<Notification> 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> notification = _notificationQue.takeLast();
qDebug()<<"taking"<<notification->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"

View File

@ -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<QSharedPointer<Notification> > _notificationQue;
bool _noNotificationDisplayed;
int _id;
private slots:
void displayNotification();
};
#endif // TRAYICONNOTIFER_H

View File

@ -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: "<<snarlInterface->GetVersionExA();
_defautSnarlinetrface = new Snarl::SnarlInterface();
this->installEventFilter(this);
Snarl::SnarlInterface *snarlInterface = new Snarl::SnarlInterface();
_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()){
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(QSharedPointer<Notification>notification){
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> 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()<<obj->objectName();
return true;
qDebug()<<obj->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"

View File

@ -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<QString,Snarl::SnarlInterface*> _applications;
Snarl::SnarlInterface* _defautSnarlinetrface;
public slots:
void registerApplication(Application *application);
void unregisterApplication(class Application *application);