From ba8a7d67ff9815f480531acab4a16cfa133929a5 Mon Sep 17 00:00:00 2001 From: romibi Date: Mon, 5 Feb 2018 18:40:37 +0100 Subject: [PATCH] Split systray notification backend into SystrayAnimationNotificationBackend for tray icon animation and SystrayNotificationBackend for tray message popup --- src/qtui/CMakeLists.txt | 1 + src/qtui/mainwin.cpp | 4 ++ .../systrayanimationnotificationbackend.cpp | 69 +++++++++++++++++++ .../systrayanimationnotificationbackend.h | 45 ++++++++++++ src/qtui/systraynotificationbackend.cpp | 13 ---- src/qtui/systraynotificationbackend.h | 8 +-- 6 files changed, 120 insertions(+), 20 deletions(-) create mode 100644 src/qtui/systrayanimationnotificationbackend.cpp create mode 100644 src/qtui/systrayanimationnotificationbackend.h diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index 518ceacb..d78f0f9b 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -46,6 +46,7 @@ set(SOURCES settingspagedlg.cpp simplenetworkeditor.cpp systemtray.cpp + systrayanimationnotificationbackend.cpp systraynotificationbackend.cpp taskbarnotificationbackend.cpp titlesetter.cpp diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index b1a4eb7b..33bef462 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -114,6 +114,7 @@ #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 index 00000000..2cb05507 --- /dev/null +++ b/src/qtui/systrayanimationnotificationbackend.cpp @@ -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 +#include +#include +#include +#include + +#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 index 00000000..6a720012 --- /dev/null +++ b/src/qtui/systrayanimationnotificationbackend.h @@ -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 diff --git a/src/qtui/systraynotificationbackend.cpp b/src/qtui/systraynotificationbackend.cpp index c6be4baa..a0f00d80 100644 --- a/src/qtui/systraynotificationbackend.cpp +++ b/src/qtui/systraynotificationbackend.cpp @@ -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", diff --git a/src/qtui/systraynotificationbackend.h b/src/qtui/systraynotificationbackend.h index ec608e54..64e6f9ce 100644 --- a/src/qtui/systraynotificationbackend.h +++ b/src/qtui/systraynotificationbackend.h @@ -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 _notifications; bool _blockActivation; }; @@ -77,6 +74,3 @@ private: QCheckBox *_showBubbleBox; bool _showBubble; }; - - -#endif -- 2.20.1