/***************************************************************************
- * Copyright (C) 2005-2012 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 *
* 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., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef QT_NO_SYSTEMTRAYICON
+#include <QIcon>
+
#include "legacysystemtray.h"
#include "mainwin.h"
#include "qtui.h"
_blinkState(false),
_lastMessageId(0)
{
-#ifndef HAVE_KDE
+#ifndef HAVE_KDE4
_trayIcon = new QSystemTrayIcon(associatedWidget());
#else
_trayIcon = new KSystemTrayIcon(associatedWidget());
disconnect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
_trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason)));
#endif
-#ifndef Q_WS_MAC
+#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()));
+ SLOT(onMessageClicked()));
- connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(syncLegacyIcon()));
-}
+ _trayIcon->setContextMenu(trayMenu());
+ _trayIcon->setVisible(false);
+ setMode(Mode::Legacy);
-void LegacySystemTray::init()
-{
- if (mode() == Invalid) // derived class hasn't set a mode itself
- setMode(Legacy);
+ 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()));
- SystemTray::init();
+ _blinkTimer.setInterval(750);
+ _blinkTimer.setSingleShot(false);
+ connect(&_blinkTimer, SIGNAL(timeout()), SLOT(onBlinkTimeout()));
- _trayIcon->setContextMenu(trayMenu());
+ updateIcon();
+ updateToolTip();
}
-void LegacySystemTray::syncLegacyIcon()
+bool LegacySystemTray::isSystemTrayAvailable() const
{
- _trayIcon->setIcon(stateIcon());
-
-#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("<b>%1</b>").arg(toolTipTitle());
- if (!toolTipSubTitle().isEmpty())
- tooltip += QString("<br>%1").arg(toolTipSubTitle());
-#endif
-
- _trayIcon->setToolTip(tooltip);
+ return mode() == Mode::Legacy
+ ? QSystemTrayIcon::isSystemTrayAvailable()
+ : SystemTray::isSystemTrayAvailable();
}
-void LegacySystemTray::setVisible(bool visible)
+void LegacySystemTray::onVisibilityChanged(bool isVisible)
{
- SystemTray::setVisible(visible);
if (mode() == Legacy) {
- if (shouldBeVisible())
- _trayIcon->show();
- else
- _trayIcon->hide();
+ _trayIcon->setVisible(isVisible);
}
}
-bool LegacySystemTray::isVisible() const
+void LegacySystemTray::onModeChanged(Mode mode)
{
- if (mode() == Legacy) {
- return _trayIcon->isVisible();
+ if (mode == Mode::Legacy) {
+ _trayIcon->setVisible(isVisible());
+ }
+ else {
+ _trayIcon->hide();
}
- return SystemTray::isVisible();
}
-void LegacySystemTray::setMode(Mode mode_)
+void LegacySystemTray::onStateChanged(State state)
{
- if (mode_ == mode())
- return;
-
- SystemTray::setMode(mode_);
-
- if (mode() == Legacy) {
- syncLegacyIcon();
- if (shouldBeVisible())
- _trayIcon->show();
- else
- _trayIcon->hide();
- if (state() == NeedsAttention)
- _blinkTimer.start();
- }
+ if (state == NeedsAttention && animationEnabled())
+ _blinkTimer.start();
else {
- _trayIcon->hide();
_blinkTimer.stop();
+ _blinkState = false;
}
+ updateIcon();
}
-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;
- }
+ QString icon;
+ if (state() == State::NeedsAttention && !_blinkState) {
+ icon = iconName(State::Active);
+ }
+ else {
+ icon = iconName(state());
}
- if (mode() == Legacy)
- _trayIcon->setIcon(stateIcon());
+ _trayIcon->setIcon(QIcon::fromTheme(icon, QIcon{QString{":/icons/hicolor/24x24/status/%1.svg"}.arg(icon)}));
}
-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("<b>%1</b>").arg(toolTipTitle());
+ if (!toolTipSubTitle().isEmpty())
+ tooltip += QString("<br>%1").arg(toolTipSubTitle());
+#endif
+
+ _trayIcon->setToolTip(tooltip);
}
-void LegacySystemTray::on_blinkTimeout()
+void LegacySystemTray::onBlinkTimeout()
{
_blinkState = !_blinkState;
- _trayIcon->setIcon(stateIcon());
+ updateIcon();
}
-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);
}