X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsystemtray.h;h=b27d81ca375d4e0a935b80ba60e729221449c373;hp=1e811cd8cea76a386e415abbbe814d23f4d1e59b;hb=3cc8b9030841cc3084ec6707a01f3b44ee58b8b9;hpb=5a470c1acab34c95d957bf81dce7e7cd330a2c58 diff --git a/src/qtui/systemtray.h b/src/qtui/systemtray.h index 1e811cd8..b27d81ca 100644 --- a/src/qtui/systemtray.h +++ b/src/qtui/systemtray.h @@ -1,81 +1,124 @@ /*************************************************************************** -* 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_ - -#include -#include - -#include "icon.h" - -class SystemTray : public QObject { - Q_OBJECT + * 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 + +class Action; +class QMenu; + +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; - Icon icon() const; - QString toolTip() 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 + }; + + explicit SystemTray(QWidget *parent); + ~SystemTray() override; + virtual void init(); + + Mode mode() const; + State state() const; + bool isAlerted() const; + void setAlert(bool alerted); + + virtual bool isVisible() 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); - + 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 msTimeout = 10000, uint notificationId = 0); + virtual void closeMessage(uint notificationId); signals: - void activated(QSystemTrayIcon::ActivationReason); - void iconChanged(const Icon &); - void messageClicked(); + void activated(SystemTray::ActivationReason); + void iconChanged(const QIcon &icon); + void animationEnabledChanged(bool); + void toolTipChanged(const QString &title, const QString &subtitle); + void messageClicked(uint notificationId); + void messageClosed(uint notificationId); -private slots: - void nextPhase(); +protected slots: + virtual void activate(SystemTray::ActivationReason = Trigger); -private: - void loadAnimations(); +protected: + virtual void setMode(Mode mode); + bool shouldBeVisible() const; - QSystemTrayIcon *_trayIcon; - QMenu *_trayMenu; - State _state; - bool _alert; + virtual QIcon stateIcon() const; + QIcon stateIcon(State state) const; + QString toolTipTitle() const; + QString toolTipSubTitle() const; + QMenu *trayMenu() const; - int _idxOffStart, _idxOffEnd, _idxOnStart, _idxOnEnd, _idxAlertStart; - int _currentIdx; - QTimer _animationTimer; + bool animationEnabled() const; - QList _phases; -}; +private slots: + void minimizeRestore(); + void trayMenuAboutToShow(); + void enableAnimationChanged(const QVariant &); -// inlines +private: + Mode _mode{Mode::Invalid}; + State _state{State::Passive}; + bool _shouldBeVisible{true}; + bool _animationEnabled{true}; -bool SystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSystemTrayAvailable(); } + QString _toolTipTitle, _toolTipSubTitle; + QIcon _passiveIcon, _activeIcon, _needsAttentionIcon; -#endif + QMenu *_trayMenu{nullptr}; + QWidget *_associatedWidget{nullptr}; + Action *_minimizeRestoreAction{nullptr}; +};