code style in snore backend, and a more user friendly config widget
authorPatrick von Reth <vonreth@kde.org>
Mon, 25 Nov 2013 11:46:02 +0000 (12:46 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 22 Dec 2013 23:34:45 +0000 (00:34 +0100)
src/qtui/snorenotificationbackend.cpp
src/qtui/snorenotificationbackend.h

index 0ada5ee..8a33dc6 100644 (file)
@@ -42,7 +42,7 @@ SnoreNotificationBackend::SnoreNotificationBackend (QObject *parent)
       m_systrayBackend(NULL)
 {
     NotificationSettings notificationSettings;
       m_systrayBackend(NULL)
 {
     NotificationSettings notificationSettings;
-    QString backend = notificationSettings.value("Snore/Backend", "SystemTray").toString();
+    QString backend = notificationSettings.value("Snore/Backend", "Default").toString();
     m_timeout = notificationSettings.value("Snore/Timeout",10).toInt();
 
     notificationSettings.notify("Snore/Backend", this, SLOT(backendChanged(const QVariant &)));
     m_timeout = notificationSettings.value("Snore/Timeout",10).toInt();
 
     notificationSettings.notify("Snore/Backend", this, SLOT(backendChanged(const QVariant &)));
@@ -64,35 +64,43 @@ SnoreNotificationBackend::SnoreNotificationBackend (QObject *parent)
     m_snore->applicationIsInitialized (a);
 
     backendChanged(QVariant::fromValue(backend));
     m_snore->applicationIsInitialized (a);
 
     backendChanged(QVariant::fromValue(backend));
+
+
 }
 
 }
 
-SnoreNotificationBackend::~SnoreNotificationBackend(){
+SnoreNotificationBackend::~SnoreNotificationBackend()
+{
     m_snore->removeApplication("Quassel");
     m_snore->deleteLater();
 }
 
     m_snore->removeApplication("Quassel");
     m_snore->deleteLater();
 }
 
-void SnoreNotificationBackend::backendChanged(const QVariant &v){
+void SnoreNotificationBackend::backendChanged(const QVariant &v)
+{
     QString backend = v.toString();
     QString backend = v.toString();
-    if(backend == "SystemTray"){
-        if(m_systrayBackend == NULL){
-            m_systrayBackend = new SystrayNotificationBackend(this);
-            QtUi::registerNotificationBackend(m_systrayBackend);
+    if(backend == "Default")
+    {
+        if(m_snore->setPrimaryNotificationBackend())//try to find the default backend for the platform
+        {
+            return;
         }
         }
-    }else{
-        if(m_systrayBackend != NULL){
-            QtUi::unregisterNotificationBackend(m_systrayBackend);
-            delete m_systrayBackend;
-            m_systrayBackend = NULL;
+    }
+    else if(backend != "SystemTray")
+    {
+        if(setSnoreBackend(backend))
+        {
+            return;
         }
         }
-        m_snore->setPrimaryNotificationBackend(backend);
     }
     }
+    setTraybackend();
 }
 
 }
 
-void SnoreNotificationBackend::timeoutChanged(const QVariant &v){
+void SnoreNotificationBackend::timeoutChanged(const QVariant &v)
+{
     m_timeout = v.toInt();
 }
 
     m_timeout = v.toInt();
 }
 
-void SnoreNotificationBackend::notify(const Notification &n){
+void SnoreNotificationBackend::notify(const Notification &n)
+{
     if(m_systrayBackend != NULL)
         return;
     QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
     if(m_systrayBackend != NULL)
         return;
     QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
@@ -103,21 +111,44 @@ void SnoreNotificationBackend::notify(const Notification &n){
     m_snore->broadcastNotification(noti);
 }
 
     m_snore->broadcastNotification(noti);
 }
 
-void SnoreNotificationBackend::close(uint notificationId){
+void SnoreNotificationBackend::close(uint notificationId)
+{
     if(m_systrayBackend != NULL)
         return;
     Snore::Notification n = m_snore->getActiveNotificationByID(m_notificationIds.take(notificationId));
     m_snore->requestCloseNotification(n,Snore::NotificationEnums::CloseReasons::CLOSED);
 }
 
     if(m_systrayBackend != NULL)
         return;
     Snore::Notification n = m_snore->getActiveNotificationByID(m_notificationIds.take(notificationId));
     m_snore->requestCloseNotification(n,Snore::NotificationEnums::CloseReasons::CLOSED);
 }
 
-void SnoreNotificationBackend::actionInvoked(Snore::Notification n){
+void SnoreNotificationBackend::actionInvoked(Snore::Notification n)
+{
     emit activated(n.hints().value("QUASSEL_ID").toUInt());
 }
 
     emit activated(n.hints().value("QUASSEL_ID").toUInt());
 }
 
-SettingsPage *SnoreNotificationBackend::createConfigWidget()const{
+SettingsPage *SnoreNotificationBackend::createConfigWidget()const
+{
     return new ConfigWidget(m_snore);
 }
 
     return new ConfigWidget(m_snore);
 }
 
+void SnoreNotificationBackend::setTraybackend()
+{
+    if(m_systrayBackend == NULL){
+        m_systrayBackend = new SystrayNotificationBackend(this);
+        QtUi::registerNotificationBackend(m_systrayBackend);
+    }
+}
+
+bool SnoreNotificationBackend::setSnoreBackend(const QString &backend)
+{
+    if(m_systrayBackend != NULL){
+        QtUi::unregisterNotificationBackend(m_systrayBackend);
+        delete m_systrayBackend;
+        m_systrayBackend = NULL;
+    }
+    return m_snore->setPrimaryNotificationBackend(backend);
+}
+
+
+
 
 /***************************************************************************/
 
 
 /***************************************************************************/
 
@@ -126,42 +157,53 @@ SnoreNotificationBackend::ConfigWidget::ConfigWidget(Snore::SnoreCore *snore,QWi
       m_snore(snore)
 {
     ui.setupUi(this);
       m_snore(snore)
 {
     ui.setupUi(this);
-    ui.backends->insertItems(0,m_snore->notificationBackends());
+    ui.backends->insertItem(0,"Default");
+    ui.backends->insertItems(1,m_snore->notificationBackends());
 
     connect(ui.backends, SIGNAL(currentIndexChanged(QString)), SLOT(backendChanged(QString)));
     connect(ui.timeout,SIGNAL(valueChanged(int)),this,SLOT(timeoutChanged(int)));
 }
 
 
     connect(ui.backends, SIGNAL(currentIndexChanged(QString)), SLOT(backendChanged(QString)));
     connect(ui.timeout,SIGNAL(valueChanged(int)),this,SLOT(timeoutChanged(int)));
 }
 
-void SnoreNotificationBackend::ConfigWidget::backendChanged(const QString &b){
-        ui.backends->setCurrentIndex(ui.backends->findText(b));
-        setChangedState(true);
+void SnoreNotificationBackend::ConfigWidget::backendChanged(const QString &b)
+{
+    ui.backends->setCurrentIndex(ui.backends->findText(b));
+    setChangedState(true);
 }
 
 }
 
-void SnoreNotificationBackend::ConfigWidget::timeoutChanged(int i){
+void SnoreNotificationBackend::ConfigWidget::timeoutChanged(int i)
+{
     ui.timeout->setValue(i);
     setChangedState(true);
 
 }
 
     ui.timeout->setValue(i);
     setChangedState(true);
 
 }
 
-bool SnoreNotificationBackend::ConfigWidget::hasDefaults() const {
+bool SnoreNotificationBackend::ConfigWidget::hasDefaults() const
+{
     return true;
 }
 
     return true;
 }
 
-void SnoreNotificationBackend::ConfigWidget::defaults() {
-    backendChanged("SystemTray");
+void SnoreNotificationBackend::ConfigWidget::defaults()
+{
+    backendChanged("Default");
     timeoutChanged(10);
 }
 
     timeoutChanged(10);
 }
 
-void SnoreNotificationBackend::ConfigWidget::load() {
+void SnoreNotificationBackend::ConfigWidget::load()
+{
     NotificationSettings s;
     NotificationSettings s;
-    QString backend = s.value("Snore/Backend", "SystemTray").toString();
+    QString backend = m_snore->primaryNotificationBackend();
+    if(backend.isEmpty()){
+        backend = "SystemTray";
+    }
+    qDebug() << s.value("Snore/Timeout",10);
     int timeout = s.value("Snore/Timeout",10).toInt();
     ui.backends->setCurrentIndex(ui.backends->findText(backend));
     ui.timeout->setValue(timeout);
     setChangedState(false);
 }
 
     int timeout = s.value("Snore/Timeout",10).toInt();
     ui.backends->setCurrentIndex(ui.backends->findText(backend));
     ui.timeout->setValue(timeout);
     setChangedState(false);
 }
 
-void SnoreNotificationBackend::ConfigWidget::save() {
+void SnoreNotificationBackend::ConfigWidget::save()
+{
     NotificationSettings s;
     s.setValue("Snore/Backend", ui.backends->currentText());
     s.setValue("Snore/Timeout",ui.timeout->value());
     NotificationSettings s;
     s.setValue("Snore/Backend", ui.backends->currentText());
     s.setValue("Snore/Timeout",ui.timeout->value());
index ef3c1af..bfdb25d 100644 (file)
@@ -52,10 +52,13 @@ signals:
 public slots:
     void actionInvoked(Snore::Notification);
 private slots:
 public slots:
     void actionInvoked(Snore::Notification);
 private slots:
-  void backendChanged(const QVariant &);
-  void timeoutChanged(const QVariant &);
+    void backendChanged(const QVariant &);
+    void timeoutChanged(const QVariant &);
 
 private:
 
 private:
+    void setTraybackend();
+    bool setSnoreBackend(const QString &backend);
+
     class ConfigWidget;
     SystrayNotificationBackend * m_systrayBackend;
     Snore::SnoreCore *m_snore;
     class ConfigWidget;
     SystrayNotificationBackend * m_systrayBackend;
     Snore::SnoreCore *m_snore;