Split systray notification backend
authorromibi <romibi@bluewin.ch>
Mon, 5 Feb 2018 17:40:37 +0000 (18:40 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 14 Jun 2018 18:53:26 +0000 (20:53 +0200)
into SystrayAnimationNotificationBackend for tray icon animation
and SystrayNotificationBackend for tray message popup

src/qtui/CMakeLists.txt
src/qtui/mainwin.cpp
src/qtui/systrayanimationnotificationbackend.cpp [new file with mode: 0644]
src/qtui/systrayanimationnotificationbackend.h [new file with mode: 0644]
src/qtui/systraynotificationbackend.cpp
src/qtui/systraynotificationbackend.h

index 518ceac..d78f0f9 100644 (file)
@@ -46,6 +46,7 @@ set(SOURCES
     settingspagedlg.cpp
     simplenetworkeditor.cpp
     systemtray.cpp
+    systrayanimationnotificationbackend.cpp
     systraynotificationbackend.cpp
     taskbarnotificationbackend.cpp
     titlesetter.cpp
index b1a4eb7..33bef46 100644 (file)
 #else /* HAVE_KDE */
 #  include "knotificationbackend.h"
 #endif /* HAVE_KDE */
+#include "systrayanimationnotificationbackend.h"
 
 
 #ifdef HAVE_LIBSNORE
@@ -257,6 +258,9 @@ void MainWin::init()
 #endif /* HAVE_KDE */
 
 
+#ifndef QT_NO_SYSTEMTRAYICON
+    QtUi::registerNotificationBackend(new SystrayAnimationNotificationBackend(this));
+#endif
 #ifdef HAVE_LIBSNORE
     QtUi::registerNotificationBackend(new SnoreNotificationBackend(this));
 #elif !defined(QT_NO_SYSTEMTRAYICON) && !defined(HAVE_KDE)
diff --git a/src/qtui/systrayanimationnotificationbackend.cpp b/src/qtui/systrayanimationnotificationbackend.cpp
new file mode 100644 (file)
index 0000000..2cb0550
--- /dev/null
@@ -0,0 +1,69 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2016 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#include <QApplication>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QIcon>
+#include <QHBoxLayout>
+
+#include "systrayanimationnotificationbackend.h"
+
+#include "client.h"
+#include "clientsettings.h"
+#include "mainwin.h"
+#include "networkmodel.h"
+#include "qtui.h"
+#include "systemtray.h"
+
+SystrayAnimationNotificationBackend::SystrayAnimationNotificationBackend(QObject *parent)
+    : AbstractNotificationBackend(parent)
+{
+    NotificationSettings notificationSettings;
+    notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
+}
+
+
+void SystrayAnimationNotificationBackend::notify(const Notification &n)
+{
+    if (n.type != Highlight && n.type != PrivMsg)
+        return;
+
+    if (_animate)
+        QtUi::mainWindow()->systemTray()->setAlert(true);
+}
+
+
+void SystrayAnimationNotificationBackend::close(uint notificationId)
+{
+    QtUi::mainWindow()->systemTray()->setAlert(false);
+}
+
+
+void SystrayAnimationNotificationBackend::animateChanged(const QVariant &v)
+{
+    _animate = v.toBool();
+}
+
+
+SettingsPage *SystrayAnimationNotificationBackend::createConfigWidget() const
+{
+    return nullptr;
+}
\ No newline at end of file
diff --git a/src/qtui/systrayanimationnotificationbackend.h b/src/qtui/systrayanimationnotificationbackend.h
new file mode 100644 (file)
index 0000000..6a72001
--- /dev/null
@@ -0,0 +1,45 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2016 by the Quassel Project                        *
+ *   devel@quassel-irc.org                                                 *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+ ***************************************************************************/
+
+#pragma once
+
+#include "abstractnotificationbackend.h"
+#include "settingspage.h"
+#include "systemtray.h"
+
+class QCheckBox;
+
+class SystrayAnimationNotificationBackend : public AbstractNotificationBackend
+{
+    Q_OBJECT
+
+public:
+    SystrayAnimationNotificationBackend(QObject *parent = 0);
+
+    void notify(const Notification &);
+    void close(uint notificationId);
+    virtual SettingsPage *createConfigWidget() const;
+
+private slots:
+    void animateChanged(const QVariant &);
+
+private:
+    bool _animate;
+};
\ No newline at end of file
index c6be4ba..a0f00d8 100644 (file)
@@ -39,7 +39,6 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
 {
     NotificationSettings notificationSettings;
     notificationSettings.initAndNotify("Systray/ShowBubble", this, SLOT(showBubbleChanged(QVariant)), true);
-    notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
 
     connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked(uint)), SLOT(notificationActivated(uint)));
     connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)),
@@ -63,9 +62,6 @@ void SystrayNotificationBackend::notify(const Notification &n)
         QtUi::mainWindow()->systemTray()->showMessage(title, message, SystemTray::Information, 10000, n.notificationId);
     }
 
-    if (_animate)
-        QtUi::mainWindow()->systemTray()->setAlert(true);
-
     updateToolTip();
 }
 
@@ -82,9 +78,6 @@ void SystrayNotificationBackend::close(uint notificationId)
 
     QtUi::mainWindow()->systemTray()->closeMessage(notificationId);
 
-    //if(!_notifications.count()) //FIXME make configurable
-    QtUi::mainWindow()->systemTray()->setAlert(false);
-
     updateToolTip();
 }
 
@@ -133,12 +126,6 @@ void SystrayNotificationBackend::showBubbleChanged(const QVariant &v)
 }
 
 
-void SystrayNotificationBackend::animateChanged(const QVariant &v)
-{
-    _animate = v.toBool();
-}
-
-
 void SystrayNotificationBackend::updateToolTip()
 {
     QtUi::mainWindow()->systemTray()->setToolTip("Quassel IRC",
index ec608e5..64e6f9c 100644 (file)
@@ -18,8 +18,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef SYSTRAYNOTIFICATIONBACKEND_H_
-#define SYSTRAYNOTIFICATIONBACKEND_H_
+#pragma once
 
 #include "abstractnotificationbackend.h"
 #include "settingspage.h"
@@ -45,7 +44,6 @@ private slots:
     void notificationActivated(uint notificationId);
     void notificationActivated(SystemTray::ActivationReason);
 
-    void animateChanged(const QVariant &);
     void showBubbleChanged(const QVariant &);
     void updateToolTip();
 
@@ -53,7 +51,6 @@ private:
     class ConfigWidget;
 
     bool _showBubble;
-    bool _animate;
     QList<Notification> _notifications;
     bool _blockActivation;
 };
@@ -77,6 +74,3 @@ private:
     QCheckBox *_showBubbleBox;
     bool _showBubble;
 };
-
-
-#endif