From a16e680bd5a0c62372727e280097507359b30ec4 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sun, 12 Jan 2014 18:00:45 +0100 Subject: [PATCH] reduce amount of pointers ... --- src/core/application.cpp | 52 +++++++++++---- src/core/application.h | 59 +++++++++-------- src/core/notification/notification.cpp | 27 ++++++-- src/core/notification/notification.h | 9 ++- src/core/notification/notification_p.cpp | 5 +- src/core/notification/notification_p.h | 8 +-- src/core/plugins/plugincontainer.h | 2 +- src/core/plugins/snorebackend.cpp | 13 ++-- src/core/plugins/snorebackend.h | 4 +- src/core/snore.cpp | 13 ++-- src/core/snore.h | 6 +- src/core/snore_p.h | 6 +- src/plugins/backends/growl/growl.cpp | 14 ++-- src/plugins/backends/growl/growl.h | 4 +- src/plugins/backends/snarl/snarl.cpp | 54 +++++++++------- src/plugins/backends/snarl/snarl.h | 4 +- .../freedesktopnotificationfrontend.cpp | 13 ++-- src/plugins/frontends/snarlnetwork/parser.cpp | 17 +++-- .../frontends/snarlnetwork/snarlnetwork.cpp | 8 ++- src/snorenotify.cpp | 3 +- src/trayicon.cpp | 64 +++++++++++-------- src/trayicon.h | 8 +-- 22 files changed, 232 insertions(+), 161 deletions(-) diff --git a/src/core/application.cpp b/src/core/application.cpp index 53a222d..ef57705 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -23,26 +23,32 @@ using namespace Snore; Application::Application (const QString &name, const Icon &icon) : - m_name ( name ), + m_name(name), m_icon(icon) { } -Application::Application() : - m_name ( "Error: Uninitialized Application" ) +Application::Application(const Application &other): + m_name(other.m_name), + m_icon(other.m_icon), + m_alerts(other.m_alerts) +{ + +} + +Application::Application() {} Application::~Application() { } -void Application::addAlert ( Alert *alert ) +void Application::addAlert(const Alert &alert) { - alert->setParent(this); - m_alerts.insert ( alert->name(),alert ); + m_alerts.insert(alert.name(), alert); } -const QString &Application::name() const +QString Application::name() const { return m_name; } @@ -52,29 +58,43 @@ const Icon &Application::icon()const return m_icon; } -const AlertList &Application::alerts() const +const QHash &Application::alerts() const { return m_alerts; } -Alert::Alert (const QString &name, const QString &title, const Icon &icon, bool active) : - m_name ( name ), - m_title ( title ), +bool Application::isValid() const +{ + return m_name.isNull(); +} + +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_active(active) {} +Alert::Alert(const Alert &other): + m_name(other.m_name), + m_title(other.m_title), + m_icon(other.m_icon), + m_active(other.m_active) +{ + +} + Alert::Alert() : m_active ( false ) {} -const QString &Alert::name() const +QString Alert::name() const { return m_name; } -const QString &Alert::title() const +QString Alert::title() const { return m_title; } @@ -89,3 +109,7 @@ bool Alert::isActive() const return m_active; } +bool Alert::isValid() const +{ + return m_name.isNull(); +} diff --git a/src/core/application.h b/src/core/application.h index 77db69c..e7cf6c7 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -24,43 +24,19 @@ #include namespace Snore{ -class Application; -class Alert; -typedef QHash ApplicationsList ; -typedef QHash AlertList; - -class SNORE_EXPORT Application : public QObject +class SNORE_EXPORT Alert { - Q_OBJECT public: - Application ( const QString &name, const Icon &icon = Icon(":/root/snore.png")); - Application(); - ~Application(); - void addAlert ( Alert *alert ); - const QString &name() const; - const Icon &icon() const; - const AlertList &alerts() const; - - -private: - QString m_name; - Icon m_icon; - AlertList m_alerts; - -}; - -class SNORE_EXPORT Alert:public QObject -{ - Q_OBJECT -public: - Alert ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true ); Alert(); + Alert ( const QString &name,const QString &title="",const Icon &icon = Icon(":/root/snore.png"),bool active=true ); + Alert(const Alert &other); - const QString &name() const; - const QString &title() const; + QString name() const; + QString title() const; const Icon &icon() const; bool isActive() const; + bool isValid() const; private: QString m_name; QString m_title; @@ -68,6 +44,29 @@ private: bool m_active; }; +class SNORE_EXPORT Application +{ +public: + Application(); + Application ( const QString &name, const Icon &icon = Icon(":/root/snore.png")); + Application(const Application &other); + ~Application(); + + void addAlert(const Alert &alert); + QString name() const; + const Icon &icon() const; + const QHash &alerts() const; + bool isValid() const; + + +private: + QString m_name; + Icon m_icon; + QHash m_alerts; + +}; + + } diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index ee84815..526a294 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -31,17 +31,36 @@ int Notification::m_defaultTimeout = 10; int NotificationData::notificationMetaID = qRegisterMetaType(); +Notification::Action::Action(): + m_id(-1) +{ + +} + Notification::Action::Action(int id, QString name): m_id(id), m_name(name) { } + +Notification::Action::Action(const Notification::Action &other): + m_id(other.id()), + m_name(other.name()) +{ + +} + QString Notification::Action::name() const { return m_name; } +bool Notification::Action::isValid() const +{ + return m_name.isNull(); +} + int Notification::Action::id() const { return m_id; @@ -97,7 +116,7 @@ const uint &Notification::updateID() const return d->m_updateID; } -const Notification::Action *Notification::actionInvoked() const +const Notification::Action &Notification::actionInvoked() const { return d->m_actionInvoked; } @@ -146,13 +165,13 @@ const NotificationEnums::Prioritys::prioritys &Notification::priority() const return d->m_priority; } -void Notification::addAction(Notification::Action *a) +void Notification::addAction(const Notification::Action &a) { - d->m_actions.insert(a->id(),a); + d->m_actions.insert(a.id(),a); } -const QHash &Notification::actions() const +const QHash &Notification::actions() const { return d->m_actions; } diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index 52000c6..fd6501d 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -41,10 +41,13 @@ public: class SNORE_EXPORT Action { public: + Action(); Action(int id,QString name); + Action(const Action &other); int id() const; QString name() const; + bool isValid() const; private: int m_id; @@ -67,7 +70,7 @@ public: void setUpdateID(uint id); const uint &updateID() const; - const Action* actionInvoked() const; + const Action &actionInvoked() const; void setSource(class SnoreFrontend *source); class SnoreFrontend *source() const; const QString &application() const; @@ -78,8 +81,8 @@ public: void setSticky(); bool sticky() const; const NotificationEnums::Prioritys::prioritys &priority() const; - const QHash &actions() const; - void addAction(Action *a); + const QHash &actions() const; + void addAction(const Action &a); const NotificationEnums::CloseReasons::closeReasons &closeReason(); void setCloseReason(const NotificationEnums::CloseReasons::closeReasons &r); Hint &hints(); diff --git a/src/core/notification/notification_p.cpp b/src/core/notification/notification_p.cpp index 22ba140..58696cb 100644 --- a/src/core/notification/notification_p.cpp +++ b/src/core/notification/notification_p.cpp @@ -43,8 +43,7 @@ NotificationData::NotificationData ( const QString &application,const QString &a m_text ( text ), m_icon ( icon ), m_priority(priority), - m_closeReason(NotificationEnums::CloseReasons::NONE), - m_actionInvoked( NULL ) + m_closeReason(NotificationEnums::CloseReasons::NONE) { notificationCount++; qDebug()<< "Creating Notification: ActiveNotifications" << notificationCount << "id" << m_id; @@ -57,7 +56,7 @@ NotificationData::~NotificationData() } -void NotificationData::setActionInvoked ( Notification::Action *action ) +void NotificationData::setActionInvoked (const Snore::Notification::Action &action ) { m_actionInvoked = action; } diff --git a/src/core/notification/notification_p.h b/src/core/notification/notification_p.h index 21af26d..0a82f69 100644 --- a/src/core/notification/notification_p.h +++ b/src/core/notification/notification_p.h @@ -38,8 +38,8 @@ public: int timeout,NotificationEnums::Prioritys::prioritys priority ); ~NotificationData(); - void setActionInvoked ( Notification::Action *action ); - void setActionInvoked ( const int &actionID); + void setActionInvoked( const Notification::Action &action ); + void setActionInvoked( const int &actionID); private: Q_DISABLE_COPY(NotificationData) @@ -55,8 +55,8 @@ private: Icon m_icon; NotificationEnums::Prioritys::prioritys m_priority; NotificationEnums::CloseReasons::closeReasons m_closeReason; - Notification::Action *m_actionInvoked; - QHash m_actions; + Notification::Action m_actionInvoked; + QHash m_actions; Hint m_hints; static uint notificationCount; diff --git a/src/core/plugins/plugincontainer.h b/src/core/plugins/plugincontainer.h index 425f378..b4b34a1 100644 --- a/src/core/plugins/plugincontainer.h +++ b/src/core/plugins/plugincontainer.h @@ -62,7 +62,7 @@ private: static QSettings *_cache = NULL; if(_cache == NULL) { - _cache = new QSettings("SnoreNotify","libsnore-plugin-cache"); + _cache = new QSettings("SnoreNotify","libsnore"); QCryptographicHash h(QCryptographicHash::Md5); h.addData(SnoreCorePrivate::pluginDir().absolutePath().toLatin1()); _cache->beginGroup( h.result().toHex()); diff --git a/src/core/plugins/snorebackend.cpp b/src/core/plugins/snorebackend.cpp index 7deb27d..8778af8 100644 --- a/src/core/plugins/snorebackend.cpp +++ b/src/core/plugins/snorebackend.cpp @@ -42,7 +42,7 @@ SnoreBackend::~SnoreBackend() { qDebug()<<"Deleting"<aplications()){ + foreach(const Application &a,snore()->aplications()){ slotDeregisterApplication(a); } } @@ -55,10 +55,11 @@ bool SnoreBackend::init( SnoreCore *snore ) { return false; } - connect( snore->d(), SIGNAL(applicationRegistered(Snore::Application*)), this, SLOT(slotRegisterApplication(Snore::Application*))); - connect( snore->d(), SIGNAL(applicationDeregistered(Snore::Application*)), this, SLOT(slotDeregisterApplication(Snore::Application*))); + connect( snore->d(), SIGNAL(applicationRegistered(const Snore::Application&)), this, SLOT(slotRegisterApplication(const Snore::Application&))); + connect( snore->d(), SIGNAL(applicationDeregistered(const Snore::Application&)), this, SLOT(slotDeregisterApplication(const Snore::Application&))); - foreach(Application *a,snore->aplications()){ + foreach(const Application &a,snore->aplications()) + { this->slotRegisterApplication(a); } @@ -127,12 +128,12 @@ bool SnoreBackend::supportsRichtext() return m_supportsRichtext; } -void SnoreBackend::slotRegisterApplication(Application *application) +void SnoreBackend::slotRegisterApplication(const Application &application) { Q_UNUSED(application); } -void SnoreBackend::slotDeregisterApplication(Application *application) +void SnoreBackend::slotDeregisterApplication(const Application &application) { Q_UNUSED(application); } diff --git a/src/core/plugins/snorebackend.h b/src/core/plugins/snorebackend.h index 4b9710f..2972e4d 100644 --- a/src/core/plugins/snorebackend.h +++ b/src/core/plugins/snorebackend.h @@ -50,8 +50,8 @@ signals: public slots: - virtual void slotRegisterApplication(Snore::Application *application ); - virtual void slotDeregisterApplication(Snore::Application *application ); + virtual void slotRegisterApplication(const Snore::Application &application ); + virtual void slotDeregisterApplication(const Application &application ); virtual void slotNotify ( Snore::Notification notification ) = 0; virtual void slotCloseNotification ( Snore::Notification notification ); diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 513a2a7..68b2b81 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -124,25 +124,24 @@ void SnoreCore::broadcastNotification ( Notification notification ) } } -void SnoreCore::registerApplication(Application *application) +void SnoreCore::registerApplication(const Application &application) { Q_D(SnoreCore); - if(!d->m_applications.contains(application->name())) + if(!d->m_applications.contains(application.name())) { - d->m_applications.insert ( application->name(),application ); + d->m_applications.insert ( application.name(),application ); emit d->applicationRegistered ( application ); } } -void SnoreCore::deregisterApplication(Application *application) +void SnoreCore::deregisterApplication(const Application &application) { Q_D(SnoreCore); emit d->applicationDeregistered (application ); - d->m_applications.take ( application->name() ); - application->deleteLater(); + d->m_applications.take ( application.name() ); } -const ApplicationsList &SnoreCore::aplications() const +const QHash &SnoreCore::aplications() const { Q_D(const SnoreCore); return d->m_applications; diff --git a/src/core/snore.h b/src/core/snore.h index ed6033d..e854cdb 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -48,10 +48,10 @@ public: void broadcastNotification( Notification notification ); - void registerApplication( Application *application ); - void deregisterApplication( Application *application ); + void registerApplication(const Application &application ); + void deregisterApplication(const Application &application ); - const ApplicationsList &aplications() const; + const QHash &aplications() const; const QStringList ¬ificationBackends() const; const QStringList ¬ificationFrontends() const; diff --git a/src/core/snore_p.h b/src/core/snore_p.h index acb81cc..82178d9 100644 --- a/src/core/snore_p.h +++ b/src/core/snore_p.h @@ -45,8 +45,8 @@ public: void notificationActionInvoked(Notification notification) const; signals: - void applicationRegistered(Snore::Application*); - void applicationDeregistered(Snore::Application*); + void applicationRegistered(const Snore::Application&); + void applicationDeregistered(const Snore::Application&); void notify(Snore::Notification noti); private slots: @@ -56,7 +56,7 @@ private: SnoreCore *q_ptr; Hint m_hints; - ApplicationsList m_applications; + QHash m_applications; QStringList m_notificationBackends; diff --git a/src/plugins/backends/growl/growl.cpp b/src/plugins/backends/growl/growl.cpp index 76eca0c..3a41439 100644 --- a/src/plugins/backends/growl/growl.cpp +++ b/src/plugins/backends/growl/growl.cpp @@ -66,19 +66,19 @@ bool Growl::init(SnoreCore *snore) return SnoreBackend::init(snore); } -void Growl::slotRegisterApplication(Application *application) +void Growl::slotRegisterApplication(const Application &application) { - gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); + gntp *growl = new gntp(application.name().toUtf8().constData(),application.icon().localUrl().toUtf8().constData()); gntp::gntp_callback callback(&Growl::gntpCallback); growl->set_gntp_callback(callback); // qDebug() << Q_FUNC_INFO << application->name().toUtf8().constData(); std::vector alerts; - foreach(Alert *a,application->alerts()) + foreach(const Alert &a,application.alerts()) { // qDebug() << Q_FUNC_INFO << a->name().toUtf8().constData(); - alerts.push_back(a->name().toUtf8().constData()); + alerts.push_back(a.name().toUtf8().constData()); } try @@ -88,12 +88,12 @@ void Growl::slotRegisterApplication(Application *application) { qWarning() << Q_FUNC_INFO << e.what(); } - m_applications.insert(application->name(),growl); + m_applications.insert(application.name(),growl); } -void Growl::slotDeregisterApplication(Application *application) +void Growl::slotDeregisterApplication(const Application &application) { - gntp *growl = m_applications.take(application->name()); + gntp *growl = m_applications.take(application.name()); if(growl == NULL) { return; diff --git a/src/plugins/backends/growl/growl.h b/src/plugins/backends/growl/growl.h index b15f4e2..ad1f832 100644 --- a/src/plugins/backends/growl/growl.h +++ b/src/plugins/backends/growl/growl.h @@ -44,8 +44,8 @@ private: gntp *m_defaultGNTP; public slots: - void slotRegisterApplication(Snore::Application *application); - void slotDeregisterApplication(Snore::Application *application); + void slotRegisterApplication(const Snore::Application &application); + void slotDeregisterApplication(const Snore::Application &application); void slotNotify(Snore::Notification notification); }; diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 3418f28..eb5513b 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -55,7 +55,8 @@ public: if(msg->message == SNARL_GLOBAL_MESSAGE){ int action = msg->wParam; if(action == SnarlEnums::SnarlLaunched){ - foreach(Application *a,m_snarl->snore()->aplications()){ + foreach(const Application &a,m_snarl->snore()->aplications()) + { m_snarl->slotRegisterApplication(a); } } @@ -160,36 +161,38 @@ bool SnarlBackend::init(SnoreCore *snore){ return SnoreBackend::init(snore); } -void SnarlBackend::slotRegisterApplication(Application *application){ +void SnarlBackend::slotRegisterApplication(const Application &application){ SnarlInterface *snarlInterface = NULL; - if(m_applications.contains(application->name())){ - snarlInterface = m_applications.value(application->name()); - }else{ - snarlInterface = new SnarlInterface(); - m_applications.insert(application->name(),snarlInterface); + if(m_applications.contains(application.name())) + { + snarlInterface = m_applications.value(application.name()); } - qDebug()<<"Register with Snarl"<name(); - QString appName = application->name(); - appName = appName.replace(" ","_");//app sig must not contain spaces + else + { + snarlInterface = new SnarlInterface(); + m_applications.insert(application.name(),snarlInterface); + } + QString appName = application.name().replace(" ","_");//app sig must not contain spaces snarlInterface->Register(appName.toUtf8().constData(), - application->name().toUtf8().constData(), - application->icon().localUrl().toUtf8().constData(), + application.name().toUtf8().constData(), + application.icon().localUrl().toUtf8().constData(), 0,(HWND)m_eventLoop->winId(),SNORENOTIFIER_MESSAGE_ID); - foreach(Alert *alert,application->alerts()){ - qDebug()<<"registering snarl alert"<name(); - snarlInterface->AddClass(alert->name().toUtf8().constData(), - alert->name().toUtf8().constData(), - 0,0,alert->icon().localUrl().toUtf8().constData()); + foreach(const Alert &alert,application.alerts()) + { + snarlInterface->AddClass(alert.name().toUtf8().constData(), + alert.name().toUtf8().constData(), + 0,0,alert.icon().localUrl().toUtf8().constData()); } } -void SnarlBackend::slotDeregisterApplication(Application *application){ - SnarlInterface *snarlInterface = m_applications.take(application->name()); +void SnarlBackend::slotDeregisterApplication(const Application &application){ + SnarlInterface *snarlInterface = m_applications.take(application.name()); if(snarlInterface == NULL) + { return; - QString appName = application->name(); - appName = appName.replace(" ","_");//app sig must not contain spaces + } + QString appName = application.name().replace(" ","_");//app sig must not contain spaces snarlInterface->Unregister(appName.toUtf8().constData()); delete snarlInterface; } @@ -225,14 +228,17 @@ void SnarlBackend::slotNotify(Notification notification){ !notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0, priority); - foreach(const Notification::Action *a, notification.actions()){ - snarlInterface->AddAction(id,a->name().toUtf8().constData(),QString("@").append(QString::number(a->id())).toUtf8().constData()); + 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; qDebug() << "snarl" << id << notification.id(); startTimeout(notification.id(),notification.timeout()); - }else{ + } + else + { //update message snarlInterface->Update(m_idMap[notification.updateID()], notification.alert().toUtf8().constData(), diff --git a/src/plugins/backends/snarl/snarl.h b/src/plugins/backends/snarl/snarl.h index 6e71952..5e7441b 100644 --- a/src/plugins/backends/snarl/snarl.h +++ b/src/plugins/backends/snarl/snarl.h @@ -41,8 +41,8 @@ private: Snarl::V42::SnarlInterface* m_defautSnarlinetrface; public slots: - void slotRegisterApplication(Snore::Application *application); - void slotDeregisterApplication(Snore::Application *application); + void slotRegisterApplication(const Snore::Application &application); + void slotDeregisterApplication(const Snore::Application &application); void slotNotify(Snore::Notification notification); void slotCloseNotification(Snore::Notification notification); diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index c094ff9..2a4d01e 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -55,9 +55,9 @@ bool FreedesktopFrontend::init(SnoreCore *snore){ } void FreedesktopFrontend::actionInvoked(Notification notification) { - if(notification.actionInvoked()) + if(notification.actionInvoked().isValid()) { - emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id())); + emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked().id())); } } @@ -90,8 +90,8 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, #else Icon appIcon(":/root/images/freedesktop-dbus.png"); #endif - Application *a = new Application(app_name,appIcon); - a->addAlert(new Alert("DBus Alert","DBus Alert",appIcon)); + Application a(app_name,appIcon); + a.addAlert(Alert("DBus Alert","DBus Alert",appIcon)); snore()->registerApplication(a); } @@ -105,8 +105,9 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id, noti.setUpdateID(replaces_id); } noti.setSource(this); - for(int i = 0;i < actions.length(); i+=2){ - noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1))); + for(int i = 0;i < actions.length(); i+=2) + { + noti.addAction(Notification::Action(actions.at(i).toInt(),actions.at(i+1))); } snore()->broadcastNotification(noti); diff --git a/src/plugins/frontends/snarlnetwork/parser.cpp b/src/plugins/frontends/snarlnetwork/parser.cpp index 5194147..6f0127f 100644 --- a/src/plugins/frontends/snarlnetwork/parser.cpp +++ b/src/plugins/frontends/snarlnetwork/parser.cpp @@ -122,21 +122,26 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ switch(action){ - case NOTIFICATION:{ + case NOTIFICATION: + { qDebug() << sNotification.notification.application(); - Application * appl = snarl->snore()->aplications().value(sNotification.notification.application()); - if(!snarl->snore()->aplications().contains(appl->name())){ + const 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()) + if(!appl.alerts().value(sNotification.notification.alert()).isActive()) + { break; + } sNotification.isNotification = true; return sNotification; break; } case ADD_CLASS: - if(sNotification.notification.alert().isEmpty()){ + if(sNotification.notification.alert().isEmpty()) + { qDebug()<<"Error registering alert with empty name"; break; } @@ -144,7 +149,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ { title = alert; } - snarl->m_applications.value(sNotification.notification.application())->addAlert(new Alert(alert,title)); + snarl->m_applications.value(sNotification.notification.application())->addAlert(Alert(alert,title)); break; case REGISTER: if(!sNotification.notification.application().isEmpty() && !snarl->m_applications.contains(sNotification.notification.application())){ diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index d32f45d..60266e5 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -56,10 +56,14 @@ bool SnarlNetworkFrontend::init(SnoreCore *snore){ void SnarlNetworkFrontend::actionInvoked(Notification notification){ //TODO:fix callback SnarlNotification sn=notifications.value(notification.id()); - if(notification.actionInvoked()->id() == 1 ) + if(notification.actionInvoked().id() == 1 ) + { callback(sn,"SNP/1.1/304/Notification acknowledged/"); - else if(notification.actionInvoked()->id() == 2) + } + else if(notification.actionInvoked().id() == 2) + { callback(sn,"SNP/1.1/302/Notification cancelled/"); + } } void SnarlNetworkFrontend::notificationClosed(Notification notification){ SnarlNotification sn=notifications.value(notification.id()); diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 82d9ec5..3ecfbd2 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -70,7 +70,8 @@ void SnoreNotify::save(){ void SnoreNotify::exit(){ qDebug()<<"Saving snore settings"; - foreach(Application *a,m_snore->aplications()){ + foreach(const Application &a,m_snore->aplications()) + { m_snore->deregisterApplication(a); } save(); diff --git a/src/trayicon.cpp b/src/trayicon.cpp index 3460b99..cc3b276 100644 --- a/src/trayicon.cpp +++ b/src/trayicon.cpp @@ -28,49 +28,54 @@ using namespace Snore; -TrayIcon::TrayIcon() +TrayIcon::TrayIcon(): + m_trayIcon(new QSystemTrayIcon(QIcon(":/root/snore.png"))) { - _trayIcon = new QSystemTrayIcon(QIcon(":/root/snore.png")); } -void TrayIcon::initConextMenu(SnoreCore *snore){ - _snore = snore; - _trayIcon->setVisible(true); +void TrayIcon::initConextMenu(SnoreCore *snore) +{ + m_snore = snore; + m_trayIcon->setVisible(true); - _trayMenu = new QMenu("SnoreNotify"); - _trayMenu->addAction(QString("SnoreNotify ").append(Version::version())); - _trayMenu->addSeparator(); - connect(_trayMenu->addAction(QString("Test")), SIGNAL(triggered()), this, SLOT(slotTestNotification())); - _trayMenu->addSeparator(); - foreach(const QString &back,_snore->notificationBackends()){ - QAction *b= new QAction(back,this); - connect(b,SIGNAL(triggered()),this,SLOT(setPrimaryBackend())); + m_trayMenu = new QMenu("SnoreNotify"); + m_trayMenu->addAction(QString("SnoreNotify ").append(Version::version())); + m_trayMenu->addSeparator(); + m_trayMenu->addAction("Test Notification", this, SLOT(slotTestNotification())); + m_trayMenu->addSeparator(); + foreach(const QString &back,m_snore->notificationBackends()) + { + QAction *b = m_trayMenu->addAction(back, this, SLOT(setPrimaryBackend())); b->setCheckable(true); - if(back == _snore->primaryNotificationBackend()) + if(back == m_snore->primaryNotificationBackend()) + { b->setChecked(true); - _backendActions.append(b); - _trayMenu->addAction(b); + } + m_backendActions.append(b); } - _trayMenu->addSeparator(); - _trayMenu->addAction("Exit",qApp,SLOT(quit())); + m_trayMenu->addSeparator(); + m_trayMenu->addAction("Exit",qApp,SLOT(quit())); - _trayIcon->setContextMenu(_trayMenu); + m_trayIcon->setContextMenu(m_trayMenu); } -void TrayIcon::hide(){ - _trayIcon->setVisible(false); +void TrayIcon::hide() +{ + m_trayIcon->setVisible(false); } -QSystemTrayIcon* TrayIcon::trayIcon(){ - return _trayIcon; +QSystemTrayIcon* TrayIcon::trayIcon() +{ + return m_trayIcon; } void TrayIcon::setPrimaryBackend(){ - QAction *a= dynamic_cast(sender()); - _snore->setPrimaryNotificationBackend(a->text()); + QAction *a = qobject_cast(sender()); + m_snore->setPrimaryNotificationBackend(a->text()); - foreach(QAction *action,_backendActions){ + foreach(QAction *action,m_backendActions) + { action->setChecked(false); } a->setChecked(true); @@ -79,7 +84,12 @@ void TrayIcon::setPrimaryBackend(){ void TrayIcon::slotTestNotification() { + Application appl("SnoreNotify"); + appl.addAlert(Alert("Default")); + m_snore->registerApplication(appl); Notification n("SnoreNotify","Default","Hello World","This is Snore",Icon(":/root/snore.png")); - _snore->broadcastNotification(n); + n.addAction(Notification::Action(1,"Test Action")); + m_snore->broadcastNotification(n); + m_snore->deregisterApplication(appl); } diff --git a/src/trayicon.h b/src/trayicon.h index 0a0d8a5..ceda150 100644 --- a/src/trayicon.h +++ b/src/trayicon.h @@ -36,10 +36,10 @@ public: class QSystemTrayIcon* trayIcon(); private: - class QSystemTrayIcon *_trayIcon; - class QMenu *_trayMenu; - class QList _backendActions; - class Snore::SnoreCore *_snore; + class QSystemTrayIcon *m_trayIcon; + class QMenu *m_trayMenu; + class QList m_backendActions; + class Snore::SnoreCore *m_snore; public slots: