dont initialize snarlbackend if snarl is not running

This commit is contained in:
Patrick von Reth 2013-11-20 18:22:48 +01:00
parent 9f5b476b05
commit e5add0f58b
3 changed files with 40 additions and 8 deletions

View File

@ -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<std::string> alerts;
alerts.push_back("Default");
try{
m_defaultGNTP->regist(alerts);
}catch(const std::exception& e){
qDebug()<<"Growl:"<<e.what();
delete m_defaultGNTP;
m_defaultGNTP = NULL;
return false;
}
return SnoreBackend::init(snore);
}
void Growl::slotRegisterApplication(Application *application)
{
gntp *growl = new gntp(application->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:"<<notification.application()<<Notification.toPlainText(notification.title());
try{
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"<<id<<QString(reason.c_str())<<QString(data.c_str());
Notification n = s_instance->snore()->getActiveNotificationByID(id);
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;

View File

@ -32,6 +32,8 @@ class Growl:public Snore::SnoreBackend
public:
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<QString,class gntp*> m_applications;
gntp *m_defaultGNTP;
public slots:
void slotRegisterApplication(Snore::Application *application);

View File

@ -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: "<<snarlInterface->GetVersion();
m_defautSnarlinetrface = new SnarlInterface();