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 ***************************************************************************/
22 #include "systemtray.h"
24 #include "actioncollection.h"
26 #include "iconloader.h"
28 #include "qtuisettings.h"
30 SystemTray::SystemTray(QObject *parent)
34 _inhibitActivation(false),
35 _passiveIcon(DesktopIcon("quassel_inactive")),
36 _activeIcon(DesktopIcon("quassel")),
37 _needsAttentionIcon(DesktopIcon("quassel_message")),
40 qApp->installEventFilter(this);
43 SystemTray::~SystemTray() {
44 _trayMenu->deleteLater();
47 void SystemTray::setTrayMenu(QMenu *menu) {
51 _trayMenu = new QMenu();
53 ActionCollection *coll = QtUi::actionCollection("General");
55 _trayMenu->addAction(coll->action("ConnectCore"));
56 _trayMenu->addAction(coll->action("DisconnectCore"));
57 _trayMenu->addAction(coll->action("CoreInfo"));
59 _trayMenu->addSeparator();
60 _trayMenu->addAction(coll->action("Quit"));
65 void SystemTray::setMode(Mode mode_) {
69 _trayMenu->setWindowFlags(Qt::Popup);
71 _trayMenu->setWindowFlags(Qt::Window);
76 Icon SystemTray::stateIcon() const {
77 return stateIcon(state());
80 Icon SystemTray::stateIcon(State state) const {
87 return _needsAttentionIcon;
92 void SystemTray::setState(State state) {
98 void SystemTray::setAlert(bool alerted) {
100 setState(NeedsAttention);
102 setState(Client::isConnected() ? Active : Passive);
105 void SystemTray::setVisible(bool visible) {
109 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
110 _toolTipTitle = title;
111 _toolTipSubTitle = subtitle;
112 emit toolTipChanged(title, subtitle);
115 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) {
119 Q_UNUSED(millisecondsTimeoutHint)
122 bool SystemTray::eventFilter(QObject *obj, QEvent *event) {
124 if(event->type() == QEvent::MouseButtonRelease) {
125 _inhibitActivation = false;