From b2cad9a71224c77e81e99a81ec2f41ee408921a1 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Thu, 18 Jul 2013 16:59:06 +0200 Subject: [PATCH] default initialisation for the backends --- src/core/snore.cpp | 46 ++++++++++++++++++++++++++++++++++++++++----- src/core/snore.h | 3 ++- src/snorenotify.cpp | 10 ++++++++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/core/snore.cpp b/src/core/snore.cpp index 1c9564e..c8d7352 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -286,24 +286,60 @@ const QStringList &SnoreCore::secondaryNotificationBackends() const return m_secondaryNotificationBackends; } -void SnoreCore::setPrimaryNotificationBackend ( const QString &backend ) +bool SnoreCore::setPrimaryNotificationBackend ( const QString &backend ) { if(!pluginCache().contains(backend)){ qDebug()<<"Unknown Backend:"<(pluginCache()[backend]->load()); if(!b->isInitialized()){ if(!b->init(this)){ qDebug()<<"Failed to initialize"<name(); - return; + return false; } connect(b,SIGNAL(closeNotification(Snore::Notification)),this,SLOT(slotNotificationClosed(Snore::Notification))); } - - m_notificationBackend = b; + return true; +} + +bool SnoreCore::setPrimaryNotificationBackend() +{ + QStringList backends = notificationBackends(); +#ifdef Q_OS_WIN + if(QSysInfo::windowsVersion() == QSysInfo::WV_WINDOWS8 && backends.contains("SnoreToast")) + { + if(setPrimaryNotificationBackend("SnoreToast")) + return true; + } + if( backends.contains("Growl")) + { + if(setPrimaryNotificationBackend("Growl")) + return true; + } + if( backends.contains("Snarl")) + { + if(setPrimaryNotificationBackend("Snarl")) + return true; + } +#elif defined(Q_OS_LINUX) + if( backends.contains("FreedesktopNotification_Backend")) + { + return setPrimaryNotificationBackend("FreedesktopNotification_Backend"); + } +#elif defined(Q_OS_MAC) + if( backends.contains("Growl")) + { + return setPrimaryNotificationBackend("Growl"); + } +#endif + if( trayIcon() && backends.contains("SystemTray")) + { + return setPrimaryNotificationBackend("SystemTray"); + } + return false; } const QString &SnoreCore::primaryNotificationBackend(){ diff --git a/src/core/snore.h b/src/core/snore.h index 341a38a..fbe683b 100644 --- a/src/core/snore.h +++ b/src/core/snore.h @@ -60,7 +60,8 @@ public: const QStringList ¬ificationFrontends() const; const QStringList &secondaryNotificationBackends() const; - void setPrimaryNotificationBackend ( const QString &backend ); + bool setPrimaryNotificationBackend( const QString &backend ); + bool setPrimaryNotificationBackend(); const QString &primaryNotificationBackend(); QSystemTrayIcon *trayIcon(); diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 0f79afc..72aa39a 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -54,9 +54,15 @@ SnoreNotify::~SnoreNotify(){ } void SnoreNotify::load(){ - m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend","SystemTray").toString()); + if(m_settings.contains("notificationBackend")) + { + m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend","SystemTray").toString()); + } + else + { + m_snore->setPrimaryNotificationBackend(); + } } - void SnoreNotify::save(){ m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend()); }