dont initialize snarlbackend if snarl is not running
This commit is contained in:
parent
9f5b476b05
commit
e5add0f58b
|
@ -33,7 +33,8 @@ Growl *Growl::s_instance = NULL;
|
||||||
|
|
||||||
Growl::Growl():
|
Growl::Growl():
|
||||||
SnoreBackend("Growl",false,false),
|
SnoreBackend("Growl",false,false),
|
||||||
m_id(0)
|
m_id(0),
|
||||||
|
m_defaultGNTP(NULL)
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
}
|
}
|
||||||
|
@ -44,11 +45,29 @@ Growl::~Growl(){
|
||||||
this->slotUnregisterApplication(a);
|
this->slotUnregisterApplication(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
delete m_defaultGNTP;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Growl::slotRegisterApplication(Application *application){
|
bool Growl::init(SnoreCore *snore)
|
||||||
gntp *growl = new gntp(application->name().toUtf8().constData(),application->icon().localUrl().toUtf8().constData());
|
{
|
||||||
|
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);
|
gntp::gntp_callback callback(&Growl::gntpCallback);
|
||||||
growl->set_gntp_callback(callback);
|
growl->set_gntp_callback(callback);
|
||||||
|
@ -74,11 +93,15 @@ void Growl::slotUnregisterApplication(Application *application){
|
||||||
|
|
||||||
void Growl::slotNotify(Notification notification){
|
void Growl::slotNotify(Notification notification){
|
||||||
gntp *growl = m_applications.value(notification.application());
|
gntp *growl = m_applications.value(notification.application());
|
||||||
|
QString alert = notification.alert();
|
||||||
if(growl == NULL)
|
if(growl == NULL)
|
||||||
return;
|
{
|
||||||
|
growl = m_defaultGNTP;
|
||||||
|
alert = "Default";
|
||||||
|
}
|
||||||
//qDebug()<<"Notify Growl:"<<notification.application()<<Notification.toPlainText(notification.title());
|
//qDebug()<<"Notify Growl:"<<notification.application()<<Notification.toPlainText(notification.title());
|
||||||
try{
|
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.title()).toUtf8().constData(),
|
||||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||||
notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1");
|
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());
|
qDebug()<<"Growl Callback"<<id<<QString(reason.c_str())<<QString(data.c_str());
|
||||||
Notification n = s_instance->snore()->getActiveNotificationByID(id);
|
Notification n = s_instance->snore()->getActiveNotificationByID(id);
|
||||||
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
|
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
|
||||||
|
|
|
@ -32,6 +32,8 @@ class Growl:public Snore::SnoreBackend
|
||||||
public:
|
public:
|
||||||
Growl();
|
Growl();
|
||||||
~Growl();
|
~Growl();
|
||||||
|
virtual bool init(Snore::SnoreCore *snore);
|
||||||
|
|
||||||
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);
|
static void gntpCallback(const int &id,const std::string &reason,const std::string &data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -39,6 +41,7 @@ private:
|
||||||
static Growl *s_instance;
|
static Growl *s_instance;
|
||||||
uint m_id;
|
uint m_id;
|
||||||
QHash<QString,class gntp*> m_applications;
|
QHash<QString,class gntp*> m_applications;
|
||||||
|
gntp *m_defaultGNTP;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void slotRegisterApplication(Snore::Application *application);
|
void slotRegisterApplication(Snore::Application *application);
|
||||||
|
|
|
@ -149,8 +149,13 @@ SnarlBackend::~SnarlBackend()
|
||||||
|
|
||||||
|
|
||||||
bool SnarlBackend::init(SnoreCore *snore){
|
bool SnarlBackend::init(SnoreCore *snore){
|
||||||
m_eventLoop = new SnarlBackend::SnarlWidget(this);
|
|
||||||
SnarlInterface *snarlInterface = new SnarlInterface();
|
SnarlInterface *snarlInterface = new SnarlInterface();
|
||||||
|
if(!snarlInterface->IsSnarlRunning())
|
||||||
|
{
|
||||||
|
delete snarlInterface;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_eventLoop = new SnarlBackend::SnarlWidget(this);
|
||||||
m_applications.insert("SnoreNotify",snarlInterface);
|
m_applications.insert("SnoreNotify",snarlInterface);
|
||||||
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
|
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersion();
|
||||||
m_defautSnarlinetrface = new SnarlInterface();
|
m_defautSnarlinetrface = new SnarlInterface();
|
||||||
|
|
Loading…
Reference in New Issue