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 ***************************************************************************/
20 #include <QApplication>
23 #include "systemtray.h"
26 #include "actioncollection.h"
28 #include "iconloader.h"
33 # include <KWindowInfo>
34 # include <KWindowSystem>
37 SystemTray::SystemTray(QWidget *parent)
41 _passiveIcon(DesktopIcon("quassel_inactive")),
42 _activeIcon(DesktopIcon("quassel")),
43 _needsAttentionIcon(DesktopIcon("quassel_message")),
45 _associatedWidget(parent)
50 SystemTray::~SystemTray() {
51 _trayMenu->deleteLater();
54 QWidget *SystemTray::associatedWidget() const {
55 return _associatedWidget;
58 void SystemTray::init() {
59 ActionCollection *coll = QtUi::actionCollection("General");
60 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
64 _trayMenu = kmenu = new KMenu();
65 kmenu->addTitle(qApp->windowIcon(), "Quassel IRC");
67 _trayMenu = new QMenu(associatedWidget());
70 _trayMenu->setTitle("Quassel IRC");
73 _trayMenu->setAttribute(Qt::WA_Hover);
76 _trayMenu->addAction(coll->action("ConnectCore"));
77 _trayMenu->addAction(coll->action("DisconnectCore"));
78 _trayMenu->addAction(coll->action("CoreInfo"));
79 _trayMenu->addSeparator();
80 _trayMenu->addAction(_minimizeRestoreAction);
81 _trayMenu->addAction(coll->action("Quit"));
83 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
86 void SystemTray::trayMenuAboutToShow() {
87 if(GraphicalUi::isMainWidgetVisible())
88 _minimizeRestoreAction->setText(tr("&Minimize"));
90 _minimizeRestoreAction->setText(tr("&Restore"));
93 void SystemTray::setMode(Mode mode_) {
99 _trayMenu->setWindowFlags(Qt::Popup);
101 _trayMenu->setWindowFlags(Qt::Window);
108 Icon SystemTray::stateIcon() const {
109 return stateIcon(state());
112 Icon SystemTray::stateIcon(State state) const {
119 return _needsAttentionIcon;
124 void SystemTray::setState(State state) {
125 if(_state != state) {
130 void SystemTray::setAlert(bool alerted) {
132 setState(NeedsAttention);
134 setState(Client::isConnected() ? Active : Passive);
137 void SystemTray::setVisible(bool visible) {
141 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
142 _toolTipTitle = title;
143 _toolTipSubTitle = subtitle;
144 emit toolTipChanged(title, subtitle);
147 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) {
151 Q_UNUSED(millisecondsTimeoutHint)
154 void SystemTray::activate(SystemTray::ActivationReason reason) {
155 emit activated(reason);
158 void SystemTray::minimizeRestore() {
159 GraphicalUi::toggleMainWidget();