X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Flegacysystemtray.cpp;h=3fbe1dcac2129556ac91b31315e12a866591dd71;hb=61f33c7895e324f6e95034d86897ad2e963653f1;hp=a3e706aa175c02ac4a4ba4d14d684cdf6b89a288;hpb=4a5065255e652dd0c301bac0db41b7afb777ef49;p=quassel.git
diff --git a/src/qtui/legacysystemtray.cpp b/src/qtui/legacysystemtray.cpp
index a3e706aa..3fbe1dca 100644
--- a/src/qtui/legacysystemtray.cpp
+++ b/src/qtui/legacysystemtray.cpp
@@ -1,11 +1,11 @@
/***************************************************************************
- * Copyright (C) 2005-2013 by the Quassel Project *
+ * Copyright (C) 2005-2018 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 file is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Library General Public License (LGPL) *
+ * as published by the Free Software Foundation; either version 2 of the *
+ * License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
@@ -21,149 +21,96 @@
#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)
+ , _trayIcon{new QSystemTrayIcon(associatedWidget())}
{
-#ifndef HAVE_KDE
- _trayIcon = new QSystemTrayIcon(associatedWidget());
-#else
- _trayIcon = new KSystemTrayIcon(associatedWidget());
- // We don't want to trigger a minimize if a highlight is pending, so we brutally remove the internal connection for that
- disconnect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
- _trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason)));
-#endif
-#ifndef Q_WS_MAC
- connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
- SLOT(on_activated(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();
+#ifndef Q_OS_MAC
+ connect(_trayIcon, &QSystemTrayIcon::activated,
+ this, &LegacySystemTray::onActivated);
+#endif
+ connect(_trayIcon, &QSystemTrayIcon::messageClicked,
+ this, &LegacySystemTray::onMessageClicked);
_trayIcon->setContextMenu(trayMenu());
-}
+ _trayIcon->setVisible(false);
+ setMode(Mode::Legacy);
-void LegacySystemTray::syncLegacyIcon()
-{
- _trayIcon->setIcon(stateIcon());
+ connect(this, &SystemTray::visibilityChanged, this, &LegacySystemTray::onVisibilityChanged);
+ connect(this, &SystemTray::modeChanged, this, &LegacySystemTray::onModeChanged);
+ connect(this, &SystemTray::toolTipChanged, this, &LegacySystemTray::updateToolTip);
+ connect(this, &SystemTray::iconsChanged, this, &LegacySystemTray::updateIcon);
+ connect(this, &SystemTray::currentIconNameChanged, this, &LegacySystemTray::updateIcon);
-#if defined Q_WS_MAC || defined Q_WS_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_)
+void LegacySystemTray::updateIcon()
{
- State oldstate = state();
- SystemTray::setState(state_);
- if (oldstate != state()) {
- if (state() == NeedsAttention && mode() == Legacy && animationEnabled())
- _blinkTimer.start();
- else {
- _blinkTimer.stop();
- _blinkState = false;
- }
- }
- if (mode() == Legacy)
- _trayIcon->setIcon(stateIcon());
+ QString iconName = (state() == NeedsAttention) ? currentAttentionIconName() : currentIconName();
+ _trayIcon->setIcon(icon::get(iconName, QString{":/icons/hicolor/24x24/status/%1.svg"}.arg(iconName)));
}
-Icon LegacySystemTray::stateIcon() const
+void LegacySystemTray::updateToolTip()
{
- if (mode() == Legacy && state() == NeedsAttention && !_blinkState)
- return SystemTray::stateIcon(Active);
- return SystemTray::stateIcon();
-}
-
+#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
-void LegacySystemTray::on_blinkTimeout()
-{
- _blinkState = !_blinkState;
- _trayIcon->setIcon(stateIcon());
+ _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);
}