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)
43 NotificationSettings{}.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
44 UiStyleSettings{}.initAndNotify("Icons/InvertTray", this, SLOT(invertTrayIconChanged(QVariant)), false);
48 SystemTray::~SystemTray()
50 _trayMenu->deleteLater();
54 void SystemTray::init()
56 ActionCollection *coll = QtUi::actionCollection("General");
57 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
61 _trayMenu = kmenu = new KMenu();
62 kmenu->addTitle(_activeIcon, "Quassel IRC");
64 _trayMenu = new QMenu(associatedWidget());
67 _trayMenu->setTitle("Quassel IRC");
70 _trayMenu->setAttribute(Qt::WA_Hover);
73 _trayMenu->addAction(coll->action("ConnectCore"));
74 _trayMenu->addAction(coll->action("DisconnectCore"));
75 _trayMenu->addAction(coll->action("CoreInfo"));
76 _trayMenu->addSeparator();
77 _trayMenu->addAction(_minimizeRestoreAction);
78 _trayMenu->addAction(coll->action("Quit"));
80 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
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
157 name = "inactive-quassel-tray";
160 name = "active-quassel-tray";
162 case State::NeedsAttention:
163 name = "message-quassel-tray";
167 if (_trayIconInverted) {
175 bool SystemTray::isAlerted() const
177 return state() == State::NeedsAttention;
181 void SystemTray::setAlert(bool alerted)
184 setState(NeedsAttention);
186 setState(Client::isConnected() ? Active : Passive);
190 QMenu *SystemTray::trayMenu() const
196 void SystemTray::trayMenuAboutToShow()
198 if (GraphicalUi::isMainWidgetVisible())
199 _minimizeRestoreAction->setText(tr("&Minimize"));
201 _minimizeRestoreAction->setText(tr("&Restore"));
205 bool SystemTray::animationEnabled() const
207 return _animationEnabled;
211 void SystemTray::enableAnimationChanged(const QVariant &v)
213 _animationEnabled = v.toBool();
214 emit animationEnabledChanged(v.toBool());
218 void SystemTray::invertTrayIconChanged(const QVariant &v)
220 _trayIconInverted = v.toBool();
224 QString SystemTray::toolTipTitle() const
226 return _toolTipTitle;
230 QString SystemTray::toolTipSubTitle() const
232 return _toolTipSubTitle;
236 void SystemTray::setToolTip(const QString &title, const QString &subtitle)
238 _toolTipTitle = title;
239 _toolTipSubTitle = subtitle;
240 emit toolTipChanged(title, subtitle);
244 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id)
249 Q_UNUSED(millisecondsTimeoutHint)
254 void SystemTray::closeMessage(uint notificationId)
256 Q_UNUSED(notificationId)
260 void SystemTray::activate(SystemTray::ActivationReason reason)
262 emit activated(reason);
266 void SystemTray::minimizeRestore()
268 GraphicalUi::toggleMainWidget();