1 /***************************************************************************
2 * Copyright (C) 2005-2013 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef QT_NO_SYSTEMTRAYICON
23 #include "legacysystemtray.h"
27 LegacySystemTray::LegacySystemTray(QWidget *parent)
33 _trayIcon = new QSystemTrayIcon(associatedWidget());
35 _trayIcon = new KSystemTrayIcon(associatedWidget());
36 // We don't want to trigger a minimize if a highlight is pending, so we brutally remove the internal connection for that
37 disconnect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
38 _trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason)));
41 connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
42 SLOT(on_activated(QSystemTrayIcon::ActivationReason)));
44 connect(_trayIcon, SIGNAL(messageClicked()),
45 SLOT(on_messageClicked()));
47 _blinkTimer.setInterval(500);
48 _blinkTimer.setSingleShot(false);
49 connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout()));
51 connect(this, SIGNAL(toolTipChanged(QString, QString)), SLOT(syncLegacyIcon()));
55 void LegacySystemTray::init()
57 if (mode() == Invalid) // derived class hasn't set a mode itself
62 _trayIcon->setContextMenu(trayMenu());
66 void LegacySystemTray::syncLegacyIcon()
68 _trayIcon->setIcon(stateIcon());
70 #if defined Q_WS_MAC || defined Q_WS_WIN
71 QString tooltip = QString("%1").arg(toolTipTitle());
72 if (!toolTipSubTitle().isEmpty())
73 tooltip += QString("\n%1").arg(toolTipSubTitle());
75 QString tooltip = QString("<b>%1</b>").arg(toolTipTitle());
76 if (!toolTipSubTitle().isEmpty())
77 tooltip += QString("<br>%1").arg(toolTipSubTitle());
80 _trayIcon->setToolTip(tooltip);
84 void LegacySystemTray::setVisible(bool visible)
86 SystemTray::setVisible(visible);
87 if (mode() == Legacy) {
88 if (shouldBeVisible())
96 bool LegacySystemTray::isVisible() const
98 if (mode() == Legacy) {
99 return _trayIcon->isVisible();
101 return SystemTray::isVisible();
105 void LegacySystemTray::setMode(Mode mode_)
110 SystemTray::setMode(mode_);
112 if (mode() == Legacy) {
114 if (shouldBeVisible())
118 if (state() == NeedsAttention)
128 void LegacySystemTray::setState(State state_)
130 State oldstate = state();
131 SystemTray::setState(state_);
132 if (oldstate != state()) {
133 if (state() == NeedsAttention && mode() == Legacy && animationEnabled())
140 if (mode() == Legacy)
141 _trayIcon->setIcon(stateIcon());
145 Icon LegacySystemTray::stateIcon() const
147 if (mode() == Legacy && state() == NeedsAttention && !_blinkState)
148 return SystemTray::stateIcon(Active);
149 return SystemTray::stateIcon();
153 void LegacySystemTray::on_blinkTimeout()
155 _blinkState = !_blinkState;
156 _trayIcon->setIcon(stateIcon());
160 void LegacySystemTray::on_activated(QSystemTrayIcon::ActivationReason reason)
162 activate((SystemTray::ActivationReason)reason);
166 void LegacySystemTray::on_messageClicked()
168 emit messageClicked(_lastMessageId);
172 void LegacySystemTray::showMessage(const QString &title, const QString &message, SystemTray::MessageIcon icon, int msTimeout, uint id)
174 // fancy stuff later: show messages in order
175 // for now, we just show the last message
177 _trayIcon->showMessage(title, message, (QSystemTrayIcon::MessageIcon)icon, msTimeout);
181 void LegacySystemTray::closeMessage(uint notificationId)
183 Q_UNUSED(notificationId)
185 // there really seems to be no sane way to close the bubble... :(
187 showMessage("", "", NoIcon, 1);
192 #endif /* QT_NO_SYSTEMTRAYICON */