From 2370fd47cc76334c0fc86fb2597af6ffe730320d Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Fri, 29 Jul 2011 17:00:59 +0200 Subject: [PATCH] improved code --- src/core/CMakeLists.txt | 2 -- src/core/interface.h | 8 ++++++-- src/core/snoreserver.cpp | 34 +++++++++++-------------------- src/core/snoreserver.h | 12 ++++++----- src/core/utils.cpp | 21 ------------------- src/core/utils.h | 13 ------------ src/plugins/CMakeLists.txt | 1 + src/plugins/growl/growl_backend.h | 2 +- src/snorenotify.cpp | 4 ++-- src/trayicon.cpp | 8 ++++---- 10 files changed, 33 insertions(+), 72 deletions(-) delete mode 100644 src/core/utils.cpp delete mode 100644 src/core/utils.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b11baec..66909a3 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -5,7 +5,6 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} snoreserver.cpp application.cpp interface.cpp - utils.cpp trayiconnotifer.cpp ) @@ -14,7 +13,6 @@ set ( SnoreNotify_HDR ${SnoreNotify_HDR} application.h interface.h snore_exports.h - utils.h ) automoc4_add_library( snorecore SHARED ${SnoreNotify_SRCS}) diff --git a/src/core/interface.h b/src/core/interface.h index f087161..f2259b4 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -37,9 +37,13 @@ private: }; +Q_DECLARE_INTERFACE ( SnorePlugin, + "org.Snore.SnorePlugin/1.0" ) + class SNORE_EXPORT Notification_Backend:public SnorePlugin { Q_OBJECT + Q_INTERFACES(SnorePlugin) public: Notification_Backend ( QString name,class SnoreServer *snore=0 ); virtual ~Notification_Backend(); @@ -62,6 +66,7 @@ public slots: class SNORE_EXPORT Notification_Frontend:public SnorePlugin { Q_OBJECT + Q_INTERFACES(SnorePlugin) public: Notification_Frontend ( QString name,class SnoreServer *snore=0 ); virtual ~Notification_Frontend(); @@ -74,8 +79,7 @@ protected: -Q_DECLARE_INTERFACE ( SnorePlugin, - "org.Snore.SnorePlugin/1.0" ) + Q_DECLARE_INTERFACE ( Notification_Frontend, "org.Snore.NotificationFrontend/1.0" ) Q_DECLARE_INTERFACE ( Notification_Backend, diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp index 8c72ff5..e2f3b4b 100644 --- a/src/core/snoreserver.cpp +++ b/src/core/snoreserver.cpp @@ -71,16 +71,15 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) : void SnoreServer::publicatePlugin ( const QString &fileName ) { QPluginLoader loader ( fileName ); - QObject *plugin = loader.instance(); - if ( plugin==NULL ) + if ( !loader.load()) { qDebug() <<"Failed loading plugin: "< ( plugin ); - if ( sp==NULL ) + SnorePlugin *sp = qobject_cast ( loader.instance()); + if ( sp == NULL ) { - std::cerr<<"Error:"<setSnore ( this ); - Notification_Frontend *nf=qobject_cast ( plugin ); - if ( nf ) - { - qDebug() <setSnore ( this ); - - } - Notification_Backend * nb=qobject_cast ( plugin ); if ( nb ) { - nb->setSnore ( this ); qDebug() <isPrimaryNotificationBackend() ) { - _primaryNotificationBackends.insert ( pluginName,nb ); + _primaryNotificationBackends.append( pluginName); if ( _notificationBackend == NULL ) { _notificationBackend = nb; @@ -187,21 +177,21 @@ const ApplicationsList &SnoreServer::aplications() const } -const QHash &SnoreServer::primaryNotificationBackends() const +const QStringList &SnoreServer::primaryNotificationBackends() const { return _primaryNotificationBackends; } -void SnoreServer::setPrimaryNotificationBackend ( Notification_Backend *backend ) +void SnoreServer::setPrimaryNotificationBackend ( const QString &backend ) { - if(!backend->isPrimaryNotificationBackend()) + if(!_primaryNotificationBackends.contains(backend)) return; - qDebug()<<"Setting Notification Backend to:"<name(); - _notificationBackend = backend; + qDebug()<<"Setting Notification Backend to:"<(plugins[backend]); } -Notification_Backend * SnoreServer::primaryNotificationBackend(){ - return _notificationBackend; +const QString &SnoreServer::primaryNotificationBackend(){ + return _notificationBackend->name(); } diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h index 945ec05..2d0b814 100644 --- a/src/core/snoreserver.h +++ b/src/core/snoreserver.h @@ -21,6 +21,7 @@ #include "application.h" #include "interface.h" +#include class SNORE_EXPORT SnoreServer:public QObject { @@ -46,19 +47,20 @@ public: void removeApplication ( const QString& appName ); const ApplicationsList &aplications() const; - const QHash &primaryNotificationBackends() const; - void setPrimaryNotificationBackend ( Notification_Backend *backend ); - Notification_Backend* primaryNotificationBackend(); + const QStringList &primaryNotificationBackends() const; + void setPrimaryNotificationBackend ( const QString &backend ); + const QString &primaryNotificationBackend(); + - QHash plugins; private: ApplicationsList _applications; QHash _notyfier; - QHash _primaryNotificationBackends; + QStringList _primaryNotificationBackends; Notification_Backend * _notificationBackend; + QHash plugins; class QSystemTrayIcon *_trayIcon; diff --git a/src/core/utils.cpp b/src/core/utils.cpp deleted file mode 100644 index 53bf3ba..0000000 --- a/src/core/utils.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "utils.h" - -Utils::Utils() -{ -} - - -QString Utils::notificationToSNTPString ( Notification notification ) -{ - QString out ( "type=SNP#?version=1.1" ); - if ( notification.hintExists ( "SNaction" ) ) - out+=QString ( "#?action="+notification.hint ( "SNaction" ).value() ); - if ( !notification.application().isEmpty() ) - out+=QString ( "#?app="+notification.application() ); - if ( !notification.alert().isEmpty() ) - out+=QString ( "#?class="+notification.alert() ); - if ( notification.hintExists ( "SnarlIcon" ) ) - out+=QString ( "#?icon="+notification.hint ( "SnarlIcon" ).value() ); - out+=QString ( "#?title="+notification.title() +"#?text="+notification.text() +"#?timeout="+QString::number ( notification.timeout() ) ); - return out; -} diff --git a/src/core/utils.h b/src/core/utils.h deleted file mode 100644 index e856275..0000000 --- a/src/core/utils.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include "snoreserver.h" - -class SNORE_EXPORT Utils -{ -public: - Utils(); - static QString notificationToSNTPString ( Notification notification ); -}; - -#endif // UTILS_H diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index c6c8271..9bcfaea 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -1,3 +1,4 @@ +set(CMAKE_SHARED_MODULE_PREFIX) add_subdirectory(freedesktopnotification) add_subdirectory(freedesktopfrontend) add_subdirectory(snarlnetwork) diff --git a/src/plugins/growl/growl_backend.h b/src/plugins/growl/growl_backend.h index 440dfbe..0680009 100644 --- a/src/plugins/growl/growl_backend.h +++ b/src/plugins/growl/growl_backend.h @@ -23,7 +23,7 @@ class Growl_Backend:public Notification_Backend { Q_OBJECT - Q_INTERFACES(Notification_Backend); + Q_INTERFACES(Notification_Backend) public: Growl_Backend(class SnoreServer *snore=0); ~Growl_Backend(); diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 7afe184..5829864 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -88,7 +88,7 @@ void SnoreNotify::load(){ QDomElement root = doc.documentElement(); QDomElement backend = root.elementsByTagName("notificationBackend").item(0).toElement(); if(!backend.isNull()) - _snore->setPrimaryNotificationBackend(_snore->primaryNotificationBackends().value(backend.text())); + _snore->setPrimaryNotificationBackend(backend.text()); } void SnoreNotify::save(){ @@ -96,7 +96,7 @@ void SnoreNotify::save(){ QDomElement root = doc.createElement( "SnoreNotifyProfile" ); doc.appendChild(root); QDomElement backend = doc.createElement( "notificationBackend"); - backend.appendChild(doc.createTextNode(_snore->primaryNotificationBackend()->name())); + backend.appendChild(doc.createTextNode(_snore->primaryNotificationBackend())); root.appendChild(backend); diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 7a29894..151f98d 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -33,11 +33,11 @@ void TrayIcon::initConextMenu(SnoreServer *snore){ _trayMenu = new QMenu("SnoreNotify"); _trayMenu->addAction(QString("SnoreNotify ").append(_snore->version())); _trayMenu->addSeparator(); - foreach(Notification_Backend *back,_snore->primaryNotificationBackends()){ - QAction *b= new QAction(back->name(),this); + foreach(const QString &back,_snore->primaryNotificationBackends()){ + QAction *b= new QAction(back,this); connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend())); b->setCheckable(true); - if(back->name() == _snore->primaryNotificationBackend()->name()) + if(back == _snore->primaryNotificationBackend()) b->setChecked(true); _backendActions.append(b); _trayMenu->addAction(b); @@ -59,7 +59,7 @@ QSystemTrayIcon* TrayIcon::trayIcon(){ void TrayIcon::setPrimaryBackend(){ QAction *a= dynamic_cast(sender()); - _snore->setPrimaryNotificationBackend(_snore->primaryNotificationBackends().value(a->text())); + _snore->setPrimaryNotificationBackend(a->text()); foreach(QAction *action,_backendActions){ action->setChecked(false);