From e28cd4e0d0776d36d483d793158b239132610573 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 6 Jul 2013 14:12:38 +0200 Subject: [PATCH] ids are generated by default and not asigned by the backend, somecleanup --- CMakeLists.txt | 7 ++- src/core/application.cpp | 4 -- src/core/notification/CMakeLists.txt | 1 + src/core/notification/icon.cpp | 1 + src/core/notification/notification.cpp | 18 +++----- src/core/notification/notification.h | 6 +-- src/core/plugins/plugincontainer.cpp | 1 - src/core/plugins/plugins.cpp | 1 - src/core/plugins/snorebackend.cpp | 1 - src/core/plugins/snorebackend.h | 7 +-- src/core/plugins/snorefrontend.cpp | 1 - src/core/snore.cpp | 8 +--- src/core/snore.h | 2 +- src/plugins/backends/growl/growl.cpp | 11 ++--- src/plugins/backends/growl/growl.h | 2 +- src/plugins/backends/snarl/snarl.cpp | 44 +++++++++---------- src/plugins/backends/snarl/snarl.h | 5 ++- .../backends/snoretoast/snoretoast.cpp | 13 +++--- src/plugins/backends/snoretoast/snoretoast.h | 2 +- .../backends/trayicon/trayiconnotifer.cpp | 6 +-- .../backends/trayicon/trayiconnotifer.h | 3 +- .../freedesktopnotificationfrontend.cpp | 2 - src/plugins/frontends/snarlnetwork/parser.cpp | 2 - .../frontends/snarlnetwork/snarlnetwork.cpp | 2 - src/snorenotify.cpp | 2 - src/trayicon.cpp | 3 -- 26 files changed, 61 insertions(+), 94 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ea0e41..8017994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,10 @@ project( SnoreNotify ) cmake_minimum_required( VERSION 2.8.8 ) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_PREFIX_PATH}/share/apps/cmake/modules) -set(CMAKE_AUTOMOC TRUE) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_INCLUDE_CURRENT_DIR ON) + ####################################################################### option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF) @@ -10,7 +13,7 @@ option(WITH_GROWL_BACKEND "Build the Growl backend" ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) + find_package(KDE4) diff --git a/src/core/application.cpp b/src/core/application.cpp index e5c3a39..dd5f50a 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -100,7 +100,3 @@ bool Alert::isActive() const } } -#include "application.moc" - - - diff --git a/src/core/notification/CMakeLists.txt b/src/core/notification/CMakeLists.txt index fe2ecff..4ec55e8 100644 --- a/src/core/notification/CMakeLists.txt +++ b/src/core/notification/CMakeLists.txt @@ -6,6 +6,7 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS} set ( Notification_HDR notification.h icon.h + notificationenums.h ) install(FILES ${Notification_HDR} DESTINATION include/snore/core/notification) diff --git a/src/core/notification/icon.cpp b/src/core/notification/icon.cpp index 2e9ed9e..60acdca 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -179,4 +179,5 @@ const QString &SnoreIcon::url() const } + #include "icon.moc" diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index 5286acf..7d3983d 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -24,18 +24,21 @@ #include #include #include + namespace Snore{ int Notification::notificationMetaID = qRegisterMetaType(); int Notification::notificationCount = 0; +uint Notification::m_idCount = 1; + class Notification::NotificationData : public QObject { Q_OBJECT public: NotificationData ( const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout,uint id,NotificationEnums::Prioritys::prioritys priority ): - m_id ( id ), + m_id ( id == 0 ?m_idCount++:id), m_timeout ( timeout ), m_source ( NULL), m_application ( application ), @@ -46,7 +49,7 @@ public: m_priority(priority), m_closeReason(NotificationEnums::CloseReasons::NONE) { - qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount; + qDebug()<<"Creating Notification: ActiveNotifications"<<++notificationCount<< "id" << m_id; m_ref.ref(); } @@ -89,7 +92,7 @@ Notification::Notification () : { } -Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id, NotificationEnums::Prioritys::prioritys priority ) +Notification::Notification ( const QString &application, const QString &alert, const QString &title, const QString &text, const SnoreIcon &icon, int timeout, uint id,NotificationEnums::Prioritys::prioritys priority ) { d = new NotificationData(application,alert,title,text,icon,timeout,id,priority); } @@ -136,12 +139,6 @@ const uint &Notification::id() const return d->m_id; } -void Notification::setId(const uint &id) -{ - qDebug()<<"setting notification id:"<m_id = id; -} - const SnoreIcon &Notification::icon() const { return d->m_icon; @@ -269,5 +266,4 @@ QDataStream & operator<< ( QDataStream &stream, const Notification::Action &a) } } - -#include +#include "notification.moc" diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index 20cc0f5..84d3518 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -19,7 +19,7 @@ #include "../snore_exports.h" #include "icon.h" -#include "NotificationEnums.h" +#include "notificationenums.h" #include namespace Snore{ @@ -40,7 +40,7 @@ public: public: Notification (); - Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id=0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); + Notification (const QString &application,const QString &alert,const QString &title,const QString &text,const SnoreIcon &icon,int timeout=10,uint id = 0, NotificationEnums::Prioritys::prioritys priority = NotificationEnums::Prioritys::NORMAL ); Notification ( const Notification &other ); ~Notification(); Notification &operator=(const Notification& other); @@ -78,10 +78,10 @@ public: //protected://TODO::make only accesable from a backend void setActionInvoked ( Action *action ); void setActionInvoked ( const int &actionID); - void setId(const uint &id); private: + static uint m_idCount; class NotificationData; NotificationData* d; static int notificationCount; diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index 890efd6..228627b 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -90,4 +90,3 @@ const QStringList &PluginContainer::types(){ } } -#include "plugincontainer.moc" diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index c4d4c4f..157c588 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -89,4 +89,3 @@ void SnorePlugin::notificationTimedOut(){ } } -#include "plugins.moc" diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 1a61336..c43e73b 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -99,4 +99,3 @@ void SnoreBackend::addActiveNotification(Notification n) } -#include "snorebackend.moc" diff --git a/src/core/plugins/snorebackend.h b/src/core/plugins/snorebackend.h index 466433c..b05fb96 100644 --- a/src/core/plugins/snorebackend.h +++ b/src/core/plugins/snorebackend.h @@ -19,13 +19,13 @@ #include "../snore_exports.h" #include "plugins.h" #include "../notification/notification.h" +#include "../snore.h" #include #include #include namespace Snore{ -class SnoreCore; class SNORE_EXPORT SnoreBackend : public SnorePlugin { @@ -39,7 +39,6 @@ public: bool requestCloseNotification( Snore::Notification notification,NotificationEnums::CloseReasons::closeReasons reason ); Snore::Notification getActiveNotificationByID(uint id); - void addActiveNotification(Notification n); signals: void closeNotification( Snore::Notification ); @@ -48,7 +47,7 @@ signals: public slots: virtual void slotRegisterApplication ( Snore::Application *application ) = 0; virtual void slotUnregisterApplication ( Snore::Application *application ) = 0; - virtual uint slotNotify ( Snore::Notification notification ) = 0; + virtual void slotNotify ( Snore::Notification notification ) = 0; virtual bool slotCloseNotification ( Snore::Notification notification ) =0; protected: @@ -58,6 +57,8 @@ protected: private: QHash m_activeNotifications; + void addActiveNotification(Notification n); + friend void SnoreCore::broadcastNotification(Notification notification); }; diff --git a/src/core/plugins/snorefrontend.cpp b/src/core/plugins/snorefrontend.cpp index a016651..140c175 100644 --- a/src/core/plugins/snorefrontend.cpp +++ b/src/core/plugins/snorefrontend.cpp @@ -43,4 +43,3 @@ bool SnoreFrontend::init( SnoreCore *snore ) return true; } } -#include "snorefrontend.moc" diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 8885d78..e2402e2 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -218,7 +218,7 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types ) } } -uint SnoreCore::broadcastNotification ( Notification notification ) +void SnoreCore::broadcastNotification ( Notification notification ) { qDebug()<<"Broadcasting"<quit(); } - notification.setId( m_notificationBackend->slotNotify( notification )); + m_notificationBackend->slotNotify( notification ); m_notificationBackend->addActiveNotification(notification); - return notification.id(); } - return -1; } @@ -335,5 +333,3 @@ void SnoreCore::requestCloseNotification(Notification n, NotificationEnums::Clos } } - -#include "snore.moc" diff --git a/src/core/snore.h b/src/core/snore.h index ba39164..92ca505 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -45,7 +45,7 @@ public: void loadPlugins ( PluginContainer::PluginTypes types ); - uint broadcastNotification ( Notification notification ); + void broadcastNotification( Notification notification ); void notificationActionInvoked ( Notification notification ); void addApplication ( Application *application ); diff --git a/src/plugins/backends/growl/growl.cpp b/src/plugins/backends/growl/growl.cpp index 05c1909..0649379 100644 --- a/src/plugins/backends/growl/growl.cpp +++ b/src/plugins/backends/growl/growl.cpp @@ -69,13 +69,13 @@ void Growl::slotUnregisterApplication(Application *application){ delete growl; } -uint Growl::slotNotify(Notification notification){ +void Growl::slotNotify(Notification notification){ gntp *growl = m_applications.value(notification.application()); if(growl == NULL) - return -1; + return; //qDebug()<<"Notify Growl:"<notify(notification.alert().toUtf8().constData(),m_id, + growl->notify(notification.alert().toUtf8().constData(),notification.id(), Notification::toPlainText(notification.title()).toUtf8().constData(), Notification::toPlainText(notification.text()).toUtf8().constData(), notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1"); @@ -83,7 +83,6 @@ uint Growl::slotNotify(Notification notification){ }catch(const std::exception& e){ qDebug()<<"Growl:"<closeNotification(n,r); } - - - -#include "growl.moc" diff --git a/src/plugins/backends/growl/growl.h b/src/plugins/backends/growl/growl.h index 83b55c9..0662b1b 100644 --- a/src/plugins/backends/growl/growl.h +++ b/src/plugins/backends/growl/growl.h @@ -38,7 +38,7 @@ private: public slots: void slotRegisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application); - uint slotNotify(Snore::Notification notification); + void slotNotify(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification); }; diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 59e2f64..09ca137 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -164,45 +164,43 @@ void SnarlBackend::slotUnregisterApplication(Application *application){ delete snarlInterface; } -uint SnarlBackend::slotNotify(Notification notification){ +void SnarlBackend::slotNotify(Notification notification){ SnarlInterface *snarlInterface = m_applications.value(notification.application()); if(snarlInterface == NULL){ qDebug()<Notify(notification.alert().toUtf8().constData(), - Notification::toPlainText(notification.title()).toUtf8().constData(), - Notification::toPlainText(notification.text()).toUtf8().constData(), - notification.timeout(), - notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, - !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, - notification.priority()); + if(!m_idMap.contains(notification.id())){ + ULONG32 id = snarlInterface->Notify(notification.alert().toUtf8().constData(), + Notification::toPlainText(notification.title()).toUtf8().constData(), + Notification::toPlainText(notification.text()).toUtf8().constData(), + notification.timeout(), + notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, + !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, + notification.priority()); foreach(const Notification::Action *a, notification.actions()){ snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData()); } + m_idMap[notification.id()] = id; + }else{ //update message - snarlInterface->Update(notification.id(), - notification.alert().toUtf8().constData(), - Notification::toPlainText(notification.title()).toUtf8().constData(), - Notification::toPlainText(notification.text()).toUtf8().constData(), - notification.timeout(), - notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, - !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, - notification.priority()); + snarlInterface->Update(m_idMap[notification.id()], + notification.alert().toUtf8().constData(), + Notification::toPlainText(notification.title()).toUtf8().constData(), + Notification::toPlainText(notification.text()).toUtf8().constData(), + notification.timeout(), + notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0, + !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, + notification.priority()); } - startTimeout(id,notification.timeout()); - return id; + startTimeout(notification.id(),notification.timeout()); } bool SnarlBackend::slotCloseNotification(Notification notification){ - m_defautSnarlinetrface->Hide(notification.id()); + m_defautSnarlinetrface->Hide(m_idMap.remove(notification.id())); return true; } - -#include "snarl.moc" diff --git a/src/plugins/backends/snarl/snarl.h b/src/plugins/backends/snarl/snarl.h index 761acfe..fe4b81e 100644 --- a/src/plugins/backends/snarl/snarl.h +++ b/src/plugins/backends/snarl/snarl.h @@ -39,9 +39,12 @@ private: public slots: void slotRegisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application); - uint slotNotify(Snore::Notification notification); + void slotNotify(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification); +private: + QHash m_idMap; + }; diff --git a/src/plugins/backends/snoretoast/snoretoast.cpp b/src/plugins/backends/snoretoast/snoretoast.cpp index 825dd39..eda42e3 100644 --- a/src/plugins/backends/snoretoast/snoretoast.cpp +++ b/src/plugins/backends/snoretoast/snoretoast.cpp @@ -59,7 +59,7 @@ void SnoreToast::slotUnregisterApplication(Application *application) Q_UNUSED(application) } -uint SnoreToast::slotNotify(Notification notification) +void SnoreToast::slotNotify(Notification notification) { QProcess *p = new QProcess(this); @@ -81,10 +81,8 @@ uint SnoreToast::slotNotify(Notification notification) qDebug() << "SnoreToast" << arguements; p->start("SnoreToast", arguements); - uint id = p->pid()->dwProcessId; - p->setProperty("SNORE_NOTIFICATION_ID",id); - return id; - + p->setProperty("SNORE_NOTIFICATION_ID",notification.id()); + qDebug() << notification.id(); } bool SnoreToast::slotCloseNotification(Notification notification) @@ -96,7 +94,8 @@ bool SnoreToast::slotCloseNotification(Notification notification) void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) { QProcess *p = qobject_cast(sender()); - Notification n = snore()->getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt()); + qDebug() << p->property("SNORE_NOTIFICATION_ID").toUInt(); + Notification n = getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt()); NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED; @@ -127,5 +126,3 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus) closeNotification(n,reason); } - -#include "snoretoast.moc" diff --git a/src/plugins/backends/snoretoast/snoretoast.h b/src/plugins/backends/snoretoast/snoretoast.h index 5cc3603..e21861f 100644 --- a/src/plugins/backends/snoretoast/snoretoast.h +++ b/src/plugins/backends/snoretoast/snoretoast.h @@ -17,7 +17,7 @@ public: public slots: void slotRegisterApplication(Snore::Application *application); void slotUnregisterApplication(Snore::Application *application); - uint slotNotify(Snore::Notification notification); + void slotNotify(Snore::Notification notification); bool slotCloseNotification(Snore::Notification notification); private slots: diff --git a/src/plugins/backends/trayicon/trayiconnotifer.cpp b/src/plugins/backends/trayicon/trayiconnotifer.cpp index db5db45..0f219f2 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.cpp +++ b/src/plugins/backends/trayicon/trayiconnotifer.cpp @@ -13,7 +13,6 @@ Q_EXPORT_PLUGIN2(trayicon,TrayIconNotifer) TrayIconNotifer::TrayIconNotifer () : SnoreBackend ( "SystemTray" ), m_trayIcon(NULL), - m_id ( 0 ), m_displayed(-1) { @@ -36,13 +35,12 @@ void TrayIconNotifer::slotUnregisterApplication ( Application *application ) Q_UNUSED ( application ) } -uint TrayIconNotifer::slotNotify ( Notification notification ) +void TrayIconNotifer::slotNotify( Notification notification ) { m_notificationQue.append(notification); if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){ displayNotification(); } - return m_id++; } bool TrayIconNotifer::slotCloseNotification( Notification notification ) @@ -87,5 +85,3 @@ void TrayIconNotifer::actionInvoked(){ } - -#include "trayiconnotifer.moc" diff --git a/src/plugins/backends/trayicon/trayiconnotifer.h b/src/plugins/backends/trayicon/trayiconnotifer.h index 8c31c20..2f08480 100644 --- a/src/plugins/backends/trayicon/trayiconnotifer.h +++ b/src/plugins/backends/trayicon/trayiconnotifer.h @@ -22,14 +22,13 @@ public: public slots: void slotRegisterApplication ( Snore::Application *application ); void slotUnregisterApplication ( Snore::Application *application ); - uint slotNotify ( Snore::Notification notification ); + void slotNotify ( Snore::Notification notification ); bool slotCloseNotification ( Snore::Notification notification ); private: QSystemTrayIcon *m_trayIcon; QList m_notificationQue; QTime m_lastNotify; - uint m_id; uint m_displayed; private slots: diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 824a0b6..5611921 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -129,5 +129,3 @@ QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& vers specVersion = "0"; return "Snore"; } - -#include "freedesktopnotificationfrontend.moc" diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 88d3027..3769174 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -194,5 +194,3 @@ QByteArray Parser::download(const QUrl &address){ loop.exec(); return reply->readAll(); } - -#include "parser.moc" diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 40d58eb..8b31fd9 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -116,5 +116,3 @@ void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){ } } - -#include "snarlnetwork.moc" diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 71f3d5f..d9f3139 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -67,5 +67,3 @@ void SnoreNotify::exit(){ m_trayIcon->hide(); } - -#include "snorenotify.moc" diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 2c0ac5c..621544a 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -70,6 +70,3 @@ void TrayIcon::setPrimaryBackend(){ } - - -#include "trayicon.moc"