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 _shouldBeVisible(true),
42 _passiveIcon(DesktopIcon("quassel_inactive")),
43 _activeIcon(DesktopIcon("quassel")),
44 _needsAttentionIcon(DesktopIcon("quassel_message")),
46 _associatedWidget(parent)
51 SystemTray::~SystemTray() {
52 _trayMenu->deleteLater();
55 QWidget *SystemTray::associatedWidget() const {
56 return _associatedWidget;
59 void SystemTray::init() {
60 ActionCollection *coll = QtUi::actionCollection("General");
61 _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
65 _trayMenu = kmenu = new KMenu();
66 kmenu->addTitle(_activeIcon, "Quassel IRC");
68 _trayMenu = new QMenu(associatedWidget());
71 _trayMenu->setTitle("Quassel IRC");
74 _trayMenu->setAttribute(Qt::WA_Hover);
77 _trayMenu->addAction(coll->action("ConnectCore"));
78 _trayMenu->addAction(coll->action("DisconnectCore"));
79 _trayMenu->addAction(coll->action("CoreInfo"));
80 _trayMenu->addSeparator();
81 _trayMenu->addAction(_minimizeRestoreAction);
82 _trayMenu->addAction(coll->action("Quit"));
84 connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
86 NotificationSettings notificationSettings;
87 notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
90 void SystemTray::trayMenuAboutToShow() {
91 if(GraphicalUi::isMainWidgetVisible())
92 _minimizeRestoreAction->setText(tr("&Minimize"));
94 _minimizeRestoreAction->setText(tr("&Restore"));
97 void SystemTray::setMode(Mode mode_) {
102 if(_mode == Legacy) {
103 _trayMenu->setWindowFlags(Qt::Popup);
105 _trayMenu->setWindowFlags(Qt::Window);
112 Icon SystemTray::stateIcon() const {
113 return stateIcon(state());
116 Icon SystemTray::stateIcon(State state) const {
123 return _needsAttentionIcon;
128 void SystemTray::setState(State state) {
129 if(_state != state) {
134 void SystemTray::setAlert(bool alerted) {
136 setState(NeedsAttention);
138 setState(Client::isConnected() ? Active : Passive);
141 void SystemTray::setVisible(bool visible) {
142 _shouldBeVisible = visible;
145 void SystemTray::setToolTip(const QString &title, const QString &subtitle) {
146 _toolTipTitle = title;
147 _toolTipSubTitle = subtitle;
148 emit toolTipChanged(title, subtitle);
151 void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id) {
155 Q_UNUSED(millisecondsTimeoutHint)
159 void SystemTray::activate(SystemTray::ActivationReason reason) {
160 emit activated(reason);
163 void SystemTray::minimizeRestore() {
164 GraphicalUi::toggleMainWidget();
167 void SystemTray::enableAnimationChanged(const QVariant &v) {
168 _animationEnabled = v.toBool();
169 emit animationEnabledChanged(v.toBool());