qtui: Rework the attention state behavior of the tray icon
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 14 Jun 2018 22:59:15 +0000 (00:59 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 15 Jun 2018 23:30:32 +0000 (01:30 +0200)
Move the attention behavior handling into the SystemTray base class,
which now determines the correct icon names to display based on
the tray state and notification settings. Systray implementations
now just react on signals from the base class to update their
icons accordingly.

Extend the systray notification settings to allow for a more fine-
grained configuration. Users can now choose if the tray should be
alerted at all, and if so, if the tray icon should change color or
even blink instead of relying on the visualizer's default.

This now works with both StatusNotifierItem and the legacy tray.

Supersedes and closes GH-327.

src/qtui/CMakeLists.txt
src/qtui/knotificationbackend.cpp
src/qtui/legacysystemtray.cpp
src/qtui/legacysystemtray.h
src/qtui/statusnotifieritem.cpp
src/qtui/systemtray.cpp
src/qtui/systemtray.h
src/qtui/systrayanimationnotificationbackend.cpp
src/qtui/systrayanimationnotificationbackend.h
src/qtui/ui/systrayanimationconfigwidget.ui [new file with mode: 0644]

index d78f0f9..0a5a3ad 100644 (file)
@@ -77,10 +77,11 @@ set(FORMS
     msgprocessorstatuswidget.ui
     nicklistwidget.ui
     passwordchangedlg.ui
     msgprocessorstatuswidget.ui
     nicklistwidget.ui
     passwordchangedlg.ui
+    receivefiledlg.ui
     settingsdlg.ui
     settingspagedlg.ui
     simplenetworkeditor.ui
     settingsdlg.ui
     settingspagedlg.ui
     simplenetworkeditor.ui
-    receivefiledlg.ui
+    systrayanimationconfigwidget.ui
     topicwidget.ui
 )
 
     topicwidget.ui
 )
 
index 4f35d64..c23a83b 100644 (file)
@@ -77,7 +77,6 @@ void KNotificationBackend::notify(const Notification &n)
     _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
 
     updateToolTip();
     _notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
 
     updateToolTip();
-    QtUi::mainWindow()->systemTray()->setAlert(true);
 }
 
 
 }
 
 
@@ -101,7 +100,6 @@ void KNotificationBackend::close(uint notificationId)
 {
     removeNotificationById(notificationId);
     //if(!_notifications.count()) // FIXME make configurable
 {
     removeNotificationById(notificationId);
     //if(!_notifications.count()) // FIXME make configurable
-    QtUi::mainWindow()->systemTray()->setAlert(false);
 }
 
 
 }
 
 
index 7513bc8..0f1135a 100644 (file)
@@ -27,9 +27,7 @@
 #include "qtui.h"
 
 LegacySystemTray::LegacySystemTray(QWidget *parent)
 #include "qtui.h"
 
 LegacySystemTray::LegacySystemTray(QWidget *parent)
-    : SystemTray(parent),
-    _blinkState(false),
-    _lastMessageId(0)
+    : SystemTray(parent)
 {
 #ifndef HAVE_KDE4
     _trayIcon = new QSystemTrayIcon(associatedWidget());
 {
 #ifndef HAVE_KDE4
     _trayIcon = new QSystemTrayIcon(associatedWidget());
@@ -53,13 +51,9 @@ LegacySystemTray::LegacySystemTray(QWidget *parent)
 
     connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(onVisibilityChanged(bool)));
     connect(this, SIGNAL(modeChanged(Mode)), this, SLOT(onModeChanged(Mode)));
 
     connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(onVisibilityChanged(bool)));
     connect(this, SIGNAL(modeChanged(Mode)), this, SLOT(onModeChanged(Mode)));
-    connect(this, SIGNAL(stateChanged(State)), this, SLOT(onStateChanged(State)));
     connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(updateToolTip()));
     connect(this, SIGNAL(iconsChanged()), this, SLOT(updateIcon()));
     connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(updateToolTip()));
     connect(this, SIGNAL(iconsChanged()), this, SLOT(updateIcon()));
-
-    _blinkTimer.setInterval(750);
-    _blinkTimer.setSingleShot(false);
-    connect(&_blinkTimer, SIGNAL(timeout()), SLOT(onBlinkTimeout()));
+    connect(this, SIGNAL(currentIconNameChanged()), this, SLOT(updateIcon()));
 
     updateIcon();
     updateToolTip();
 
     updateIcon();
     updateToolTip();
@@ -93,28 +87,10 @@ void LegacySystemTray::onModeChanged(Mode mode)
 }
 
 
 }
 
 
-void LegacySystemTray::onStateChanged(State state)
-{
-    if (state == NeedsAttention && animationEnabled())
-        _blinkTimer.start();
-    else {
-        _blinkTimer.stop();
-        _blinkState = false;
-    }
-    updateIcon();
-}
-
-
 void LegacySystemTray::updateIcon()
 {
 void LegacySystemTray::updateIcon()
 {
-    QString icon;
-    if (state() == State::NeedsAttention && !_blinkState) {
-        icon = iconName(State::Active);
-    }
-    else {
-        icon = iconName(state());
-    }
-    _trayIcon->setIcon(QIcon::fromTheme(icon, QIcon{QString{":/icons/hicolor/24x24/status/%1.svg"}.arg(icon)}));
+    QString iconName = (state() == NeedsAttention) ? currentAttentionIconName() : currentIconName();
+    _trayIcon->setIcon(QIcon::fromTheme(iconName, QIcon{QString{":/icons/hicolor/24x24/status/%1.svg"}.arg(iconName)}));
 }
 
 
 }
 
 
@@ -134,13 +110,6 @@ void LegacySystemTray::updateToolTip()
 }
 
 
 }
 
 
-void LegacySystemTray::onBlinkTimeout()
-{
-    _blinkState = !_blinkState;
-    updateIcon();
-}
-
-
 void LegacySystemTray::onActivated(QSystemTrayIcon::ActivationReason reason)
 {
     activate((SystemTray::ActivationReason)reason);
 void LegacySystemTray::onActivated(QSystemTrayIcon::ActivationReason reason)
 {
     activate((SystemTray::ActivationReason)reason);
index 15134b1..e2bc338 100644 (file)
@@ -30,8 +30,6 @@
 #  include <QSystemTrayIcon>
 #endif
 
 #  include <QSystemTrayIcon>
 #endif
 
-#include <QTimer>
-
 #include "systemtray.h"
 
 class LegacySystemTray : public SystemTray
 #include "systemtray.h"
 
 class LegacySystemTray : public SystemTray
@@ -49,10 +47,8 @@ public slots:
 
 private slots:
     void onModeChanged(Mode mode);
 
 private slots:
     void onModeChanged(Mode mode);
-    void onStateChanged(State state);
     void onVisibilityChanged(bool isVisible);
 
     void onVisibilityChanged(bool isVisible);
 
-    void onBlinkTimeout();
     void onActivated(QSystemTrayIcon::ActivationReason);
     void onMessageClicked();
 
     void onActivated(QSystemTrayIcon::ActivationReason);
     void onMessageClicked();
 
@@ -60,9 +56,7 @@ private slots:
     void updateToolTip();
 
 private:
     void updateToolTip();
 
 private:
-    QTimer _blinkTimer;
-    bool _blinkState;
-    uint _lastMessageId;
+    uint _lastMessageId {0};
 
 #ifdef HAVE_KDE4
     KSystemTrayIcon *_trayIcon;
 
 #ifdef HAVE_KDE4
     KSystemTrayIcon *_trayIcon;
@@ -71,10 +65,4 @@ private:
 #endif
 };
 
 #endif
 };
 
-
-// inlines
-
-
-
-
 #endif /* QT_NO_SYSTEMTRAYICON */
 #endif /* QT_NO_SYSTEMTRAYICON */
index 68d81ab..5932746 100644 (file)
@@ -105,8 +105,9 @@ StatusNotifierItem::StatusNotifierItem(QWidget *parent)
 
     // Our own SNI service
     _statusNotifierItemDBus = new StatusNotifierItemDBus(this);
 
     // Our own SNI service
     _statusNotifierItemDBus = new StatusNotifierItemDBus(this);
+    connect(this, SIGNAL(currentIconNameChanged()), _statusNotifierItemDBus, SIGNAL(NewIcon()));
+    connect(this, SIGNAL(currentIconNameChanged()), _statusNotifierItemDBus, SIGNAL(NewAttentionIcon()));
     connect(this, SIGNAL(toolTipChanged(QString, QString)), _statusNotifierItemDBus, SIGNAL(NewToolTip()));
     connect(this, SIGNAL(toolTipChanged(QString, QString)), _statusNotifierItemDBus, SIGNAL(NewToolTip()));
-    connect(this, SIGNAL(animationEnabledChanged(bool)), _statusNotifierItemDBus, SIGNAL(NewAttentionIcon()));
 
     // Service watcher to keep track of the StatusNotifierWatcher service
     QDBusServiceWatcher *watcher = new QDBusServiceWatcher(kSniWatcherService,
 
     // Service watcher to keep track of the StatusNotifierWatcher service
     QDBusServiceWatcher *watcher = new QDBusServiceWatcher(kSniWatcherService,
@@ -252,7 +253,6 @@ void StatusNotifierItem::onModeChanged(Mode mode)
 void StatusNotifierItem::onStateChanged(State state)
 {
     if (mode() == Mode::StatusNotifier) {
 void StatusNotifierItem::onStateChanged(State state)
 {
     if (mode() == Mode::StatusNotifier) {
-        emit _statusNotifierItemDBus->NewIcon();
         emit _statusNotifierItemDBus->NewStatus(metaObject()->enumerator(metaObject()->indexOfEnumerator("State")).valueToKey(state));
     }
 }
         emit _statusNotifierItemDBus->NewStatus(metaObject()->enumerator(metaObject()->indexOfEnumerator("State")).valueToKey(state));
     }
 }
@@ -280,23 +280,13 @@ QString StatusNotifierItem::title() const
 
 QString StatusNotifierItem::iconName() const
 {
 
 QString StatusNotifierItem::iconName() const
 {
-    if (state() == Passive) {
-        return SystemTray::iconName(State::Passive);
-    }
-    else {
-        return SystemTray::iconName(State::Active);
-    }
+    return currentIconName();
 }
 
 
 QString StatusNotifierItem::attentionIconName() const
 {
 }
 
 
 QString StatusNotifierItem::attentionIconName() const
 {
-    if (animationEnabled()) {
-        return SystemTray::iconName(State::NeedsAttention);
-    }
-    else {
-        return SystemTray::iconName(State::NeedsAttention);
-    }
+    return currentAttentionIconName();
 }
 
 
 }
 
 
index 9d2078b..0e1e5c5 100644 (file)
@@ -40,7 +40,8 @@ SystemTray::SystemTray(QWidget *parent)
 {
     Q_ASSERT(parent);
 
 {
     Q_ASSERT(parent);
 
-    NotificationSettings{}.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
+    NotificationSettings{}.initAndNotify("Systray/ChangeColor", this, SLOT(enableChangeColorChanged(QVariant)), true);
+    NotificationSettings{}.initAndNotify("Systray/Animate", this, SLOT(enableBlinkChanged(QVariant)), false);
     UiStyleSettings{}.initAndNotify("Icons/InvertTray", this, SLOT(invertTrayIconChanged(QVariant)), false);
 
     ActionCollection *coll = QtUi::actionCollection("General");
     UiStyleSettings{}.initAndNotify("Icons/InvertTray", this, SLOT(invertTrayIconChanged(QVariant)), false);
 
     ActionCollection *coll = QtUi::actionCollection("General");
@@ -69,6 +70,10 @@ SystemTray::SystemTray(QWidget *parent)
     connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
 
     connect(QtUi::instance(), SIGNAL(iconThemeRefreshed()), this, SIGNAL(iconsChanged()));
     connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
 
     connect(QtUi::instance(), SIGNAL(iconThemeRefreshed()), this, SIGNAL(iconsChanged()));
+
+    _blinkTimer.setInterval(1000);
+    _blinkTimer.setSingleShot(false);
+    connect(&_blinkTimer, SIGNAL(timeout()), SLOT(onBlinkTimeout()));
 }
 
 
 }
 
 
@@ -141,6 +146,16 @@ void SystemTray::setState(State state)
     if (_state != state) {
         _state = state;
         emit stateChanged(state);
     if (_state != state) {
         _state = state;
         emit stateChanged(state);
+
+        if (state == NeedsAttention && _attentionBehavior == AttentionBehavior::Blink) {
+            _blinkTimer.start();
+            _blinkState = true;
+        }
+        else {
+            _blinkTimer.stop();
+            _blinkState = false;
+        }
+        emit currentIconNameChanged();
     }
 }
 
     }
 }
 
@@ -168,6 +183,32 @@ QString SystemTray::iconName(State state) const
 }
 
 
 }
 
 
+QString SystemTray::currentIconName() const
+{
+    if (state() == State::NeedsAttention) {
+        if (_attentionBehavior == AttentionBehavior::ChangeColor) {
+            return iconName(State::NeedsAttention);
+        }
+        if (_attentionBehavior == AttentionBehavior::Blink && _blinkState) {
+            return iconName(State::NeedsAttention);
+        }
+        return iconName(State::Active);
+    }
+    else {
+        return iconName(state());
+    }
+}
+
+
+QString SystemTray::currentAttentionIconName() const
+{
+    if (state() == State::NeedsAttention && _attentionBehavior == AttentionBehavior::Blink && !_blinkState) {
+        return iconName(State::Active);
+    }
+    return iconName(State::NeedsAttention);
+}
+
+
 bool SystemTray::isAlerted() const
 {
     return state() == State::NeedsAttention;
 bool SystemTray::isAlerted() const
 {
     return state() == State::NeedsAttention;
@@ -176,10 +217,19 @@ bool SystemTray::isAlerted() const
 
 void SystemTray::setAlert(bool alerted)
 {
 
 void SystemTray::setAlert(bool alerted)
 {
-    if (alerted)
+    if (alerted) {
         setState(NeedsAttention);
         setState(NeedsAttention);
-    else
+    }
+    else {
         setState(Client::isConnected() ? Active : Passive);
         setState(Client::isConnected() ? Active : Passive);
+    }
+}
+
+
+void SystemTray::onBlinkTimeout()
+{
+    _blinkState = !_blinkState;
+    emit currentIconNameChanged();
 }
 
 
 }
 
 
@@ -198,16 +248,31 @@ void SystemTray::trayMenuAboutToShow()
 }
 
 
 }
 
 
-bool SystemTray::animationEnabled() const
+void SystemTray::enableChangeColorChanged(const QVariant &v)
 {
 {
-    return _animationEnabled;
+    if (v.toBool()) {
+        _attentionBehavior = AttentionBehavior::ChangeColor;
+    }
+    else {
+        if (_attentionBehavior == AttentionBehavior::ChangeColor) {
+            _attentionBehavior = AttentionBehavior::DoNothing;
+        }
+    }
+    emit currentIconNameChanged();
 }
 
 
 }
 
 
-void SystemTray::enableAnimationChanged(const QVariant &v)
+void SystemTray::enableBlinkChanged(const QVariant &v)
 {
 {
-    _animationEnabled = v.toBool();
-    emit animationEnabledChanged(v.toBool());
+    if (v.toBool()) {
+        _attentionBehavior = AttentionBehavior::Blink;
+    }
+    else {
+        if (_attentionBehavior == AttentionBehavior::Blink) {
+            _attentionBehavior = AttentionBehavior::DoNothing;
+        }
+    }
+    emit currentIconNameChanged();
 }
 
 
 }
 
 
index 733a6f0..c5fee19 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QObject>
 #include <QString>
 
 #include <QObject>
 #include <QString>
+#include <QTimer>
 
 class Action;
 class QMenu;
 
 class Action;
 class QMenu;
@@ -61,6 +62,12 @@ public:
         MiddleClick
     };
 
         MiddleClick
     };
 
+    enum class AttentionBehavior {
+        DoNothing,
+        ChangeColor,
+        Blink
+    };
+
     explicit SystemTray(QWidget *parent);
     ~SystemTray() override;
 
     explicit SystemTray(QWidget *parent);
     ~SystemTray() override;
 
@@ -87,7 +94,7 @@ signals:
     void stateChanged(State state);
     void visibilityChanged(bool isVisible);
     void iconsChanged();
     void stateChanged(State state);
     void visibilityChanged(bool isVisible);
     void iconsChanged();
-    void animationEnabledChanged(bool);
+    void currentIconNameChanged();
     void toolTipChanged(const QString &title, const QString &subtitle);
 
     void activated(SystemTray::ActivationReason);
     void toolTipChanged(const QString &title, const QString &subtitle);
 
     void activated(SystemTray::ActivationReason);
@@ -99,28 +106,36 @@ protected slots:
 
 protected:
     void setMode(Mode mode);
 
 protected:
     void setMode(Mode mode);
-    bool animationEnabled() const;
 
     QString toolTipTitle() const;
     QString toolTipSubTitle() const;
     QMenu *trayMenu() const;
 
     QString iconName(State state) const;
 
     QString toolTipTitle() const;
     QString toolTipSubTitle() const;
     QMenu *trayMenu() const;
 
     QString iconName(State state) const;
+    QString currentIconName() const;
+    QString currentAttentionIconName() const;
 
 private slots:
     void minimizeRestore();
     void trayMenuAboutToShow();
 
 private slots:
     void minimizeRestore();
     void trayMenuAboutToShow();
-    void enableAnimationChanged(const QVariant &);
     void invertTrayIconChanged(const QVariant &);
     void invertTrayIconChanged(const QVariant &);
+    void enableChangeColorChanged(const QVariant &);
+    void enableBlinkChanged(const QVariant &);
+
+    void onBlinkTimeout();
 
 private:
     bool _isVisible{false};
     Mode _mode{Mode::Invalid};
     State _state{State::Passive};
 
 private:
     bool _isVisible{false};
     Mode _mode{Mode::Invalid};
     State _state{State::Passive};
-    bool _animationEnabled{true};
     bool _trayIconInverted{false};
     bool _trayIconInverted{false};
+    AttentionBehavior _attentionBehavior{AttentionBehavior::ChangeColor};
+
+    QTimer _blinkTimer;
+    bool _blinkState{false};
 
 
-    QString _toolTipTitle, _toolTipSubTitle;
+    QString _toolTipTitle;
+    QString _toolTipSubTitle;
 
     QMenu *_trayMenu{nullptr};
     QWidget *_associatedWidget{nullptr};
 
     QMenu *_trayMenu{nullptr};
     QWidget *_associatedWidget{nullptr};
index 65cc38b..4af9109 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#include <QApplication>
-#include <QCheckBox>
-#include <QGroupBox>
 #include <QIcon>
 #include <QIcon>
-#include <QHBoxLayout>
 
 #include "systrayanimationnotificationbackend.h"
 
 
 #include "systrayanimationnotificationbackend.h"
 
-#include "client.h"
 #include "clientsettings.h"
 #include "mainwin.h"
 #include "clientsettings.h"
 #include "mainwin.h"
-#include "networkmodel.h"
 #include "qtui.h"
 #include "systemtray.h"
 
 #include "qtui.h"
 #include "systemtray.h"
 
@@ -37,7 +31,7 @@ SystrayAnimationNotificationBackend::SystrayAnimationNotificationBackend(QObject
     : AbstractNotificationBackend(parent)
 {
     NotificationSettings notificationSettings;
     : AbstractNotificationBackend(parent)
 {
     NotificationSettings notificationSettings;
-    notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
+    notificationSettings.initAndNotify("Systray/Alert", this, SLOT(alertChanged(QVariant)), true);
 }
 
 
 }
 
 
@@ -46,20 +40,21 @@ void SystrayAnimationNotificationBackend::notify(const Notification &n)
     if (n.type != Highlight && n.type != PrivMsg)
         return;
 
     if (n.type != Highlight && n.type != PrivMsg)
         return;
 
-    if (_animate)
+    if (_alert)
         QtUi::mainWindow()->systemTray()->setAlert(true);
 }
 
 
 void SystrayAnimationNotificationBackend::close(uint notificationId)
 {
         QtUi::mainWindow()->systemTray()->setAlert(true);
 }
 
 
 void SystrayAnimationNotificationBackend::close(uint notificationId)
 {
+    Q_UNUSED(notificationId)
     QtUi::mainWindow()->systemTray()->setAlert(false);
 }
 
 
     QtUi::mainWindow()->systemTray()->setAlert(false);
 }
 
 
-void SystrayAnimationNotificationBackend::animateChanged(const QVariant &v)
+void SystrayAnimationNotificationBackend::alertChanged(const QVariant &v)
 {
 {
-    _animate = v.toBool();
+    _alert = v.toBool();
 }
 
 
 }
 
 
@@ -71,49 +66,57 @@ SettingsPage *SystrayAnimationNotificationBackend::createConfigWidget() const
 
 /***************************************************************************/
 
 
 /***************************************************************************/
 
-SystrayAnimationNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayNotification", parent)
+SystrayAnimationNotificationBackend::ConfigWidget::ConfigWidget(QWidget *parent) : SettingsPage("Internal", "SystrayAnimation", parent)
 {
 {
-    _animateBox = new QCheckBox(tr("Animate system tray icon"));
-    _animateBox->setIcon(QIcon::fromTheme("dialog-information"));
-    connect(_animateBox, SIGNAL(toggled(bool)), this, SLOT(widgetChanged()));
-    QHBoxLayout *layout = new QHBoxLayout(this);
-    layout->addWidget(_animateBox);
-}
+    ui.setupUi(this);
+    ui.enableAlert->setIcon(QIcon::fromTheme("dialog-information"));
 
 
+    ui.attentionBehavior->setEnabled(ui.enableAlert->isChecked());
 
 
-void SystrayAnimationNotificationBackend::ConfigWidget::widgetChanged()
-{
-    bool changed = (_animate != _animateBox->isChecked());
-    if (changed != hasChanged())
-        setChangedState(changed);
+    initAutoWidgets();
 }
 
 
 }
 
 
-bool SystrayAnimationNotificationBackend::ConfigWidget::hasDefaults() const
+QString SystrayAnimationNotificationBackend::ConfigWidget::settingsKey() const
 {
 {
-    return true;
+    return "Notification";
 }
 
 
 }
 
 
-void SystrayAnimationNotificationBackend::ConfigWidget::defaults()
+QVariant SystrayAnimationNotificationBackend::ConfigWidget::loadAutoWidgetValue(const QString &widgetName)
 {
 {
-    _animateBox->setChecked(false);
-    widgetChanged();
+    if (widgetName == "attentionBehavior") {
+        NotificationSettings s;
+        if (s.value("Systray/Animate", false).toBool()) {
+            return 2;
+        }
+        if (s.value("Systray/ChangeColor", true).toBool()) {
+            return 1;
+        }
+        return 0;
+    }
+
+    return SettingsPage::loadAutoWidgetValue(widgetName);
 }
 
 
 }
 
 
-void SystrayAnimationNotificationBackend::ConfigWidget::load()
+void SystrayAnimationNotificationBackend::ConfigWidget::saveAutoWidgetValue(const QString &widgetName, const QVariant &value)
 {
 {
-    NotificationSettings s;
-    _animate = s.value("Systray/Animate", true).toBool();
-    _animateBox->setChecked(_animate);
-    setChangedState(false);
+    if (widgetName == "attentionBehavior") {
+        NotificationSettings s;
+        s.setValue("Systray/ChangeColor", false);
+        s.setValue("Systray/Animate", false);
+        switch (value.toInt()) {
+        case 1:
+            s.setValue("Systray/ChangeColor", true);
+            return;
+        case 2:
+            s.setValue("Systray/Animate", true);
+            return;
+        default:
+            return;
+        }
+    }
+
+    SettingsPage::saveAutoWidgetValue(widgetName, value);
 }
 }
-
-
-void SystrayAnimationNotificationBackend::ConfigWidget::save()
-{
-    NotificationSettings s;
-    s.setValue("Systray/Animate", _animateBox->isChecked());
-    load();
-}
\ No newline at end of file
index cbe934d..c9155e7 100644 (file)
@@ -22,7 +22,8 @@
 
 #include "abstractnotificationbackend.h"
 #include "settingspage.h"
 
 #include "abstractnotificationbackend.h"
 #include "settingspage.h"
-#include "systemtray.h"
+
+#include "ui_systrayanimationconfigwidget.h"
 
 class QCheckBox;
 
 
 class QCheckBox;
 
@@ -31,18 +32,18 @@ class SystrayAnimationNotificationBackend : public AbstractNotificationBackend
     Q_OBJECT
 
 public:
     Q_OBJECT
 
 public:
-    SystrayAnimationNotificationBackend(QObject *parent = 0);
+    SystrayAnimationNotificationBackend(QObject *parent = nullptr);
 
 
-    void notify(const Notification &);
-    void close(uint notificationId);
-    virtual SettingsPage *createConfigWidget() const;
+    void notify(const Notification &) override;
+    void close(uint notificationId) override;
+    virtual SettingsPage *createConfigWidget() const override;
 
 private slots:
 
 private slots:
-    void animateChanged(const QVariant &);
+    void alertChanged(const QVariant &);
 
 private:
 
 private:
+    bool _alert{false};
     class ConfigWidget;
     class ConfigWidget;
-    bool _animate;
 };
 
 
 };
 
 
@@ -51,16 +52,13 @@ class SystrayAnimationNotificationBackend::ConfigWidget : public SettingsPage
     Q_OBJECT
 
 public:
     Q_OBJECT
 
 public:
-    ConfigWidget(QWidget *parent = 0);
-    void save();
-    void load();
-    bool hasDefaults() const;
-    void defaults();
+    ConfigWidget(QWidget *parent = nullptr);
+    QString settingsKey() const override;
 
 
-private slots:
-    void widgetChanged();
+private:
+    QVariant loadAutoWidgetValue(const QString &widgetName) override;
+    void saveAutoWidgetValue(const QString &widgetName, const QVariant &value) override;
 
 private:
 
 private:
-    QCheckBox *_animateBox;
-    bool _animate;
-};
\ No newline at end of file
+    Ui::SystrayAnimationConfigWidget ui;
+};
diff --git a/src/qtui/ui/systrayanimationconfigwidget.ui b/src/qtui/ui/systrayanimationconfigwidget.ui
new file mode 100644 (file)
index 0000000..9736a47
--- /dev/null
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SystrayAnimationConfigWidget</class>
+ <widget class="QWidget" name="SystrayAnimationConfigWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>438</width>
+    <height>50</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QCheckBox" name="enableAlert">
+       <property name="toolTip">
+        <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If enabled, alert the system tray or dock in case of a notification.&lt;/p&gt;&lt;p&gt;It depends on your desktop environment how an alert is visualized. For example, Plasma will pulsate the tray icon, while Windows will change the icon's color. You may choose to forcefully change color or even letting the icon blink, if desired.&lt;/p&gt;&lt;p&gt;Note that not all icon themes support changing the color of the tray icon.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+       </property>
+       <property name="text">
+        <string>Alert tray icon and</string>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string notr="true">Systray/Alert</string>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="attentionBehavior">
+       <property name="currentIndex">
+        <number>1</number>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string notr="true"/>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <number>1</number>
+       </property>
+       <item>
+        <property name="text">
+         <string>do nothing</string>
+        </property>
+       </item>
+       <item>
+        <property name="text">
+         <string>change color</string>
+        </property>
+       </item>
+       <item>
+        <property name="text">
+         <string>blink</string>
+        </property>
+       </item>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>enableAlert</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>attentionBehavior</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>121</x>
+     <y>26</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>257</x>
+     <y>28</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>