X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsystemtray.cpp;h=2bc365417a7383d2cea0cafd3d432c0da6ef3d47;hp=912582306722827500dad89449c2ec78816274df;hb=1a9450ecc5eeb5f987ceac790be84dcced02f028;hpb=2e9492d9ef198bde37da1f858602ab9624c0a12a diff --git a/src/qtui/systemtray.cpp b/src/qtui/systemtray.cpp index 91258230..2bc36541 100644 --- a/src/qtui/systemtray.cpp +++ b/src/qtui/systemtray.cpp @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-2010 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * + * This file is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License (LGPL) * + * as published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -15,132 +15,240 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ + +#include #include #include "systemtray.h" +#include "action.h" #include "actioncollection.h" #include "client.h" -#include "iconloader.h" #include "qtui.h" -#ifdef HAVE_KDE +#ifdef HAVE_KDE4 +# include # include # include #endif SystemTray::SystemTray(QWidget *parent) -: QObject(parent), - _mode(Invalid), - _state(Passive), - _inhibitActivation(false), - _passiveIcon(DesktopIcon("quassel_inactive")), - _activeIcon(DesktopIcon("quassel")), - _needsAttentionIcon(DesktopIcon("quassel_message")), - _trayMenu(0), - _associatedWidget(parent) + : QObject(parent), + _associatedWidget(parent) { - Q_ASSERT(parent); + Q_ASSERT(parent); +} + - qApp->installEventFilter(this); +SystemTray::~SystemTray() +{ + _trayMenu->deleteLater(); } -SystemTray::~SystemTray() { - _trayMenu->deleteLater(); + +void SystemTray::init() +{ + ActionCollection *coll = QtUi::actionCollection("General"); + _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore())); + +#ifdef HAVE_KDE4 + KMenu *kmenu; + _trayMenu = kmenu = new KMenu(); + kmenu->addTitle(_activeIcon, "Quassel IRC"); +#else + _trayMenu = new QMenu(associatedWidget()); +#endif + + _trayMenu->setTitle("Quassel IRC"); + +#ifndef HAVE_KDE4 + _trayMenu->setAttribute(Qt::WA_Hover); +#endif + + _trayMenu->addAction(coll->action("ConnectCore")); + _trayMenu->addAction(coll->action("DisconnectCore")); + _trayMenu->addAction(coll->action("CoreInfo")); + _trayMenu->addSeparator(); + _trayMenu->addAction(_minimizeRestoreAction); + _trayMenu->addAction(coll->action("Quit")); + + connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow())); + + NotificationSettings notificationSettings; + notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true); +} + + +QWidget *SystemTray::associatedWidget() const +{ + return _associatedWidget; +} + + +bool SystemTray::isSystemTrayAvailable() const +{ + return false; } -QWidget *SystemTray::associatedWidget() const { - return _associatedWidget; + +bool SystemTray::isVisible() const +{ + return false; +} + + +bool SystemTray::shouldBeVisible() const +{ + return _shouldBeVisible; +} + + +void SystemTray::setVisible(bool visible) +{ + _shouldBeVisible = visible; +} + + +SystemTray::Mode SystemTray::mode() const +{ + return _mode; +} + + +void SystemTray::setMode(Mode mode_) +{ + if (mode_ != _mode) { + _mode = mode_; +#ifdef HAVE_KDE4 + if (_trayMenu) { + if (_mode == Legacy) { + _trayMenu->setWindowFlags(Qt::Popup); + } + else { + _trayMenu->setWindowFlags(Qt::Window); + } + } +#endif + } } -void SystemTray::setTrayMenu(QMenu *menu) { - if(menu) - _trayMenu = menu; - else - _trayMenu = new QMenu(); - ActionCollection *coll = QtUi::actionCollection("General"); +SystemTray::State SystemTray::state() const +{ + return _state; +} + - _trayMenu->addAction(coll->action("ConnectCore")); - _trayMenu->addAction(coll->action("DisconnectCore")); - _trayMenu->addAction(coll->action("CoreInfo")); -#ifndef HAVE_KDE - _trayMenu->addSeparator(); - _trayMenu->addAction(coll->action("Quit")); -#endif /* HAVE_KDE */ +void SystemTray::setState(State state) +{ + if (_state != state) { + _state = state; + } } -void SystemTray::setMode(Mode mode_) { - if(mode_ != _mode) { - _mode = mode_; - if(_mode == Legacy) { - _trayMenu->setWindowFlags(Qt::Popup); - } else { - _trayMenu->setWindowFlags(Qt::Window); + +QString SystemTray::iconName(State state) const +{ + switch (state) { + case State::Passive: + return "inactive-quassel"; + case State::Active: + return "quassel"; + case State::NeedsAttention: + return "message-quassel"; } - } + return {}; } -Icon SystemTray::stateIcon() const { - return stateIcon(state()); + +bool SystemTray::isAlerted() const +{ + return state() == State::NeedsAttention; } -Icon SystemTray::stateIcon(State state) const { - switch(state) { - case Passive: - return _passiveIcon; - case Active: - return _activeIcon; - case NeedsAttention: - return _needsAttentionIcon; - } - return Icon(); + +void SystemTray::setAlert(bool alerted) +{ + if (alerted) + setState(NeedsAttention); + else + setState(Client::isConnected() ? Active : Passive); } -void SystemTray::setState(State state) { - if(_state != state) { - _state = state; - } + +QMenu *SystemTray::trayMenu() const +{ + return _trayMenu; } -void SystemTray::setAlert(bool alerted) { - if(alerted) - setState(NeedsAttention); - else - setState(Client::isConnected() ? Active : Passive); + +void SystemTray::trayMenuAboutToShow() +{ + if (GraphicalUi::isMainWidgetVisible()) + _minimizeRestoreAction->setText(tr("&Minimize")); + else + _minimizeRestoreAction->setText(tr("&Restore")); } -void SystemTray::setVisible(bool visible) { - Q_UNUSED(visible) + +bool SystemTray::animationEnabled() const +{ + return _animationEnabled; } -void SystemTray::setToolTip(const QString &title, const QString &subtitle) { - _toolTipTitle = title; - _toolTipSubTitle = subtitle; - emit toolTipChanged(title, subtitle); + +void SystemTray::enableAnimationChanged(const QVariant &v) +{ + _animationEnabled = v.toBool(); + emit animationEnabledChanged(v.toBool()); } -void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint) { - Q_UNUSED(title) - Q_UNUSED(message) - Q_UNUSED(icon) - Q_UNUSED(millisecondsTimeoutHint) + +QString SystemTray::toolTipTitle() const +{ + return _toolTipTitle; } -void SystemTray::activate(SystemTray::ActivationReason reason) { - emit activated(reason); +QString SystemTray::toolTipSubTitle() const +{ + return _toolTipSubTitle; +} - if(reason == Trigger && !isActivationInhibited()) { - GraphicalUi::toggleMainWidget(); - } + +void SystemTray::setToolTip(const QString &title, const QString &subtitle) +{ + _toolTipTitle = title; + _toolTipSubTitle = subtitle; + emit toolTipChanged(title, subtitle); +} + + +void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id) +{ + Q_UNUSED(title) + Q_UNUSED(message) + Q_UNUSED(icon) + Q_UNUSED(millisecondsTimeoutHint) + Q_UNUSED(id) +} + + +void SystemTray::closeMessage(uint notificationId) +{ + Q_UNUSED(notificationId) +} + + +void SystemTray::activate(SystemTray::ActivationReason reason) +{ + emit activated(reason); } -bool SystemTray::eventFilter(QObject *obj, QEvent *event) { - if(event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) { - _inhibitActivation = false; - } - return QObject::eventFilter(obj, event); + +void SystemTray::minimizeRestore() +{ + GraphicalUi::toggleMainWidget(); }