1 /***************************************************************************
2 * Copyright (C) 2005-09 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 ***************************************************************************/
23 #include "systemtray.h"
25 #include "actioncollection.h"
26 #include "iconloader.h"
28 #include "qtuisettings.h"
30 SystemTray::SystemTray(QObject *parent)
37 _currentIdx = _idxOffEnd;
38 _trayIcon = new QSystemTrayIcon(_phases.at(_currentIdx), this);
40 _animationTimer.setInterval(150);
41 _animationTimer.setSingleShot(false);
42 connect(&_animationTimer, SIGNAL(timeout()), SLOT(nextPhase()));
44 ActionCollection *coll = QtUi::actionCollection("General");
45 _trayMenu = new QMenu();
46 _trayMenu->addAction(coll->action("ConnectCore"));
47 _trayMenu->addAction(coll->action("DisconnectCore"));
48 _trayMenu->addAction(coll->action("CoreInfo"));
49 _trayMenu->addSeparator();
50 _trayMenu->addAction(coll->action("Quit"));
52 _trayIcon->setContextMenu(_trayMenu);
55 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
59 connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SIGNAL(activated(QSystemTrayIcon::ActivationReason)));
60 connect(_trayIcon, SIGNAL(messageClicked()), SIGNAL(messageClicked()));
63 SystemTray::~SystemTray() {
64 _trayMenu->deleteLater();
67 void SystemTray::loadAnimations() {
68 // system tray icon size
71 #elif defined Q_WS_MAC
80 KIconLoader *loader = KIconLoader::global();
82 IconLoader *loader = IconLoader::global();
86 QString fadeOffName("quassel_tray-fade-off-%1");
87 for(int i = 2; i <= 10; i++)
88 _phases.append(loader->loadIcon(fadeOffName.arg(i), IconLoader::Panel, size));
89 _idxOffEnd = _idxOnStart = _phases.count() - 1;
91 QString fadeOnName("quassel_tray-fade-on-%1");
92 for(int i = 2; i <= 15; i++)
93 _phases.append(loader->loadIcon(fadeOnName.arg(i), IconLoader::Panel, size));
94 _idxOnEnd = _idxAlertStart = _phases.count() - 1;
96 QString alertName("quassel_tray-alert-%1");
97 for(int i = 1; i <= 10; i++)
98 _phases.append(loader->loadIcon(alertName.arg(i), IconLoader::Panel, size));
101 void SystemTray::nextPhase() {
102 if(_currentIdx == _idxOnEnd && !_alert && _state == Inactive)
103 _currentIdx = _idxOffStart; // skip alert phases
105 else if(++_currentIdx >= _phases.count()) {
107 _currentIdx = _idxAlertStart;
110 _currentIdx = _idxOnEnd;
112 _currentIdx = _idxOffStart;
115 _trayIcon->setIcon(_phases.at(_currentIdx));
120 if((_state == Active && _currentIdx == _idxOnEnd) || (_state == Inactive && _currentIdx == _idxOffEnd))
121 _animationTimer.stop();
124 void SystemTray::setState(State state) {
125 if(_state != state) {
127 if(state == Inactive && _alert)
129 if(!_animationTimer.isActive())
130 _animationTimer.start();
134 void SystemTray::setAlert(bool alert) {
135 if(_alert != alert) {
137 if(!_animationTimer.isActive())
138 _animationTimer.start();
142 void SystemTray::setIconVisible(bool visible) {
149 void SystemTray::setToolTip(const QString &tip) {
150 _trayIcon->setToolTip(tip);
153 void SystemTray::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int millisecondsTimeoutHint) {
154 _trayIcon->showMessage(title, message, icon, millisecondsTimeoutHint);