From e5add0f58b1e5a32fb0cd2a517ebe9ddea7da6bd Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 20 Nov 2013 18:22:48 +0100 Subject: [PATCH] dont initialize snarlbackend if snarl is not running --- src/plugins/backends/growl/growl.cpp | 36 +++++++++++++++++++++++----- src/plugins/backends/growl/growl.h | 5 +++- src/plugins/backends/snarl/snarl.cpp | 7 +++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/plugins/backends/growl/growl.cpp b/src/plugins/backends/growl/growl.cpp index 1bb283a..907806f 100644 --- a/src/plugins/backends/growl/growl.cpp +++ b/src/plugins/backends/growl/growl.cpp @@ -33,7 +33,8 @@ Growl *Growl::s_instance = NULL; Growl::Growl(): SnoreBackend("Growl",false,false), - m_id(0) + m_id(0), + m_defaultGNTP(NULL) { s_instance = this; } @@ -44,11 +45,29 @@ Growl::~Growl(){ this->slotUnregisterApplication(a); } } + delete m_defaultGNTP; } -void Growl::slotRegisterApplication(Application *application){ - gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); +bool Growl::init(SnoreCore *snore) +{ + m_defaultGNTP = new gntp(QString("SnoreNotify").toUtf8().constData()); + + std::vector alerts; + alerts.push_back("Default"); + try{ + m_defaultGNTP->regist(alerts); + }catch(const std::exception& e){ + qDebug()<<"Growl:"<name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData()); gntp::gntp_callback callback(&Growl::gntpCallback); growl->set_gntp_callback(callback); @@ -74,11 +93,15 @@ void Growl::slotUnregisterApplication(Application *application){ void Growl::slotNotify(Notification notification){ gntp *growl = m_applications.value(notification.application()); + QString alert = notification.alert(); if(growl == NULL) - return; + { + growl = m_defaultGNTP; + alert = "Default"; + } //qDebug()<<"Notify Growl:"<notify(notification.alert().toUtf8().constData(),notification.id(), + growl->notify(alert.toUtf8().constData(),notification.id(), Snore::toPlainText(notification.title()).toUtf8().constData(), Snore::toPlainText(notification.text()).toUtf8().constData(), notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1"); @@ -88,7 +111,8 @@ void Growl::slotNotify(Notification notification){ } } -void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data){ +void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data) +{ qDebug()<<"Growl Callback"<snore()->getActiveNotificationByID(id); NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE; diff --git a/src/plugins/backends/growl/growl.h b/src/plugins/backends/growl/growl.h index 725c898..fbd784f 100644 --- a/src/plugins/backends/growl/growl.h +++ b/src/plugins/backends/growl/growl.h @@ -31,7 +31,9 @@ class Growl:public Snore::SnoreBackend public: Growl(); - ~Growl(); + ~Growl(); + virtual bool init(Snore::SnoreCore *snore); + static void gntpCallback(const int &id,const std::string &reason,const std::string &data); private: @@ -39,6 +41,7 @@ private: static Growl *s_instance; uint m_id; QHash m_applications; + gntp *m_defaultGNTP; public slots: void slotRegisterApplication(Snore::Application *application); diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index 3b24e3f..52318cf 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -149,8 +149,13 @@ SnarlBackend::~SnarlBackend() bool SnarlBackend::init(SnoreCore *snore){ - m_eventLoop = new SnarlBackend::SnarlWidget(this); SnarlInterface *snarlInterface = new SnarlInterface(); + if(!snarlInterface->IsSnarlRunning()) + { + delete snarlInterface; + return false; + } + m_eventLoop = new SnarlBackend::SnarlWidget(this); m_applications.insert("SnoreNotify",snarlInterface); qDebug()<<"Initiating Snarl Backend, Snarl version: "<GetVersion(); m_defautSnarlinetrface = new SnarlInterface();