1 /***************************************************************************
2 * Copyright (C) 2005-2010 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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef QT_NO_SYSTEMTRAYICON
23 #include "legacysystemtray.h"
27 LegacySystemTray::LegacySystemTray(QWidget *parent)
34 _trayIcon = new QSystemTrayIcon(associatedWidget());
36 _trayIcon = new KSystemTrayIcon(associatedWidget());
37 // We don't want to trigger a minimize if a highlight is pending, so we brutally remove the internal connection for that
38 disconnect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
39 _trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason)));
42 connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
43 SLOT(on_activated(QSystemTrayIcon::ActivationReason)));
45 connect(_trayIcon, SIGNAL(messageClicked()),
46 SLOT(on_messageClicked()));
48 _blinkTimer.setInterval(500);
49 _blinkTimer.setSingleShot(false);
50 connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout()));
52 connect(this, SIGNAL(toolTipChanged(QString,QString)), SLOT(syncLegacyIcon()));
55 void LegacySystemTray::init() {
56 if(mode() == Invalid) // derived class hasn't set a mode itself
61 _trayIcon->setContextMenu(trayMenu());
64 void LegacySystemTray::syncLegacyIcon() {
65 _trayIcon->setIcon(stateIcon());
67 #if defined Q_WS_MAC || defined Q_WS_WIN
68 QString tooltip = QString("%1").arg(toolTipTitle());
69 if(!toolTipSubTitle().isEmpty())
70 tooltip += QString("\n%1").arg(toolTipSubTitle());
72 QString tooltip = QString("<b>%1</b>").arg(toolTipTitle());
73 if(!toolTipSubTitle().isEmpty())
74 tooltip += QString("<br>%1").arg(toolTipSubTitle());
77 _trayIcon->setToolTip(tooltip);
80 void LegacySystemTray::setVisible(bool visible) {
82 if(mode() == Legacy) {
90 bool LegacySystemTray::isVisible() const {
91 if(mode() == Legacy) {
92 return _trayIcon->isVisible();
97 void LegacySystemTray::setMode(Mode mode_) {
98 SystemTray::setMode(mode_);
100 if(mode() == Legacy) {
104 if(state() == NeedsAttention)
112 void LegacySystemTray::setState(State state_) {
113 State oldstate = state();
114 SystemTray::setState(state_);
115 if(oldstate != state()) {
116 if(state() == NeedsAttention && mode() == Legacy && animationEnabled())
124 _trayIcon->setIcon(stateIcon());
127 Icon LegacySystemTray::stateIcon() const {
128 if(mode() == Legacy && state() == NeedsAttention && !_blinkState)
129 return SystemTray::stateIcon(Active);
130 return SystemTray::stateIcon();
133 void LegacySystemTray::on_blinkTimeout() {
134 _blinkState = !_blinkState;
135 _trayIcon->setIcon(stateIcon());
138 void LegacySystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) {
139 activate((SystemTray::ActivationReason)reason);
142 void LegacySystemTray::on_messageClicked() {
143 emit messageClicked(_lastMessageId);
146 void LegacySystemTray::showMessage(const QString &title, const QString &message, SystemTray::MessageIcon icon, int msTimeout, uint id) {
147 // fancy stuff later: show messages in order
148 // for now, we just show the last message
150 _trayIcon->showMessage(title, message, (QSystemTrayIcon::MessageIcon)icon, msTimeout);
153 void LegacySystemTray::closeMessage(uint notificationId) {
154 Q_UNUSED(notificationId)
156 // there really seems to be no sane way to close the bubble... :(
158 showMessage("", "", NoIcon, 1);
162 #endif /* QT_NO_SYSTEMTRAYICON */