From a125761e6f7154ecfbca7c32fe798f6b62f9cd0a Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Fri, 10 Jan 2014 18:31:28 +0100 Subject: [PATCH] started some api changes --- CMakeLists.txt | 4 +- src/core/application.cpp | 27 ++++-------- src/core/application.h | 3 -- src/core/snore.cpp | 25 ++++++++--- src/core/snore.h | 12 ++++-- src/plugins/frontends/snarlnetwork/parser.cpp | 42 ++++++++++--------- .../frontends/snarlnetwork/snarlnetwork.h | 1 + 7 files changed, 60 insertions(+), 54 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b53a15..8980087 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ option(WITH_SNORE_DEAMON "Build the Snore deamon, which redirects notifications" ####################################################################### set(SNORE_VERSION_MAJOR 0) -set(SNORE_VERSION_MINOR 4) -set(SNORE_VERSION_SUFFIX "beta2") +set(SNORE_VERSION_MINOR 5) +set(SNORE_VERSION_SUFFIX "pre") diff --git a/src/core/application.cpp b/src/core/application.cpp index 0262649..5bfa0cb 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -23,14 +23,13 @@ using namespace Snore; Application::Application (const QString &name, const Icon &icon) : - m_name ( name ), - m_icon(icon), - m_initialized ( false ) + m_name ( name ), + m_icon(icon) { } Application::Application() : - m_name ( "Error: Uninitialized Application" ) + m_name ( "Error: Uninitialized Application" ) {} Application::~Application() @@ -58,25 +57,15 @@ const AlertList &Application::alerts() const return m_alerts; } -bool Application::isInitialized() -{ - return m_initialized; -} - -void Application::setInitialized ( bool b ) -{ - m_initialized = b; -} - Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) : - m_name ( name ), - m_title ( title ), - m_icon(icon), - m_active ( active ) + m_name ( name ), + m_title ( title ), + m_icon(icon), + m_active ( active ) {} Alert::Alert() : - m_active ( false ) + m_active ( false ) {} diff --git a/src/core/application.h b/src/core/application.h index 48dc666..a7d862d 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -41,15 +41,12 @@ public: const QString &name() const; const Icon &icon() const; const AlertList &alerts() const; - bool isInitialized(); - void setInitialized ( bool b ); private: QString m_name; Icon m_icon; AlertList m_alerts; - bool m_initialized; }; diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 7bf4988..1f91033 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -151,22 +151,35 @@ void SnoreCore::notificationActionInvoked ( Notification notification ) } } +void SnoreCore::registerApplication(Application *application) +{ + if(!m_applications.contains(application->name())) + { + m_applications.insert ( application->name(),application ); + emit applicationInitialized ( application ); + } +} + void SnoreCore::addApplication ( Application *application ) { - m_applications.insert ( application->name(),application ); + registerApplication(application); } void SnoreCore::applicationIsInitialized ( Application *application ) { - application->setInitialized ( true ); - emit applicationInitialized ( application ); + registerApplication(application); } void SnoreCore::removeApplication ( const QString& appName ) { - qDebug()<<"Remove Application"<deleteLater(); + deregisterApplication( m_applications.value ( appName ) ); +} + +void SnoreCore::deregisterApplication(Application *application) +{ + emit applicationRemoved (application ); + m_applications.take ( application->name() ); + application->deleteLater(); } const ApplicationsList &SnoreCore::aplications() const diff --git a/src/core/snore.h b/src/core/snore.h index 2928a91..6383a4c 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -48,11 +48,15 @@ public: void broadcastNotification( Notification notification ); - void notificationActionInvoked ( Notification notification ); + void notificationActionInvoked( Notification notification );//TODO: move to private header + + void registerApplication( Application *application ); + void deregisterApplication( Application *application ); + + void Q_DECL_DEPRECATED addApplication ( Application *application ); + void Q_DECL_DEPRECATED applicationIsInitialized ( Application* application ); + void Q_DECL_DEPRECATED removeApplication ( const QString& appName ); - void addApplication ( Application *application ); - void applicationIsInitialized ( Application* application ); - void removeApplication ( const QString& appName ); const ApplicationsList &aplications() const; const QStringList ¬ificationBackends() const; diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 59dfaf7..b4ff44a 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -36,8 +36,8 @@ using namespace Snore; Parser::Parser(SnarlNetworkFrontend *snarl): - QObject(snarl), - snarl(snarl) + QObject(snarl), + snarl(snarl) { getSnpType.insert("type",TYPE); getSnpType.insert("app",APP); @@ -58,12 +58,12 @@ Parser::Parser(SnarlNetworkFrontend *snarl): SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ SnarlNotification sNotification; sNotification.httpClient=false; - sNotification.vailid=true; + sNotification.vailid=true; sNotification.clientSocket=client; sNotification.isNotification = false; - snpTypes action(ERROR); + snpTypes action(ERROR); if(msg.startsWith("GET ")){ msg=msg.mid(msg.indexOf("/")+1); msg=msg.mid(0,msg.indexOf(" ")); @@ -123,36 +123,38 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ switch(action){ case NOTIFICATION:{ - qDebug()<snore()->aplications().value(sNotification.notification.application()); - if(!appl->isInitialized()){ - snarl->snore()->applicationIsInitialized(appl); - } - - if(!appl->alerts().value(sNotification.notification.alert())->isActive()) - break; - sNotification.isNotification = true; - return sNotification; - break; + qDebug() << sNotification.notification.application(); + Application * appl = snarl->snore()->aplications().value(sNotification.notification.application()); + if(!snarl->snore()->aplications().contains(appl->name())){ + snarl->snore()->registerApplication(appl); } + + if(!appl->alerts().value(sNotification.notification.alert())->isActive()) + break; + sNotification.isNotification = true; + return sNotification; + break; + } case ADD_CLASS: if(sNotification.notification.alert().isEmpty()){ qDebug()<<"Error registering alert with empty name"; break; } if(title.isEmpty()) + { title = alert; - snarl->snore()->aplications().value(sNotification.notification.application())->addAlert(new Alert(alert,title)); + } + snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title)); break; case REGISTER: - if(!snarl->snore()->aplications().contains(sNotification.notification.application())&&!sNotification.notification.application().isEmpty()){ - snarl->snore()->addApplication(new Application(sNotification.notification.application())); - } + if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){ + snarl->m_applications.insert(sNotification.notification.application(), new Application(sNotification.notification.application())); + } else qDebug()<snore()->removeApplication(sNotification.notification.application()); + snarl->snore()->deregisterApplication( snarl->snore()->aplications().value(sNotification.notification.application()) ); break; case ERROR: default: diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.h b/src/plugins/frontends/snarlnetwork/snarlnetwork.h index 2ad6bcd..3ff9170 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.h +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.h @@ -61,6 +61,7 @@ private: class QTcpServer *tcpServer; Parser *parser; QHash notifications; + QHash m_applications; void callback(const SnarlNotification &sn,QString msg);