1 /***************************************************************************
2 * Copyright (C) 2005-2016 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"
33 # include <KWindowInfo>
34 # include <KWindowSystem>
37 SystemTray::SystemTray(QWidget *parent)
41 _shouldBeVisible(true),
42 _passiveIcon(QIcon::fromTheme("inactive-quassel", QIcon(":/icons/inactive-quassel.png"))),
43 _activeIcon(QIcon::fromTheme("quassel", QIcon(":/icons/quassel.png"))),
44 _needsAttentionIcon(QIcon::fromTheme("message-quassel", QIcon(":/icons/message-quassel.png"))),
46 _associatedWidget(parent)
52 SystemTray::~SystemTray()
54 _trayMenu->deleteLater();
58 QWidget *SystemTray::associatedWidget() const
60 return _associatedWidget;
64 void SystemTray::init()
66 ActionCollection *coll = QtUi::actionCollection("General");
67 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
71 _trayMenu = kmenu = new KMenu();
72 kmenu->addTitle(_activeIcon, "Quassel IRC");
74 _trayMenu = new QMenu(associatedWidget());
77 _trayMenu->setTitle("Quassel IRC");
80 _trayMenu->setAttribute(Qt::WA_Hover);
83 _trayMenu->addAction(coll->action("ConnectCore"));
84 _trayMenu->addAction(coll->action("DisconnectCore"));
85 _trayMenu->addAction(coll->action("CoreInfo"));
86 _trayMenu->addSeparator();
87 _trayMenu->addAction(_minimizeRestoreAction);
88 _trayMenu->addAction(coll->action("Quit"));
90 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
92 NotificationSettings notificationSettings;
93 notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
97 void SystemTray::trayMenuAboutToShow()
99 if (GraphicalUi::isMainWidgetVisible())
100 _minimizeRestoreAction->setText(tr("&Minimize"));
102 _minimizeRestoreAction->setText(tr("&Restore"));
106 void SystemTray::setMode(Mode mode_)
108 if (mode_ != _mode) {
112 if (_mode == Legacy) {
113 _trayMenu->setWindowFlags(Qt::Popup);
116 _trayMenu->setWindowFlags(Qt::Window);
124 QIcon SystemTray::stateIcon() const
126 return stateIcon(state());
130 QIcon SystemTray::stateIcon(State state) const
138 return _needsAttentionIcon;
144 void SystemTray::setState(State state)
146 if (_state != state) {
152 void SystemTray::setAlert(bool alerted)
155 setState(NeedsAttention);
157 setState(Client::isConnected() ? Active : Passive);
161 void SystemTray::setVisible(bool visible)
163 _shouldBeVisible = visible;
167 void SystemTray::setToolTip(const QString &title, const QString &subtitle)
169 _toolTipTitle = title;
170 _toolTipSubTitle = subtitle;
171 emit toolTipChanged(title, subtitle);
175 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id)
180 Q_UNUSED(millisecondsTimeoutHint)
185 void SystemTray::activate(SystemTray::ActivationReason reason)
187 emit activated(reason);
191 void SystemTray::minimizeRestore()
193 GraphicalUi::toggleMainWidget();
197 void SystemTray::enableAnimationChanged(const QVariant &v)
199 _animationEnabled = v.toBool();
200 emit animationEnabledChanged(v.toBool());