X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsystemtray.cpp;h=afa7964f602b9c372fc399a5370903a009bc5684;hp=acb68b1937a9546422cbcefcce3b8de436b2964f;hb=5ba28fb36a747bd9a2c05a58f0533d1e38c2a0de;hpb=5a470c1acab34c95d957bf81dce7e7cd330a2c58 diff --git a/src/qtui/systemtray.cpp b/src/qtui/systemtray.cpp index acb68b19..afa7964f 100644 --- a/src/qtui/systemtray.cpp +++ b/src/qtui/systemtray.cpp @@ -1,155 +1,161 @@ /*************************************************************************** -* Copyright (C) 2005-09 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 program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* 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. * -***************************************************************************/ - + * Copyright (C) 2005-2010 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 program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * 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. * + ***************************************************************************/ +#include #include #include "systemtray.h" +#include "action.h" #include "actioncollection.h" +#include "client.h" #include "iconloader.h" #include "qtui.h" -#include "qtuisettings.h" -SystemTray::SystemTray(QObject *parent) +#ifdef HAVE_KDE +# include +# include +# include +#endif + +SystemTray::SystemTray(QWidget *parent) : QObject(parent), - _state(Inactive), - _alert(false), - _currentIdx(0) + _mode(Invalid), + _state(Passive), + _passiveIcon(DesktopIcon("quassel_inactive")), + _activeIcon(DesktopIcon("quassel")), + _needsAttentionIcon(DesktopIcon("quassel_message")), + _trayMenu(0), + _associatedWidget(parent) { - loadAnimations(); - _currentIdx = _idxOffEnd; - _trayIcon = new QSystemTrayIcon(_phases.at(_currentIdx), this); - - _animationTimer.setInterval(150); - _animationTimer.setSingleShot(false); - connect(&_animationTimer, SIGNAL(timeout()), SLOT(nextPhase())); - - ActionCollection *coll = QtUi::actionCollection("General"); - _trayMenu = new QMenu(); - _trayMenu->addAction(coll->action("ConnectCore")); - _trayMenu->addAction(coll->action("DisconnectCore")); - _trayMenu->addAction(coll->action("CoreInfo")); - _trayMenu->addSeparator(); - _trayMenu->addAction(coll->action("Quit")); - - _trayIcon->setContextMenu(_trayMenu); - - QtUiSettings s; - if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) { - _trayIcon->show(); - } - - connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SIGNAL(activated(QSystemTrayIcon::ActivationReason))); - connect(_trayIcon, SIGNAL(messageClicked()), SIGNAL(messageClicked())); + Q_ASSERT(parent); } SystemTray::~SystemTray() { _trayMenu->deleteLater(); } -void SystemTray::loadAnimations() { -// system tray icon size -#ifdef Q_WS_WIN - const int size = 16; -#elif defined Q_WS_MAC - const int size = 128; -#else - const int size = 22; -#endif +QWidget *SystemTray::associatedWidget() const { + return _associatedWidget; +} - _phases.clear(); +void SystemTray::init() { + ActionCollection *coll = QtUi::actionCollection("General"); + _minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore())); #ifdef HAVE_KDE - KIconLoader *loader = KIconLoader::global(); + KMenu *kmenu; + _trayMenu = kmenu = new KMenu(); + kmenu->addTitle(qApp->windowIcon(), "Quassel IRC"); #else - IconLoader *loader = IconLoader::global(); + _trayMenu = new QMenu(associatedWidget()); #endif - _idxOffStart = 0; - QString fadeOffName("quassel_tray-fade-off-%1"); - for(int i = 2; i <= 10; i++) - _phases.append(loader->loadIcon(fadeOffName.arg(i), IconLoader::Panel, size)); - _idxOffEnd = _idxOnStart = _phases.count() - 1; + _trayMenu->setTitle("Quassel IRC"); - QString fadeOnName("quassel_tray-fade-on-%1"); - for(int i = 2; i <= 15; i++) - _phases.append(loader->loadIcon(fadeOnName.arg(i), IconLoader::Panel, size)); - _idxOnEnd = _idxAlertStart = _phases.count() - 1; +#ifndef HAVE_KDE + _trayMenu->setAttribute(Qt::WA_Hover); +#endif - QString alertName("quassel_tray-alert-%1"); - for(int i = 1; i <= 10; i++) - _phases.append(loader->loadIcon(alertName.arg(i), IconLoader::Panel, size)); + _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())); } -void SystemTray::nextPhase() { - if(_currentIdx == _idxOnEnd && !_alert && _state == Inactive) - _currentIdx = _idxOffStart; // skip alert phases - - else if(++_currentIdx >= _phases.count()) { - if(_alert) - _currentIdx = _idxAlertStart; - else - if(_state == Active) - _currentIdx = _idxOnEnd; - else - _currentIdx = _idxOffStart; - } +void SystemTray::trayMenuAboutToShow() { + if(GraphicalUi::isMainWidgetVisible()) + _minimizeRestoreAction->setText(tr("&Minimize")); + else + _minimizeRestoreAction->setText(tr("&Restore")); +} - _trayIcon->setIcon(_phases.at(_currentIdx)); +void SystemTray::setMode(Mode mode_) { + if(mode_ != _mode) { + _mode = mode_; +#ifdef HAVE_KDE + if(_trayMenu) { + if(_mode == Legacy) { + _trayMenu->setWindowFlags(Qt::Popup); + } else { + _trayMenu->setWindowFlags(Qt::Window); + } + } +#endif + } +} - if(_alert) - return; +Icon SystemTray::stateIcon() const { + return stateIcon(state()); +} - if((_state == Active && _currentIdx == _idxOnEnd) || (_state == Inactive && _currentIdx == _idxOffEnd)) - _animationTimer.stop(); +Icon SystemTray::stateIcon(State state) const { + switch(state) { + case Passive: + return _passiveIcon; + case Active: + return _activeIcon; + case NeedsAttention: + return _needsAttentionIcon; + } + return Icon(); } void SystemTray::setState(State state) { if(_state != state) { _state = state; - if(state == Inactive && _alert) - _alert = false; - if(!_animationTimer.isActive()) - _animationTimer.start(); } } -void SystemTray::setAlert(bool alert) { - if(_alert != alert) { - _alert = alert; - if(!_animationTimer.isActive()) - _animationTimer.start(); - } +void SystemTray::setAlert(bool alerted) { + if(alerted) + setState(NeedsAttention); + else + setState(Client::isConnected() ? Active : Passive); } -void SystemTray::setIconVisible(bool visible) { - if(visible) - _trayIcon->show(); - else - _trayIcon->hide(); +void SystemTray::setVisible(bool visible) { + Q_UNUSED(visible) +} + +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::setToolTip(const QString &tip) { - _trayIcon->setToolTip(tip); +void SystemTray::activate(SystemTray::ActivationReason reason) { + emit activated(reason); } -void SystemTray::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon, int millisecondsTimeoutHint) { - _trayIcon->showMessage(title, message, icon, millisecondsTimeoutHint); +void SystemTray::minimizeRestore() { + GraphicalUi::toggleMainWidget(); }