modernize: Prefer default member init over ctor init
[quassel.git] / src / qtui / systemtray.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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         Passive,
38         Active,
39         NeedsAttention
40     };
41
42     enum Mode {
43         Invalid,
44         Legacy,
45         StatusNotifier
46     };
47
48     // same as in QSystemTrayIcon
49     enum MessageIcon {
50         NoIcon,
51         Information,
52         Warning,
53         Critical
54     };
55
56     // same as in QSystemTrayIcon
57     enum ActivationReason {
58         Unknown,
59         Context,
60         DoubleClick,
61         Trigger,
62         MiddleClick
63     };
64
65     enum class AttentionBehavior {
66         DoNothing,
67         ChangeColor,
68         Blink
69     };
70
71     explicit SystemTray(QWidget *parent);
72     ~SystemTray() override;
73
74     Mode mode() const;
75     State state() const;
76     bool isVisible() const;
77     bool isAlerted() const;
78
79     virtual bool isSystemTrayAvailable() const;
80
81     QWidget *associatedWidget() const;
82
83 public slots:
84     void setVisible(bool visible = true);
85     void setState(State);
86     void setAlert(bool alerted);
87
88     void setToolTip(const QString &title, const QString &subtitle);
89     virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0);
90     virtual void closeMessage(uint notificationId);
91
92 signals:
93     void modeChanged(Mode mode);
94     void stateChanged(State state);
95     void visibilityChanged(bool isVisible);
96     void iconsChanged();
97     void currentIconNameChanged();
98     void toolTipChanged(const QString &title, const QString &subtitle);
99
100     void activated(SystemTray::ActivationReason);
101     void messageClicked(uint notificationId);
102     void messageClosed(uint notificationId);
103
104 protected slots:
105     virtual void activate(SystemTray::ActivationReason = Trigger);
106
107 protected:
108     void setMode(Mode mode);
109
110     QString toolTipTitle() const;
111     QString toolTipSubTitle() const;
112     QMenu *trayMenu() const;
113
114     QString iconName(State state) const;
115     QString currentIconName() const;
116     QString currentAttentionIconName() const;
117
118 private slots:
119     void minimizeRestore();
120     void trayMenuAboutToShow();
121     void invertTrayIconChanged(const QVariant &);
122     void enableChangeColorChanged(const QVariant &);
123     void enableBlinkChanged(const QVariant &);
124
125     void onBlinkTimeout();
126
127 private:
128     bool _isVisible{false};
129     Mode _mode{Mode::Invalid};
130     State _state{State::Passive};
131     bool _trayIconInverted{false};
132     AttentionBehavior _attentionBehavior{AttentionBehavior::ChangeColor};
133
134     QTimer _blinkTimer;
135     bool _blinkState{false};
136
137     QString _toolTipTitle;
138     QString _toolTipSubTitle;
139
140     QMenu *_trayMenu{nullptr};
141     QWidget *_associatedWidget{nullptr};
142     Action *_minimizeRestoreAction{nullptr};
143 };