diff --git a/src/core/interface.cpp b/src/core/interface.cpp index 1a0e73f..28e2052 100644 --- a/src/core/interface.cpp +++ b/src/core/interface.cpp @@ -23,52 +23,58 @@ namespace Snore{ SnorePlugin::SnorePlugin ( QString name ) : - _name ( name ) + m_name ( name ), + m_initialized(false) {} SnorePlugin::~SnorePlugin() { - qDebug()<<_name<deleteLater(); + qDebug()<_snore = snore; - qDebug()<<"Initialize"<<_name<m_snore = snore; + m_initialized = true; + return true; +} + +bool SnorePlugin::isInitialized(){ + return m_initialized; } SnoreServer* SnorePlugin::snore() { - return _snore.data(); + return m_snore.data(); } const QString &SnorePlugin::name() const { - return _name; + return m_name; } void SnorePlugin::startTimeout(uint id,int timeout){ if(timeout==-1)//sticky return; - if(timeouts.contains(id)){ - QTimer *t = timeouts.take(id); + if(m_timeouts.contains(id)){ + QTimer *t = m_timeouts.take(id); t->stop(); t->deleteLater(); - timeout_order.removeOne(id); + m_timeout_order.removeOne(id); } QTimer *timer= new QTimer(this); timer->setInterval(timeout*1000); timer->setSingleShot(true); - timeouts.insert(id,timer); - timeout_order.append(id); + m_timeouts.insert(id,timer); + m_timeout_order.append(id); connect(timer,SIGNAL(timeout()),this,SLOT(notificationTimedOut())); timer->start(); } void SnorePlugin::notificationTimedOut(){ - uint id = timeout_order.takeFirst(); - timeouts.take(id)->deleteLater(); + uint id = m_timeout_order.takeFirst(); + m_timeouts.take(id)->deleteLater(); if(activeNotifications.contains(id)){ Notification n = activeNotifications.take(id); snore()->closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT); @@ -85,14 +91,17 @@ Notification_Backend::~Notification_Backend() { } -void Notification_Backend::init( SnoreServer *snore ) +bool Notification_Backend::init( SnoreServer *snore ) { - SnorePlugin::init(snore); + if(!SnorePlugin::init(snore)) + return false; connect( snore,SIGNAL( closeNotify( Snore::Notification ) ),this,SLOT( closeNotification( Snore::Notification) ) ); connect( snore,SIGNAL( applicationInitialized( Snore::Application* ) ),this,SLOT( registerApplication( Snore::Application* ) ) ); connect( snore,SIGNAL( applicationRemoved( Snore::Application* ) ),this,SLOT( unregisterApplication( Snore::Application* ) ) ); if(!isPrimaryNotificationBackend()) connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) ); + return true; + } Notification_Frontend::Notification_Frontend ( QString name ) : @@ -104,10 +113,12 @@ Notification_Frontend::Notification_Frontend ( QString name ) : Notification_Frontend::~Notification_Frontend() { } -void Notification_Frontend::init( SnoreServer *snore ) +bool Notification_Frontend::init( SnoreServer *snore ) { - SnorePlugin::init(snore); + if(!SnorePlugin::init(snore)) + return false; connect( snore,SIGNAL ( closeNotify( Snore::Notification ) ),this,SLOT ( notificationClosed( Snore::Notification) ) ); + return true; } } #include "interface.moc" diff --git a/src/core/interface.h b/src/core/interface.h index 7241072..9bdd306 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -31,7 +31,8 @@ class SNORE_EXPORT SnorePlugin:public QObject public: SnorePlugin ( QString name); virtual ~SnorePlugin(); - virtual void init( SnoreServer* snore ); + virtual bool init( SnoreServer* snore ); + bool isInitialized(); SnoreServer* snore(); const QString &name() const; @@ -43,10 +44,11 @@ private slots: private: SnorePlugin() {} - QString _name; - QPointer _snore; - QHash timeouts; - QList timeout_order; + QString m_name; + bool m_initialized; + QPointer m_snore; + QHash m_timeouts; + QList m_timeout_order; }; @@ -64,7 +66,7 @@ class SNORE_EXPORT Notification_Backend:public SnorePlugin public: Notification_Backend ( QString name ); virtual ~Notification_Backend(); - virtual void init(SnoreServer *snore); + virtual bool init(SnoreServer *snore); virtual bool isPrimaryNotificationBackend() =0; @@ -87,7 +89,7 @@ class SNORE_EXPORT Notification_Frontend:public SnorePlugin public: Notification_Frontend ( QString name); virtual ~Notification_Frontend(); - virtual void init(SnoreServer *snore); + virtual bool init(SnoreServer *snore); public slots: virtual void actionInvoked( Snore::Notification notification )=0; diff --git a/src/core/notification/icon.cpp b/src/core/notification/icon.cpp index 09ab051..3900833 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -38,6 +38,7 @@ public: {} SnoreIconData(const QString &url){ + qDebug()<<"Creating SnoreIcon"< #include #include +#include namespace Snore{ @@ -95,7 +96,10 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin ) m_notificationBackend = nb; } }else{ - nb->init( this ); + if(!nb->init( this )){ + nb->deleteLater(); + return; + } } m_notyfier.insert ( pluginName,nb ); @@ -103,9 +107,10 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin ) Notification_Frontend * nf = qobject_cast ( plugin ); if(nf != NULL){ qDebug() <init( this ); - if(nf != NULL) + if(nf->init( this )) m_frontends.insert(nf->name(),nf); + else + nf->deleteLater(); } } } @@ -116,6 +121,10 @@ uint SnoreServer::broadcastNotification ( Notification notification ) emit notify ( notification ); if ( m_notificationBackend != NULL ) { + if(!m_notificationBackend->isInitialized()){ + qDebug()<<"Notification backend "<quit(); + } notification.setId(m_notificationBackend->notify( notification )); return notification.id(); } diff --git a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp index 262236e..34b37b0 100644 --- a/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp +++ b/src/plugins/freedesktopfrontend/freedesktopnotificationfrontend.cpp @@ -40,17 +40,16 @@ FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(): FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){ QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.unregisterService( "org.freedesktop.Notifications" ); - qDebug()<<"FreedesktopNotification_Frontend"<<"bye"; } -void FreedesktopNotification_Frontend::init(SnoreServer *snore){ - Notification_Frontend::init(snore); - qDebug()<<"arg"<GetVersion(); _defautSnarlinetrface = new SnarlInterface(); + return true; } void Snarl_Backend::registerApplication(Application *application){ diff --git a/src/plugins/snarl/snarl_backend.h b/src/plugins/snarl/snarl_backend.h index bd4193e..a0c8ae1 100644 --- a/src/plugins/snarl/snarl_backend.h +++ b/src/plugins/snarl/snarl_backend.h @@ -35,7 +35,7 @@ class Snarl_Backend:public Snore::Notification_Backend public: Snarl_Backend(); ~Snarl_Backend(); - virtual void init(Snore::SnoreServer *snore); + virtual bool init(Snore::SnoreServer *snore); bool isPrimaryNotificationBackend(); private: diff --git a/src/plugins/snarlnetwork/snarlnetwork.cpp b/src/plugins/snarlnetwork/snarlnetwork.cpp index 9d361d7..6c5e430 100644 --- a/src/plugins/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/snarlnetwork/snarlnetwork.cpp @@ -34,20 +34,21 @@ SnarlNetworkFrontend::SnarlNetworkFrontend(): } SnarlNetworkFrontend::~SnarlNetworkFrontend(){ - delete parser; - delete tcpServer; } -void SnarlNetworkFrontend::init(SnoreServer *snore){ - Notification_Frontend::init(snore); +bool SnarlNetworkFrontend::init(SnoreServer *snore){ + if(!Notification_Frontend::init(snore)) + return false; parser=new Parser(this); tcpServer=new QTcpServer(this); if(!tcpServer->listen(QHostAddress::Any,port)){ qDebug()<<"The port is already used"; + return false; }else{ connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection())); std::cout<<"The Snarl Network Protokoll is developed for Snarl "<