X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsystemtray.h;h=c5fee1994b32a0b88012dd0550a39b79e503cc42;hp=cdb66d7dee30cb1a893fa03347e87ac6c38f8b5e;hb=f9efdde7f3a6004af8f834c409cfa6ae1d877692;hpb=d76bb125c8dd275095409edd3426700a98d89f3a diff --git a/src/qtui/systemtray.h b/src/qtui/systemtray.h index cdb66d7d..c5fee199 100644 --- a/src/qtui/systemtray.h +++ b/src/qtui/systemtray.h @@ -1,102 +1,143 @@ /*************************************************************************** -* 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 SYSTEMTRAY_H_ -#define SYSTEMTRAY_H_ - -#ifndef QT_NO_SYSTEMTRAYICON - -#ifdef HAVE_KDE -# include -#else -# include -#endif - + * Copyright (C) 2005-2018 by the Quassel Project * + * devel@quassel-irc.org * + * * + * 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 * + * 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#pragma once + +#include +#include #include -#include "icon.h" +class Action; +class QMenu; -class SystemTray : public QObject { - Q_OBJECT +class SystemTray : public QObject +{ + Q_OBJECT + Q_ENUMS(State Mode MessageIcon ActivationReason) public: - enum State { - Inactive, - Active - }; - - SystemTray(QObject *parent = 0); - ~SystemTray(); - - inline bool isSystemTrayAvailable() const; - inline bool isAlerted() const; - - inline void setInhibitActivation(); + 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: - 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); + 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(QSystemTrayIcon::ActivationReason); - void iconChanged(const Icon &); - 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: - bool eventFilter(QObject *obj, QEvent *event); + void activated(SystemTray::ActivationReason); + void messageClicked(uint notificationId); + void messageClosed(uint notificationId); -private slots: - void nextPhase(); - void on_activated(QSystemTrayIcon::ActivationReason); +protected slots: + virtual void activate(SystemTray::ActivationReason = Trigger); -private: - void loadAnimations(); +protected: + void setMode(Mode mode); -#ifdef HAVE_KDE - KSystemTrayIcon *_trayIcon; -#else - QSystemTrayIcon *_trayIcon; -#endif + QString toolTipTitle() const; + QString toolTipSubTitle() const; + QMenu *trayMenu() const; - QMenu *_trayMenu; - State _state; - bool _alert; - bool _inhibitActivation; + QString iconName(State state) const; + QString currentIconName() const; + QString currentAttentionIconName() const; - int _idxOffStart, _idxOffEnd, _idxOnStart, _idxOnEnd, _idxAlertStart; - int _currentIdx; - QTimer _animationTimer; +private slots: + void minimizeRestore(); + void trayMenuAboutToShow(); + void invertTrayIconChanged(const QVariant &); + void enableChangeColorChanged(const QVariant &); + void enableBlinkChanged(const QVariant &); - QList _phases; -}; + void onBlinkTimeout(); -// inlines +private: + bool _isVisible{false}; + Mode _mode{Mode::Invalid}; + State _state{State::Passive}; + bool _trayIconInverted{false}; + AttentionBehavior _attentionBehavior{AttentionBehavior::ChangeColor}; -bool SystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSystemTrayAvailable(); } -bool SystemTray::isAlerted() const { return _alert; } -void SystemTray::setInhibitActivation() { _inhibitActivation = true; } + QTimer _blinkTimer; + bool _blinkState{false}; -#endif /* QT_NO_SYSTEMTRAYICON */ + QString _toolTipTitle; + QString _toolTipSubTitle; -#endif + QMenu *_trayMenu{nullptr}; + QWidget *_associatedWidget{nullptr}; + Action *_minimizeRestoreAction{nullptr}; +};