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
{
@ -122,8 +119,6 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
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,"" ) ) );
}
}
@ -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,6 +7,7 @@
class TrayIconNotifer:public Notification_Backend
{
Q_OBJECT
Q_INTERFACES(Notification_Backend)
public:
TrayIconNotifer ( class SnoreServer *snore=0,class QSystemTrayIcon *icon=0 );
bool isPrimaryNotificationBackend();
@ -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,7 +30,7 @@
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();
@ -124,4 +124,8 @@ wchar_t *Snarl_Backend::toWchar(const QString &string){
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);