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()));
85 NotificationSettings notificationSettings;
86 notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
89 void SystemTray::trayMenuAboutToShow() {
90 if(GraphicalUi::isMainWidgetVisible())
91 _minimizeRestoreAction->setText(tr("&Minimize"));
93 _minimizeRestoreAction->setText(tr("&Restore"));
96 void SystemTray::setMode(Mode mode_) {
101 if(_mode == Legacy) {
102 _trayMenu->setWindowFlags(Qt::Popup);
104 _trayMenu->setWindowFlags(Qt::Window);
111 Icon SystemTray::stateIcon() const {
112 return stateIcon(state());
115 Icon SystemTray::stateIcon(State state) const {
122 return _needsAttentionIcon;
127 void SystemTray::setState(State state) {
128 if(_state != state) {
133 void SystemTray::setAlert(bool alerted) {
135 setState(NeedsAttention);
137 setState(Client::isConnected() ? Active : Passive);
140 void SystemTray::setVisible(bool visible) {
144 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
145 _toolTipTitle = title;
146 _toolTipSubTitle = subtitle;
147 emit toolTipChanged(title, subtitle);
150 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id) {
154 Q_UNUSED(millisecondsTimeoutHint)
158 void SystemTray::activate(SystemTray::ActivationReason reason) {
159 emit activated(reason);
162 void SystemTray::minimizeRestore() {
163 GraphicalUi::toggleMainWidget();
166 void SystemTray::enableAnimationChanged(const QVariant &v) {
167 _animationEnabled = v.toBool();
168 emit animationEnabledChanged(v.toBool());