1 /***************************************************************************
2 * Copyright (C) 2005-2013 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This file is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License (LGPL) *
7 * as published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include <QApplication>
24 #include "systemtray.h"
27 #include "actioncollection.h"
29 #include "iconloader.h"
34 # include <KWindowInfo>
35 # include <KWindowSystem>
38 SystemTray::SystemTray(QWidget *parent)
42 _shouldBeVisible(true),
43 _passiveIcon(DesktopIcon("quassel-inactive")),
44 _activeIcon(DesktopIcon("quassel")),
45 _needsAttentionIcon(DesktopIcon("quassel-message")),
47 _associatedWidget(parent)
53 SystemTray::~SystemTray()
55 _trayMenu->deleteLater();
59 QWidget *SystemTray::associatedWidget() const
61 return _associatedWidget;
65 void SystemTray::init()
67 ActionCollection *coll = QtUi::actionCollection("General");
68 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
72 _trayMenu = kmenu = new KMenu();
73 kmenu->addTitle(_activeIcon, "Quassel IRC");
75 _trayMenu = new QMenu(associatedWidget());
78 _trayMenu->setTitle("Quassel IRC");
81 _trayMenu->setAttribute(Qt::WA_Hover);
84 _trayMenu->addAction(coll->action("ConnectCore"));
85 _trayMenu->addAction(coll->action("DisconnectCore"));
86 _trayMenu->addAction(coll->action("CoreInfo"));
87 _trayMenu->addSeparator();
88 _trayMenu->addAction(_minimizeRestoreAction);
89 _trayMenu->addAction(coll->action("Quit"));
91 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
93 NotificationSettings notificationSettings;
94 notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
98 void SystemTray::trayMenuAboutToShow()
100 if (GraphicalUi::isMainWidgetVisible())
101 _minimizeRestoreAction->setText(tr("&Minimize"));
103 _minimizeRestoreAction->setText(tr("&Restore"));
107 void SystemTray::setMode(Mode mode_)
109 if (mode_ != _mode) {
113 if (_mode == Legacy) {
114 _trayMenu->setWindowFlags(Qt::Popup);
117 _trayMenu->setWindowFlags(Qt::Window);
125 Icon SystemTray::stateIcon() const
127 return stateIcon(state());
131 Icon SystemTray::stateIcon(State state) const
139 return _needsAttentionIcon;
145 void SystemTray::setState(State state)
147 if (_state != state) {
153 void SystemTray::setAlert(bool alerted)
156 setState(NeedsAttention);
158 setState(Client::isConnected() ? Active : Passive);
162 void SystemTray::setVisible(bool visible)
164 _shouldBeVisible = visible;
168 void SystemTray::setToolTip(const QString &title, const QString &subtitle)
170 _toolTipTitle = title;
171 _toolTipSubTitle = subtitle;
172 emit toolTipChanged(title, subtitle);
176 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id)
181 Q_UNUSED(millisecondsTimeoutHint)
186 void SystemTray::activate(SystemTray::ActivationReason reason)
188 emit activated(reason);
192 void SystemTray::minimizeRestore()
194 GraphicalUi::toggleMainWidget();
198 void SystemTray::enableAnimationChanged(const QVariant &v)
200 _animationEnabled = v.toBool();
201 emit animationEnabledChanged(v.toBool());