X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Flegacysystemtray.cpp;h=40cd2ed8f756fd6567420f9f440896675263b074;hp=9308798e923671f868c8172e25cbb6b510963036;hb=c27d5bfbe80bfeb583a25404f4ccee4b70b010e0;hpb=1a9450ecc5eeb5f987ceac790be84dcced02f028 diff --git a/src/qtui/legacysystemtray.cpp b/src/qtui/legacysystemtray.cpp index 9308798e..40cd2ed8 100644 --- a/src/qtui/legacysystemtray.cpp +++ b/src/qtui/legacysystemtray.cpp @@ -21,13 +21,13 @@ #ifndef QT_NO_SYSTEMTRAYICON #include "legacysystemtray.h" + +#include "icon.h" #include "mainwin.h" #include "qtui.h" LegacySystemTray::LegacySystemTray(QWidget *parent) - : SystemTray(parent), - _blinkState(false), - _lastMessageId(0) + : SystemTray(parent) { #ifndef HAVE_KDE4 _trayIcon = new QSystemTrayIcon(associatedWidget()); @@ -39,133 +39,84 @@ LegacySystemTray::LegacySystemTray(QWidget *parent) #endif #ifndef Q_OS_MAC connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - SLOT(on_activated(QSystemTrayIcon::ActivationReason))); + SLOT(onActivated(QSystemTrayIcon::ActivationReason))); #endif connect(_trayIcon, SIGNAL(messageClicked()), - SLOT(on_messageClicked())); - - _blinkTimer.setInterval(500); - _blinkTimer.setSingleShot(false); - connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout())); - - connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(syncLegacyIcon())); -} - - -void LegacySystemTray::init() -{ - if (mode() == Invalid) // derived class hasn't set a mode itself - setMode(Legacy); - - SystemTray::init(); + SLOT(onMessageClicked())); _trayIcon->setContextMenu(trayMenu()); -} + _trayIcon->setVisible(false); + setMode(Mode::Legacy); -void LegacySystemTray::syncLegacyIcon() -{ - updateIcon(); + connect(this, SIGNAL(visibilityChanged(bool)), this, SLOT(onVisibilityChanged(bool))); + connect(this, SIGNAL(modeChanged(Mode)), this, SLOT(onModeChanged(Mode))); + connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(updateToolTip())); + connect(this, SIGNAL(iconsChanged()), this, SLOT(updateIcon())); + connect(this, SIGNAL(currentIconNameChanged()), this, SLOT(updateIcon())); -#if defined Q_OS_MAC || defined Q_OS_WIN - QString tooltip = QString("%1").arg(toolTipTitle()); - if (!toolTipSubTitle().isEmpty()) - tooltip += QString("\n%1").arg(toolTipSubTitle()); -#else - QString tooltip = QString("%1").arg(toolTipTitle()); - if (!toolTipSubTitle().isEmpty()) - tooltip += QString("
%1").arg(toolTipSubTitle()); -#endif - - _trayIcon->setToolTip(tooltip); + updateIcon(); + updateToolTip(); } -void LegacySystemTray::setVisible(bool visible) +bool LegacySystemTray::isSystemTrayAvailable() const { - SystemTray::setVisible(visible); - if (mode() == Legacy) { - if (shouldBeVisible()) - _trayIcon->show(); - else - _trayIcon->hide(); - } + return mode() == Mode::Legacy + ? QSystemTrayIcon::isSystemTrayAvailable() + : SystemTray::isSystemTrayAvailable(); } -bool LegacySystemTray::isVisible() const +void LegacySystemTray::onVisibilityChanged(bool isVisible) { if (mode() == Legacy) { - return _trayIcon->isVisible(); + _trayIcon->setVisible(isVisible); } - return SystemTray::isVisible(); } -void LegacySystemTray::setMode(Mode mode_) +void LegacySystemTray::onModeChanged(Mode mode) { - if (mode_ == mode()) - return; - - SystemTray::setMode(mode_); - - if (mode() == Legacy) { - syncLegacyIcon(); - if (shouldBeVisible()) - _trayIcon->show(); - else - _trayIcon->hide(); - if (state() == NeedsAttention) - _blinkTimer.start(); + if (mode == Mode::Legacy) { + _trayIcon->setVisible(isVisible()); } else { _trayIcon->hide(); - _blinkTimer.stop(); - } -} - - -void LegacySystemTray::setState(State state_) -{ - State oldstate = state(); - SystemTray::setState(state_); - if (oldstate != state()) { - if (state() == NeedsAttention && mode() == Legacy && animationEnabled()) - _blinkTimer.start(); - else { - _blinkTimer.stop(); - _blinkState = false; - } } - updateIcon(); } void LegacySystemTray::updateIcon() { - if (state() == State::NeedsAttention && !_blinkState) { - _trayIcon->setIcon(QIcon::fromTheme(iconName(State::Active))); - } - else { - _trayIcon->setIcon(QIcon::fromTheme(iconName(state()))); - } + QString iconName = (state() == NeedsAttention) ? currentAttentionIconName() : currentIconName(); + _trayIcon->setIcon(icon::get(iconName, QString{":/icons/hicolor/24x24/status/%1.svg"}.arg(iconName))); } -void LegacySystemTray::on_blinkTimeout() +void LegacySystemTray::updateToolTip() { - _blinkState = !_blinkState; - updateIcon(); +#if defined Q_OS_MAC || defined Q_OS_WIN + QString tooltip = QString("%1").arg(toolTipTitle()); + if (!toolTipSubTitle().isEmpty()) + tooltip += QString("\n%1").arg(toolTipSubTitle()); +#else + QString tooltip = QString("%1").arg(toolTipTitle()); + if (!toolTipSubTitle().isEmpty()) + tooltip += QString("
%1").arg(toolTipSubTitle()); +#endif + + _trayIcon->setToolTip(tooltip); } -void LegacySystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) +void LegacySystemTray::onActivated(QSystemTrayIcon::ActivationReason reason) { activate((SystemTray::ActivationReason)reason); } -void LegacySystemTray::on_messageClicked() +void LegacySystemTray::onMessageClicked() { emit messageClicked(_lastMessageId); }