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 _passiveIcon(DesktopIcon("quassel_inactive")),
39 _activeIcon(DesktopIcon("quassel")),
40 _needsAttentionIcon(DesktopIcon("quassel_message")),
42 _associatedWidget(parent)
47 SystemTray::~SystemTray() {
48 _trayMenu->deleteLater();
51 QWidget *SystemTray::associatedWidget() const {
52 return _associatedWidget;
55 void SystemTray::setTrayMenu(QMenu *menu) {
59 _trayMenu = new QMenu();
61 ActionCollection *coll = QtUi::actionCollection("General");
63 _trayMenu->addAction(coll->action("ConnectCore"));
64 _trayMenu->addAction(coll->action("DisconnectCore"));
65 _trayMenu->addAction(coll->action("CoreInfo"));
67 _trayMenu->addSeparator();
68 _trayMenu->addAction(coll->action("Quit"));
72 void SystemTray::setMode(Mode mode_) {
76 _trayMenu->setWindowFlags(Qt::Popup);
78 _trayMenu->setWindowFlags(Qt::Window);
83 Icon SystemTray::stateIcon() const {
84 return stateIcon(state());
87 Icon SystemTray::stateIcon(State state) const {
94 return _needsAttentionIcon;
99 void SystemTray::setState(State state) {
100 if(_state != state) {
105 void SystemTray::setAlert(bool alerted) {
107 setState(NeedsAttention);
109 setState(Client::isConnected() ? Active : Passive);
112 void SystemTray::setVisible(bool visible) {
116 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
117 _toolTipTitle = title;
118 _toolTipSubTitle = subtitle;
119 emit toolTipChanged(title, subtitle);
122 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) {
126 Q_UNUSED(millisecondsTimeoutHint)
129 void SystemTray::activate(SystemTray::ActivationReason reason) {
130 emit activated(reason);