1 /***************************************************************************
2 * Copyright (C) 2005-2018 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)
39 _associatedWidget(parent)
45 SystemTray::~SystemTray()
47 _trayMenu->deleteLater();
51 void SystemTray::init()
53 ActionCollection *coll = QtUi::actionCollection("General");
54 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
58 _trayMenu = kmenu = new KMenu();
59 kmenu->addTitle(_activeIcon, "Quassel IRC");
61 _trayMenu = new QMenu(associatedWidget());
64 _trayMenu->setTitle("Quassel IRC");
67 _trayMenu->setAttribute(Qt::WA_Hover);
70 _trayMenu->addAction(coll->action("ConnectCore"));
71 _trayMenu->addAction(coll->action("DisconnectCore"));
72 _trayMenu->addAction(coll->action("CoreInfo"));
73 _trayMenu->addSeparator();
74 _trayMenu->addAction(_minimizeRestoreAction);
75 _trayMenu->addAction(coll->action("Quit"));
77 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
79 NotificationSettings notificationSettings;
80 notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
84 QWidget *SystemTray::associatedWidget() const
86 return _associatedWidget;
90 bool SystemTray::isSystemTrayAvailable() const
96 bool SystemTray::isVisible() const
102 bool SystemTray::shouldBeVisible() const
104 return _shouldBeVisible;
108 void SystemTray::setVisible(bool visible)
110 _shouldBeVisible = visible;
114 SystemTray::Mode SystemTray::mode() const
120 void SystemTray::setMode(Mode mode_)
122 if (mode_ != _mode) {
126 if (_mode == Legacy) {
127 _trayMenu->setWindowFlags(Qt::Popup);
130 _trayMenu->setWindowFlags(Qt::Window);
138 SystemTray::State SystemTray::state() const
144 void SystemTray::setState(State state)
146 if (_state != state) {
152 QString SystemTray::iconName(State state) const
156 return "inactive-quassel";
159 case State::NeedsAttention:
160 return "message-quassel";
166 bool SystemTray::isAlerted() const
168 return state() == State::NeedsAttention;
172 void SystemTray::setAlert(bool alerted)
175 setState(NeedsAttention);
177 setState(Client::isConnected() ? Active : Passive);
181 QMenu *SystemTray::trayMenu() const
187 void SystemTray::trayMenuAboutToShow()
189 if (GraphicalUi::isMainWidgetVisible())
190 _minimizeRestoreAction->setText(tr("&Minimize"));
192 _minimizeRestoreAction->setText(tr("&Restore"));
196 bool SystemTray::animationEnabled() const
198 return _animationEnabled;
202 void SystemTray::enableAnimationChanged(const QVariant &v)
204 _animationEnabled = v.toBool();
205 emit animationEnabledChanged(v.toBool());
209 QString SystemTray::toolTipTitle() const
211 return _toolTipTitle;
215 QString SystemTray::toolTipSubTitle() const
217 return _toolTipSubTitle;
221 void SystemTray::setToolTip(const QString &title, const QString &subtitle)
223 _toolTipTitle = title;
224 _toolTipSubTitle = subtitle;
225 emit toolTipChanged(title, subtitle);
229 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id)
234 Q_UNUSED(millisecondsTimeoutHint)
239 void SystemTray::closeMessage(uint notificationId)
241 Q_UNUSED(notificationId)
245 void SystemTray::activate(SystemTray::ActivationReason reason)
247 emit activated(reason);
251 void SystemTray::minimizeRestore()
253 GraphicalUi::toggleMainWidget();