cmake: avoid de-duplication of user's CXXFLAGS
[quassel.git] / src / qtui / systemtray.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2022 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This file is free software; you can redistribute it and/or modify     *
6  *   it under the terms of the GNU Library General Public License (LGPL)   *
7  *   as published by the Free Software Foundation; either version 2 of the *
8  *   License, or (at your option) any later version.                       *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include <QObject>
24 #include <QString>
25 #include <QTimer>
26
27 class Action;
28 class QMenu;
29
30 class SystemTray : public QObject
31 {
32     Q_OBJECT
33     Q_ENUMS(State Mode MessageIcon ActivationReason)
34
35 public:
36     enum State
37     {
38         Passive,
39         Active,
40         NeedsAttention
41     };
42
43     enum Mode
44     {
45         Invalid,
46         Legacy,
47         StatusNotifier
48     };
49
50     // same as in QSystemTrayIcon
51     enum MessageIcon
52     {
53         NoIcon,
54         Information,
55         Warning,
56         Critical
57     };
58
59     // same as in QSystemTrayIcon
60     enum ActivationReason
61     {
62         Unknown,
63         Context,
64         DoubleClick,
65         Trigger,
66         MiddleClick
67     };
68
69     enum class AttentionBehavior
70     {
71         DoNothing,
72         ChangeColor,
73         Blink
74     };
75
76     explicit SystemTray(QWidget* parent);
77     ~SystemTray() override;
78
79     Mode mode() const;
80     State state() const;
81     bool isVisible() const;
82     bool isAlerted() const;
83
84     virtual bool isSystemTrayAvailable() const;
85
86     QWidget* associatedWidget() const;
87
88 public slots:
89     void setVisible(bool visible = true);
90     void setState(State);
91     void setAlert(bool alerted);
92
93     void setToolTip(const QString& title, const QString& subtitle);
94     virtual void showMessage(
95         const QString& title, const QString& message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0);
96     virtual void closeMessage(uint notificationId);
97
98 signals:
99     void modeChanged(Mode mode);
100     void stateChanged(State state);
101     void visibilityChanged(bool isVisible);
102     void iconsChanged();
103     void currentIconNameChanged();
104     void toolTipChanged(const QString& title, const QString& subtitle);
105
106     void activated(SystemTray::ActivationReason);
107     void messageClicked(uint notificationId);
108     void messageClosed(uint notificationId);
109
110 protected slots:
111     virtual void activate(SystemTray::ActivationReason = Trigger);
112
113 protected:
114     void setMode(Mode mode);
115
116     QString toolTipTitle() const;
117     QString toolTipSubTitle() const;
118     QMenu* trayMenu() const;
119
120     QString iconName(State state) const;
121     QString currentIconName() const;
122     QString currentAttentionIconName() const;
123
124 private slots:
125     void minimizeRestore();
126     void trayMenuAboutToShow();
127     void invertTrayIconChanged(const QVariant&);
128     void enableChangeColorChanged(const QVariant&);
129     void enableBlinkChanged(const QVariant&);
130
131     void onBlinkTimeout();
132
133 private:
134     bool _isVisible{false};
135     Mode _mode{Mode::Invalid};
136     State _state{State::Passive};
137     bool _trayIconInverted{false};
138     AttentionBehavior _attentionBehavior{AttentionBehavior::ChangeColor};
139
140     QTimer _blinkTimer;
141     bool _blinkState{false};
142
143     QString _toolTipTitle;
144     QString _toolTipSubTitle;
145
146     QMenu* _trayMenu{nullptr};
147     QWidget* _associatedWidget{nullptr};
148     Action* _minimizeRestoreAction{nullptr};
149 };