X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsystemtray.h;h=c5fee1994b32a0b88012dd0550a39b79e503cc42;hp=d610c48ea05c67036d133106af7aeb11da71463a;hb=ddfb1d2574c4bffd180361a80df9b1cd584bb040;hpb=d452877910888c25d40590b5fff57eb8197ca9b0 diff --git a/src/qtui/systemtray.h b/src/qtui/systemtray.h index d610c48e..c5fee199 100644 --- a/src/qtui/systemtray.h +++ b/src/qtui/systemtray.h @@ -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,134 +15,129 @@ * 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. * ***************************************************************************/ -#ifndef SYSTEMTRAY_H_ -#define SYSTEMTRAY_H_ +#pragma once -#include "icon.h" - -#ifdef Q_WS_WIN -# include -#endif +#include +#include +#include +class Action; class QMenu; -class SystemTray : public QObject { - Q_OBJECT - Q_ENUMS(State Mode MessageIcon ActivationReason) +class SystemTray : public QObject +{ + Q_OBJECT + Q_ENUMS(State Mode MessageIcon ActivationReason) public: - enum State { - 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 - }; - - explicit SystemTray(QWidget *parent); - virtual ~SystemTray(); - virtual void init() {} - - inline State state() const; - inline bool isAlerted() const; - virtual inline bool isSystemTrayAvailable() const; - - void setAlert(bool alerted); - inline void setInhibitActivation(); - inline virtual bool isVisible() const { return false; } - inline bool isActivationInhibited() const; - - QWidget *associatedWidget() const; + enum State { + 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 + }; + + enum class AttentionBehavior { + DoNothing, + ChangeColor, + Blink + }; + + explicit SystemTray(QWidget *parent); + ~SystemTray() override; + + Mode mode() const; + State state() const; + bool isVisible() const; + bool isAlerted() const; + + virtual bool isSystemTrayAvailable() const; + + QWidget *associatedWidget() const; public slots: - 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); - void toggleMainWidget(); - void hideMainWidget(); + void setVisible(bool visible = true); + void setState(State); + void setAlert(bool alerted); + + void setToolTip(const QString &title, const QString &subtitle); + virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0); + virtual void closeMessage(uint notificationId); signals: - void activated(SystemTray::ActivationReason); - void iconChanged(const Icon &); - void toolTipChanged(const QString &title, const QString &subtitle); - void messageClicked(); + void modeChanged(Mode mode); + void stateChanged(State state); + void visibilityChanged(bool isVisible); + void iconsChanged(); + void currentIconNameChanged(); + void toolTipChanged(const QString &title, const QString &subtitle); -protected slots: - virtual void activate(SystemTray::ActivationReason = Trigger); + void activated(SystemTray::ActivationReason); + void messageClicked(uint notificationId); + void messageClosed(uint notificationId); - void minimizeRestore(bool restore); +protected slots: + virtual void activate(SystemTray::ActivationReason = Trigger); protected: - virtual void setMode(Mode mode); - inline Mode mode() const; + void setMode(Mode mode); - virtual Icon stateIcon() const; - Icon stateIcon(State state) const; - inline QString toolTipTitle() const; - inline QString toolTipSubTitle() const; - inline QMenu *trayMenu() const; - void setTrayMenu(QMenu *); + QString toolTipTitle() const; + QString toolTipSubTitle() const; + QMenu *trayMenu() const; - virtual bool eventFilter(QObject *obj, QEvent *event); + QString iconName(State state) const; + QString currentIconName() const; + QString currentAttentionIconName() const; private slots: + void minimizeRestore(); + void trayMenuAboutToShow(); + void invertTrayIconChanged(const QVariant &); + void enableChangeColorChanged(const QVariant &); + void enableBlinkChanged(const QVariant &); -private: - bool checkVisibility(bool performToggle = true); - - Mode _mode; - State _state; + void onBlinkTimeout(); - bool _inhibitActivation; - - QString _toolTipTitle, _toolTipSubTitle; - Icon _passiveIcon, _activeIcon, _needsAttentionIcon; +private: + bool _isVisible{false}; + Mode _mode{Mode::Invalid}; + State _state{State::Passive}; + bool _trayIconInverted{false}; + AttentionBehavior _attentionBehavior{AttentionBehavior::ChangeColor}; - QMenu *_trayMenu; - QWidget *_associatedWidget; + QTimer _blinkTimer; + bool _blinkState{false}; -#ifdef Q_WS_WIN - DWORD _dwTickCount; -#endif + QString _toolTipTitle; + QString _toolTipSubTitle; + QMenu *_trayMenu{nullptr}; + QWidget *_associatedWidget{nullptr}; + Action *_minimizeRestoreAction{nullptr}; }; - -// inlines - -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