msgprocessorstatuswidget.ui
nicklistwidget.ui
passwordchangedlg.ui
+ receivefiledlg.ui
settingsdlg.ui
settingspagedlg.ui
simplenetworkeditor.ui
- receivefiledlg.ui
+ systrayanimationconfigwidget.ui
topicwidget.ui
)
_notifications.append(qMakePair(n.notificationId, QPointer<KNotification>(notification)));
updateToolTip();
- QtUi::mainWindow()->systemTray()->setAlert(true);
}
{
removeNotificationById(notificationId);
//if(!_notifications.count()) // FIXME make configurable
- QtUi::mainWindow()->systemTray()->setAlert(false);
}
#include "qtui.h"
LegacySystemTray::LegacySystemTray(QWidget *parent)
- : SystemTray(parent),
- _blinkState(false),
- _lastMessageId(0)
+ : SystemTray(parent)
{
#ifndef HAVE_KDE4
_trayIcon = new QSystemTrayIcon(associatedWidget());
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()));
-
- _blinkTimer.setInterval(750);
- _blinkTimer.setSingleShot(false);
- connect(&_blinkTimer, SIGNAL(timeout()), SLOT(onBlinkTimeout()));
+ connect(this, SIGNAL(currentIconNameChanged()), this, SLOT(updateIcon()));
updateIcon();
updateToolTip();
}
-void LegacySystemTray::onStateChanged(State state)
-{
- if (state == NeedsAttention && animationEnabled())
- _blinkTimer.start();
- else {
- _blinkTimer.stop();
- _blinkState = false;
- }
- 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)}));
}
}
-void LegacySystemTray::onBlinkTimeout()
-{
- _blinkState = !_blinkState;
- updateIcon();
-}
-
-
void LegacySystemTray::onActivated(QSystemTrayIcon::ActivationReason reason)
{
activate((SystemTray::ActivationReason)reason);
# include <QSystemTrayIcon>
#endif
-#include <QTimer>
-
#include "systemtray.h"
class LegacySystemTray : public SystemTray
private slots:
void onModeChanged(Mode mode);
- void onStateChanged(State state);
void onVisibilityChanged(bool isVisible);
- void onBlinkTimeout();
void onActivated(QSystemTrayIcon::ActivationReason);
void onMessageClicked();
void updateToolTip();
private:
- QTimer _blinkTimer;
- bool _blinkState;
- uint _lastMessageId;
+ uint _lastMessageId {0};
#ifdef HAVE_KDE4
KSystemTrayIcon *_trayIcon;
#endif
};
-
-// inlines
-
-
-
-
#endif /* QT_NO_SYSTEMTRAYICON */
// 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(animationEnabledChanged(bool)), _statusNotifierItemDBus, SIGNAL(NewAttentionIcon()));
// Service watcher to keep track of the StatusNotifierWatcher service
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(kSniWatcherService,
void StatusNotifierItem::onStateChanged(State state)
{
if (mode() == Mode::StatusNotifier) {
- emit _statusNotifierItemDBus->NewIcon();
emit _statusNotifierItemDBus->NewStatus(metaObject()->enumerator(metaObject()->indexOfEnumerator("State")).valueToKey(state));
}
}
QString StatusNotifierItem::iconName() const
{
- if (state() == Passive) {
- return SystemTray::iconName(State::Passive);
- }
- else {
- return SystemTray::iconName(State::Active);
- }
+ return currentIconName();
}
QString StatusNotifierItem::attentionIconName() const
{
- if (animationEnabled()) {
- return SystemTray::iconName(State::NeedsAttention);
- }
- else {
- return SystemTray::iconName(State::NeedsAttention);
- }
+ return currentAttentionIconName();
}
{
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");
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()));
}
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();
}
}
}
+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;
void SystemTray::setAlert(bool alerted)
{
- if (alerted)
+ if (alerted) {
setState(NeedsAttention);
- else
+ }
+ else {
setState(Client::isConnected() ? Active : Passive);
+ }
+}
+
+
+void SystemTray::onBlinkTimeout()
+{
+ _blinkState = !_blinkState;
+ emit currentIconNameChanged();
}
}
-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();
}
#include <QObject>
#include <QString>
+#include <QTimer>
class Action;
class QMenu;
MiddleClick
};
+ enum class AttentionBehavior {
+ DoNothing,
+ ChangeColor,
+ Blink
+ };
+
explicit SystemTray(QWidget *parent);
~SystemTray() override;
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);
protected:
void setMode(Mode mode);
- bool animationEnabled() 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();
- void enableAnimationChanged(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};
- bool _animationEnabled{true};
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};
* 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"
: AbstractNotificationBackend(parent)
{
NotificationSettings notificationSettings;
- notificationSettings.initAndNotify("Systray/Animate", this, SLOT(animateChanged(QVariant)), true);
+ notificationSettings.initAndNotify("Systray/Alert", this, SLOT(alertChanged(QVariant)), true);
}
if (n.type != Highlight && n.type != PrivMsg)
return;
- if (_animate)
+ if (_alert)
QtUi::mainWindow()->systemTray()->setAlert(true);
}
void SystrayAnimationNotificationBackend::close(uint notificationId)
{
+ Q_UNUSED(notificationId)
QtUi::mainWindow()->systemTray()->setAlert(false);
}
-void SystrayAnimationNotificationBackend::animateChanged(const QVariant &v)
+void SystrayAnimationNotificationBackend::alertChanged(const QVariant &v)
{
- _animate = v.toBool();
+ _alert = v.toBool();
}
/***************************************************************************/
-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
#include "abstractnotificationbackend.h"
#include "settingspage.h"
-#include "systemtray.h"
+
+#include "ui_systrayanimationconfigwidget.h"
class QCheckBox;
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:
- void animateChanged(const QVariant &);
+ void alertChanged(const QVariant &);
private:
+ bool _alert{false};
class ConfigWidget;
- bool _animate;
};
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:
- QCheckBox *_animateBox;
- bool _animate;
-};
\ No newline at end of file
+ Ui::SystrayAnimationConfigWidget ui;
+};
--- /dev/null
+<?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><html><head/><body><p>If enabled, alert the system tray or dock in case of a notification.</p><p>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.</p><p>Note that not all icon themes support changing the color of the tray icon.</p></body></html></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>