From: Manuel Nickschas Date: Fri, 5 Feb 2010 15:07:27 +0000 (+0100) Subject: SystemTray refactoring in preparation of supporting StatusNotifier X-Git-Tag: 0.6-beta1~46 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=e7d1bc1fa02e1233f140e4b04d99ab8f4685bce5 SystemTray refactoring in preparation of supporting StatusNotifier * Make SystemTray the base class for both legacy tray icon and StatusNotifier * Move all {Q|K}SystemTrayIcon related functionality into LegacySystemTray * Replace tray animation (can't be done via dbus later) by blinking * Adapt the rest of the code base to this --- diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index 0a873772..920fe2c2 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -38,6 +38,7 @@ set(SOURCES inputwidget.cpp ircconnectionwizard.cpp jumpkeyhandler.cpp + legacysystemtray.cpp mainpage.cpp mainwin.cpp msgprocessorstatuswidget.cpp @@ -84,6 +85,7 @@ set(MOC_HDRS inputwidget.h ircconnectionwizard.h jumpkeyhandler.h + legacysystemtray.h mainpage.h mainwin.h msgprocessorstatuswidget.h diff --git a/src/qtui/knotificationbackend.cpp b/src/qtui/knotificationbackend.cpp index 24974e0f..d3939dfb 100644 --- a/src/qtui/knotificationbackend.cpp +++ b/src/qtui/knotificationbackend.cpp @@ -1,28 +1,27 @@ /*************************************************************************** -* 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. * -***************************************************************************/ - -#include + * 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 +#include #include "knotificationbackend.h" @@ -31,13 +30,12 @@ #include "iconloader.h" #include "networkmodel.h" #include "qtui.h" -#include "systemtray.h" KNotificationBackend::KNotificationBackend(QObject *parent) : AbstractNotificationBackend(parent) { - connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - SLOT(notificationActivated(QSystemTrayIcon::ActivationReason))); + connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)), + SLOT(notificationActivated(SystemTray::ActivationReason))); } void KNotificationBackend::notify(const Notification &n) { @@ -94,8 +92,8 @@ void KNotificationBackend::notificationActivated() { notificationActivated(id); } -void KNotificationBackend::notificationActivated(QSystemTrayIcon::ActivationReason reason) { - if(reason == QSystemTrayIcon::Trigger && _notifications.count()) { +void KNotificationBackend::notificationActivated(SystemTray::ActivationReason reason) { + if(reason == SystemTray::Trigger && _notifications.count()) { notificationActivated(_notifications.first().first); // oldest one } } diff --git a/src/qtui/knotificationbackend.h b/src/qtui/knotificationbackend.h index 5bdd6c6a..925f4479 100644 --- a/src/qtui/knotificationbackend.h +++ b/src/qtui/knotificationbackend.h @@ -1,30 +1,29 @@ /*************************************************************************** -* 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. * + ***************************************************************************/ #ifndef KNOTIFICATIONBACKEND_H_ #define KNOTIFICATIONBACKEND_H_ -#include - #include "abstractnotificationbackend.h" #include "settingspage.h" +#include "systemtray.h" class KNotification; class KNotifyConfigWidget; @@ -41,7 +40,7 @@ public: private slots: void notificationActivated(); - void notificationActivated(QSystemTrayIcon::ActivationReason); + void notificationActivated(SystemTray::ActivationReason); void notificationActivated(uint notificationId); private: diff --git a/src/qtui/legacysystemtray.cpp b/src/qtui/legacysystemtray.cpp new file mode 100644 index 00000000..b57fd995 --- /dev/null +++ b/src/qtui/legacysystemtray.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifndef QT_NO_SYSTEMTRAYICON + +#include "legacysystemtray.h" +#include "qtui.h" + +LegacySystemTray::LegacySystemTray(QObject *parent) + : SystemTray(parent), + _blinkState(false), + _isVisible(true) +{ +#ifndef HAVE_KDE + _trayIcon = new QSystemTrayIcon(QtUi::mainWindow()); +#else + _trayIcon = new KSystemTrayIcon(QtUi::mainWindow()); + // We don't want to trigger a minimize if a highlight is pending, so we brutally remove the internal connection for that + disconnect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + _trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason))); +#endif +#ifndef Q_WS_MAC + connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), + SLOT(on_activated(QSystemTrayIcon::ActivationReason))); +#endif + connect(_trayIcon, SIGNAL(messageClicked()), + SIGNAL(messageClicked())); + + setTrayMenu(_trayIcon->contextMenu()); + _trayIcon->setContextMenu(trayMenu()); + + _blinkTimer.setInterval(500); + _blinkTimer.setSingleShot(false); + connect(&_blinkTimer, SIGNAL(timeout()), SLOT(on_blinkTimeout())); +} + +void LegacySystemTray::init() { + if(mode() == Invalid) // derived class hasn't set a mode itself + setMode(Legacy); +} + +void LegacySystemTray::syncLegacyIcon() { + _trayIcon->setIcon(stateIcon()); + _trayIcon->setToolTip(toolTipTitle()); +} + +void LegacySystemTray::setVisible(bool visible) { + _isVisible = visible; + if(mode() == Legacy) { + if(visible) + _trayIcon->show(); + else + _trayIcon->hide(); + } +} + +void LegacySystemTray::setMode(Mode mode_) { + SystemTray::setMode(mode_); + + if(mode() == Legacy) { + syncLegacyIcon(); + if(_isVisible) + _trayIcon->show(); + if(state() == NeedsAttention) + _blinkTimer.start(); + } else { + _trayIcon->hide(); + _blinkTimer.stop(); + } +} + +void LegacySystemTray::setState(State state_) { + State oldstate = state(); + SystemTray::setState(state_); + if(oldstate != state()) { + if(state() == NeedsAttention && mode() == Legacy) + _blinkTimer.start(); + else { + _blinkTimer.stop(); + _blinkState = false; + } + } + if(mode() == Legacy) + _trayIcon->setIcon(stateIcon()); +} + +Icon LegacySystemTray::stateIcon() const { + if(mode() == Legacy && state() == NeedsAttention && !_blinkState) + return SystemTray::stateIcon(Active); + return SystemTray::stateIcon(); +} + +void LegacySystemTray::on_blinkTimeout() { + _blinkState = !_blinkState; + _trayIcon->setIcon(stateIcon()); +} + +void LegacySystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) { + emit activated((ActivationReason)reason); + + if(reason == QSystemTrayIcon::Trigger && !isActivationInhibited()) { + +# ifdef HAVE_KDE + // the slot is private, but meh, who cares :) + QMetaObject::invokeMethod(_trayIcon, "activateOrHide", Q_ARG(QSystemTrayIcon::ActivationReason, QSystemTrayIcon::Trigger)); +# else + QtUi::mainWindow()->toggleMinimizedToTray(); +# endif + + } +} + +void LegacySystemTray::showMessage(const QString &title, const QString &message, SystemTray::MessageIcon icon, int millisecondsTimeoutHint) { + _trayIcon->showMessage(title, message, (QSystemTrayIcon::MessageIcon)icon, millisecondsTimeoutHint); +} + +#endif /* QT_NO_SYSTEMTRAYICON */ diff --git a/src/qtui/legacysystemtray.h b/src/qtui/legacysystemtray.h new file mode 100644 index 00000000..e84a9171 --- /dev/null +++ b/src/qtui/legacysystemtray.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifndef LEGACYSYSTEMTRAY_H_ +#define LEGACYSYSTEMTRAY_H_ + +#ifndef QT_NO_SYSTEMTRAYICON + +#ifdef HAVE_KDE +# include +#else +# include +#endif + +#include + +#include "systemtray.h" + +class LegacySystemTray : public SystemTray { + Q_OBJECT + +public: + LegacySystemTray(QObject *parent = 0); + virtual ~LegacySystemTray() {} + virtual void init(); + + virtual inline bool isSystemTrayAvailable() const; + virtual Icon stateIcon() const; // overriden to care about blinkState + +public slots: + virtual void setState(State state); + virtual void setVisible(bool visible = true); + virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); + +protected: + virtual void setMode(Mode mode); + +private slots: + void on_blinkTimeout(); + void on_activated(QSystemTrayIcon::ActivationReason); + +private: + void syncLegacyIcon(); + + QTimer _blinkTimer; + bool _blinkState; + bool _isVisible; + +#ifdef HAVE_KDE + KSystemTrayIcon *_trayIcon; +#else + QSystemTrayIcon *_trayIcon; +#endif + +}; + +// inlines + +bool LegacySystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSystemTrayAvailable(); } + +#endif /* QT_NO_SYSTEMTRAYICON */ + +#endif /* LEGACYSYSTEMTRAY_H_ */ diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 48b2aa11..d943bfac 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -70,6 +70,7 @@ #include "irclistmodel.h" #include "ircconnectionwizard.h" #include "jumpkeyhandler.h" +#include "legacysystemtray.h" #include "msgprocessorstatuswidget.h" #include "nicklistwidget.h" #include "qtuiapplication.h" @@ -78,7 +79,6 @@ #include "qtuistyle.h" #include "settingsdlg.h" #include "settingspagedlg.h" -#include "systemtray.h" #include "toolbaractionprovider.h" #include "topicwidget.h" #include "verticaldock.h" @@ -279,13 +279,9 @@ void MainWin::restoreStateFromSettings(UiSettings &s) { move(_normalPos); #endif -#ifndef QT_NO_SYSTEMTRAYICON - if(s.value("MainWinHidden").toBool()) { + if(s.value("MainWinHidden").toBool()) hideToTray(); - return; - } -#endif - if(s.value("MainWinMinimized").toBool()) + else if(s.value("MainWinMinimized").toBool()) showMinimized(); else if(maximized) showMaximized(); @@ -685,8 +681,11 @@ void MainWin::saveStatusBarStatus(bool enabled) { void MainWin::setupSystray() { #ifndef QT_NO_SYSTEMTRAYICON - _systemTray = new SystemTray(this); + _systemTray = new LegacySystemTray(this); +#else + _systemTray = new SystemTray(this); // dummy #endif + _systemTray->init(); } void MainWin::setupToolBars() { @@ -818,9 +817,7 @@ void MainWin::setDisconnectedState() { if(_msgProcessorStatusWidget) _msgProcessorStatusWidget->setProgress(0, 0); updateIcon(); -#ifndef QT_NO_SYSTEMTRAYICON - systemTray()->setState(SystemTray::Inactive); -#endif + systemTray()->setState(SystemTray::Passive); } void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) { @@ -1040,15 +1037,13 @@ void MainWin::changeEvent(QEvent *event) { QMainWindow::changeEvent(event); } -#ifndef QT_NO_SYSTEMTRAYICON - void MainWin::hideToTray() { if(!systemTray()->isSystemTrayAvailable()) { qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!"; return; } hide(); - systemTray()->setIconVisible(); + systemTray()->setVisible(); } void MainWin::toggleMinimizedToTray() { @@ -1074,8 +1069,6 @@ void MainWin::toggleMinimizedToTray() { #endif } -#endif /* QT_NO_SYSTEMTRAYICON */ - void MainWin::forceActivated() { #ifdef HAVE_KDE show(); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 010a1bc7..4929e5c9 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -76,10 +76,7 @@ class MainWin BufferView *allBuffersView() const; inline BufferWidget *bufferWidget() const { return _bufferWidget; } - -#ifndef QT_NO_SYSTEMTRAYICON inline SystemTray *systemTray() const { return _systemTray; } -#endif bool event(QEvent *event); @@ -91,10 +88,7 @@ class MainWin public slots: void showStatusBarMessage(const QString &message); - -#ifndef QT_NO_SYSTEMTRAYICON void toggleMinimizedToTray(); -#endif //! Bring window to front and focus it void forceActivated(); @@ -174,6 +168,7 @@ class MainWin MsgProcessorStatusWidget *_msgProcessorStatusWidget; CoreConnectionStatusWidget *_coreConnectionStatusWidget; + SystemTray *_systemTray; TitleSetter _titleSetter; @@ -193,10 +188,7 @@ class MainWin void updateIcon(); void enableMenus(); -#ifndef QT_NO_SYSTEMTRAYICON void hideToTray(); - SystemTray *_systemTray; -#endif QList _bufferViews; BufferWidget *_bufferWidget; diff --git a/src/qtui/systemtray.cpp b/src/qtui/systemtray.cpp index 8c346550..9944823e 100644 --- a/src/qtui/systemtray.cpp +++ b/src/qtui/systemtray.cpp @@ -1,61 +1,57 @@ /*************************************************************************** -* 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. * -***************************************************************************/ - -#ifndef QT_NO_SYSTEMTRAYICON - + * 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 "systemtray.h" #include "actioncollection.h" +#include "client.h" #include "iconloader.h" #include "qtui.h" #include "qtuisettings.h" SystemTray::SystemTray(QObject *parent) : QObject(parent), - _state(Inactive), - _alert(false), + _mode(Invalid), + _state(Passive), _inhibitActivation(false), - _currentIdx(0) + _passiveIcon(DesktopIcon("quassel_inactive")), + _activeIcon(DesktopIcon("quassel")), + _needsAttentionIcon(DesktopIcon("quassel_message")), + _trayMenu(0) { - loadAnimations(); - _currentIdx = _idxOffEnd; + qApp->installEventFilter(this); +} -#ifndef HAVE_KDE - _trayIcon = new QSystemTrayIcon(_phases.at(_currentIdx), QtUi::mainWindow()); -#else - _trayIcon = new KSystemTrayIcon(_phases.at(_currentIdx), QtUi::mainWindow()); - // We don't want to trigger a minimize if a highlight is pending, so we brutally remove the internal connection for that - disconnect(_trayIcon, SIGNAL(activated( QSystemTrayIcon::ActivationReason)), - _trayIcon, SLOT(activateOrHide(QSystemTrayIcon::ActivationReason))); -#endif - - _animationTimer.setInterval(150); - _animationTimer.setSingleShot(false); - connect(&_animationTimer, SIGNAL(timeout()), SLOT(nextPhase())); +SystemTray::~SystemTray() { + _trayMenu->deleteLater(); +} - ActionCollection *coll = QtUi::actionCollection("General"); - _trayMenu = _trayIcon->contextMenu(); - if (!_trayMenu) +void SystemTray::setTrayMenu(QMenu *menu) { + if(menu) + _trayMenu = menu; + else _trayMenu = new QMenu(); + + ActionCollection *coll = QtUi::actionCollection("General"); + _trayMenu->addAction(coll->action("ConnectCore")); _trayMenu->addAction(coll->action("DisconnectCore")); _trayMenu->addAction(coll->action("CoreInfo")); @@ -64,113 +60,63 @@ SystemTray::SystemTray(QObject *parent) _trayMenu->addAction(coll->action("Quit")); #endif /* HAVE_KDE */ - _trayIcon->setContextMenu(_trayMenu); - - QtUiSettings s; - if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) { - _trayIcon->show(); - } - - qApp->installEventFilter(this); - -#ifndef Q_WS_MAC - connect(_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(on_activated(QSystemTrayIcon::ActivationReason))); -#endif - connect(_trayIcon, SIGNAL(messageClicked()), SIGNAL(messageClicked())); } -SystemTray::~SystemTray() { - _trayMenu->deleteLater(); +void SystemTray::setMode(Mode mode_) { + if(mode_ != _mode) { + _mode = mode_; + if(_mode == Legacy) { + _trayMenu->setWindowFlags(Qt::Popup); + } else { + _trayMenu->setWindowFlags(Qt::Window); + } + } } -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 - - _phases.clear(); - -#ifdef HAVE_KDE - KIconLoader *loader = KIconLoader::global(); -#else - IconLoader *loader = IconLoader::global(); -#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; - - 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; - - QString alertName("quassel_tray-alert-%1"); - for(int i = 1; i <= 10; i++) - _phases.append(loader->loadIcon(alertName.arg(i), IconLoader::Panel, size)); +Icon SystemTray::stateIcon() const { + return stateIcon(state()); } -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; +Icon SystemTray::stateIcon(State state) const { + switch(state) { + case Passive: + return _passiveIcon; + case Active: + return _activeIcon; + case NeedsAttention: + return _needsAttentionIcon; } - - _trayIcon->setIcon(_phases.at(_currentIdx)); - - if(_alert) - return; - - if((_state == Active && _currentIdx == _idxOnEnd) || (_state == Inactive && _currentIdx == _idxOffEnd)) - _animationTimer.stop(); + 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 &tip) { - _trayIcon->setToolTip(tip); +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, QSystemTrayIcon::MessageIcon icon, int millisecondsTimeoutHint) { - _trayIcon->showMessage(title, message, icon, millisecondsTimeoutHint); +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) } bool SystemTray::eventFilter(QObject *obj, QEvent *event) { @@ -180,20 +126,3 @@ bool SystemTray::eventFilter(QObject *obj, QEvent *event) { } return false; } - -void SystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) { - emit activated(reason); - - if(reason == QSystemTrayIcon::Trigger && !_inhibitActivation) { - -# ifdef HAVE_KDE - // the slot is private, but meh, who cares :) - QMetaObject::invokeMethod(_trayIcon, "activateOrHide", Q_ARG(QSystemTrayIcon::ActivationReason, QSystemTrayIcon::Trigger)); -# else - QtUi::mainWindow()->toggleMinimizedToTray(); -# endif - - } -} - -#endif /* QT_NO_SYSTEMTRAYICON */ diff --git a/src/qtui/systemtray.h b/src/qtui/systemtray.h index cdb66d7d..b2b0afba 100644 --- a/src/qtui/systemtray.h +++ b/src/qtui/systemtray.h @@ -1,102 +1,125 @@ /*************************************************************************** -* 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. * + ***************************************************************************/ #ifndef SYSTEMTRAY_H_ #define SYSTEMTRAY_H_ -#ifndef QT_NO_SYSTEMTRAYICON - -#ifdef HAVE_KDE -# include -#else -# include -#endif - -#include - #include "icon.h" +class QMenu; + class SystemTray : public QObject { Q_OBJECT public: enum State { - Inactive, - Active + Passive, + Active, + NeedsAttention + }; + + enum Mode { + Invalid, + Legacy, + StatusNotifier + }; + + // same as in QSystemTrayIcon + enum MessageIcon { + NoIcon, + Information, + Warning, + Critical + }; + + // same as in QSystemTrayIcon + enum ActivationReason { + Unknown, + Context, + DoubleClick, + Trigger, + MiddleClick }; SystemTray(QObject *parent = 0); - ~SystemTray(); + virtual ~SystemTray(); + virtual void init() {} - inline bool isSystemTrayAvailable() const; + inline State state() const; inline bool isAlerted() const; + virtual inline bool isSystemTrayAvailable() const; + void setAlert(bool alerted); inline void setInhibitActivation(); + inline bool isActivationInhibited() const; public slots: - void setState(State); - void setAlert(bool alert = true); - void setIconVisible(bool visible = true); - void setToolTip(const QString &tip); - void showMessage(const QString &title, const QString &message, - QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int millisecondsTimeoutHint = 10000); + virtual void setState(State); + virtual void setVisible(bool visible = true); + virtual void setToolTip(const QString &title, const QString &subtitle); + virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); signals: - void activated(QSystemTrayIcon::ActivationReason); + void activated(SystemTray::ActivationReason); void iconChanged(const Icon &); + void toolTipChanged(const QString &title, const QString &subtitle); void messageClicked(); protected: - bool eventFilter(QObject *obj, QEvent *event); + virtual void setMode(Mode mode); + inline Mode mode() const; -private slots: - void nextPhase(); - void on_activated(QSystemTrayIcon::ActivationReason); + virtual Icon stateIcon() const; + Icon stateIcon(State state) const; + inline QString toolTipTitle() const; + inline QString toolTipSubTitle() const; + inline QMenu *trayMenu() const; + void setTrayMenu(QMenu *); -private: - void loadAnimations(); + virtual bool eventFilter(QObject *obj, QEvent *event); -#ifdef HAVE_KDE - KSystemTrayIcon *_trayIcon; -#else - QSystemTrayIcon *_trayIcon; -#endif +private slots: - QMenu *_trayMenu; +private: + Mode _mode; State _state; - bool _alert; + bool _inhibitActivation; - int _idxOffStart, _idxOffEnd, _idxOnStart, _idxOnEnd, _idxAlertStart; - int _currentIdx; - QTimer _animationTimer; + QString _toolTipTitle, _toolTipSubTitle; + Icon _passiveIcon, _activeIcon, _needsAttentionIcon; - QList _phases; + QMenu *_trayMenu; }; // inlines -bool SystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSystemTrayAvailable(); } -bool SystemTray::isAlerted() const { return _alert; } +bool SystemTray::isSystemTrayAvailable() const { return false; } +bool SystemTray::isAlerted() const { return state() == NeedsAttention; } void SystemTray::setInhibitActivation() { _inhibitActivation = true; } +bool SystemTray::isActivationInhibited() const { return _inhibitActivation; } +SystemTray::Mode SystemTray::mode() const { return _mode; } +SystemTray::State SystemTray::state() const { return _state; } +QMenu *SystemTray::trayMenu() const { return _trayMenu; } +QString SystemTray::toolTipTitle() const { return _toolTipTitle; } +QString SystemTray::toolTipSubTitle() const { return _toolTipSubTitle; } -#endif /* QT_NO_SYSTEMTRAYICON */ #endif diff --git a/src/qtui/systraynotificationbackend.cpp b/src/qtui/systraynotificationbackend.cpp index 1c97d4f5..7a8f9930 100644 --- a/src/qtui/systraynotificationbackend.cpp +++ b/src/qtui/systraynotificationbackend.cpp @@ -1,24 +1,22 @@ /*************************************************************************** -* 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. * -***************************************************************************/ - -#ifndef QT_NO_SYSTEMTRAYICON + * 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 "systraynotificationbackend.h" @@ -43,8 +41,8 @@ SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent) notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &))); connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated())); - connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - SLOT(notificationActivated(QSystemTrayIcon::ActivationReason))); + connect(QtUi::mainWindow()->systemTray(), SIGNAL(activated(SystemTray::ActivationReason)), + SLOT(notificationActivated(SystemTray::ActivationReason))); } void SystrayNotificationBackend::notify(const Notification ¬ification) { @@ -88,7 +86,7 @@ void SystrayNotificationBackend::showBubble() { void SystrayNotificationBackend::closeBubble() { // there really seems to be no sane way to close the bubble... :( #ifdef Q_WS_X11 - QtUi::mainWindow()->systemTray()->showMessage("", "", QSystemTrayIcon::NoIcon, 1); + QtUi::mainWindow()->systemTray()->showMessage("", "", SystemTray::NoIcon, 1); #endif } @@ -100,8 +98,8 @@ void SystrayNotificationBackend::notificationActivated() { } } -void SystrayNotificationBackend::notificationActivated(QSystemTrayIcon::ActivationReason reason) { - if(reason == QSystemTrayIcon::Trigger) { +void SystrayNotificationBackend::notificationActivated(SystemTray::ActivationReason reason) { + if(reason == SystemTray::Trigger) { notificationActivated(); } } @@ -165,5 +163,3 @@ void SystrayNotificationBackend::ConfigWidget::save() { s.setValue("Systray/ShowBubble", _showBubbleBox->isChecked()); load(); } - -#endif /* QT_NO_SYSTEMTRAYICON */ diff --git a/src/qtui/systraynotificationbackend.h b/src/qtui/systraynotificationbackend.h index 7fdf4e8e..c96958dd 100644 --- a/src/qtui/systraynotificationbackend.h +++ b/src/qtui/systraynotificationbackend.h @@ -1,33 +1,29 @@ /*************************************************************************** -* 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. * + ***************************************************************************/ #ifndef SYSTRAYNOTIFICATIONBACKEND_H_ #define SYSTRAYNOTIFICATIONBACKEND_H_ -#ifndef QT_NO_SYSTEMTRAYICON - -#include - #include "abstractnotificationbackend.h" - #include "settingspage.h" +#include "systemtray.h" class QCheckBox; @@ -45,7 +41,7 @@ private slots: void showBubble(); void closeBubble(); void notificationActivated(); - void notificationActivated(QSystemTrayIcon::ActivationReason); + void notificationActivated(SystemTray::ActivationReason); void animateChanged(const QVariant &); void showBubbleChanged(const QVariant &); @@ -76,6 +72,4 @@ private: bool _showBubble, _animate; }; -#endif /* QT_NO_SYSTEMTRAYICON */ - #endif