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"
30 # include <KWindowInfo>
31 # include <KWindowSystem>
34 SystemTray::SystemTray(QWidget *parent)
38 _inhibitActivation(false),
39 _passiveIcon(DesktopIcon("quassel_inactive")),
40 _activeIcon(DesktopIcon("quassel")),
41 _needsAttentionIcon(DesktopIcon("quassel_message")),
43 _associatedWidget(parent)
47 qApp->installEventFilter(this);
50 SystemTray::~SystemTray() {
51 _trayMenu->deleteLater();
54 QWidget *SystemTray::associatedWidget() const {
55 return _associatedWidget;
58 void SystemTray::setTrayMenu(QMenu *menu) {
62 _trayMenu = new QMenu();
64 ActionCollection *coll = QtUi::actionCollection("General");
66 _trayMenu->addAction(coll->action("ConnectCore"));
67 _trayMenu->addAction(coll->action("DisconnectCore"));
68 _trayMenu->addAction(coll->action("CoreInfo"));
70 _trayMenu->addSeparator();
71 _trayMenu->addAction(coll->action("Quit"));
75 void SystemTray::setMode(Mode mode_) {
79 _trayMenu->setWindowFlags(Qt::Popup);
81 _trayMenu->setWindowFlags(Qt::Window);
86 Icon SystemTray::stateIcon() const {
87 return stateIcon(state());
90 Icon SystemTray::stateIcon(State state) const {
97 return _needsAttentionIcon;
102 void SystemTray::setState(State state) {
103 if(_state != state) {
108 void SystemTray::setAlert(bool alerted) {
110 setState(NeedsAttention);
112 setState(Client::isConnected() ? Active : Passive);
115 void SystemTray::setVisible(bool visible) {
119 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
120 _toolTipTitle = title;
121 _toolTipSubTitle = subtitle;
122 emit toolTipChanged(title, subtitle);
125 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) {
129 Q_UNUSED(millisecondsTimeoutHint)
132 void SystemTray::activate(SystemTray::ActivationReason reason) {
134 emit activated(reason);
136 if(reason == Trigger && !isActivationInhibited()) {
137 GraphicalUi::toggleMainWidget();
141 bool SystemTray::eventFilter(QObject *obj, QEvent *event) {
142 if(event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) {
143 _inhibitActivation = false;
145 return QObject::eventFilter(obj, event);