1 | /*************************************************************************** |
2 | * Copyright (C) 2005-2014 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 | #ifndef SYSTEMTRAY_H_ |
22 | #define SYSTEMTRAY_H_ |
23 | |
24 | #include "icon.h" |
25 | |
26 | class Action; |
27 | class ; |
28 | |
29 | class SystemTray : public QObject |
30 | { |
31 | Q_OBJECT |
32 | Q_ENUMS(State Mode MessageIcon ActivationReason) |
33 | |
34 | public : |
35 | enum State { |
36 | Passive, |
37 | Active, |
38 | NeedsAttention |
39 | }; |
40 | |
41 | enum Mode { |
42 | Invalid, |
43 | Legacy, |
44 | StatusNotifier |
45 | }; |
46 | |
47 | // same as in QSystemTrayIcon |
48 | enum MessageIcon { |
49 | NoIcon, |
50 | Information, |
51 | Warning, |
52 | Critical |
53 | }; |
54 | |
55 | // same as in QSystemTrayIcon |
56 | enum ActivationReason { |
57 | Unknown, |
58 | Context, |
59 | DoubleClick, |
60 | Trigger, |
61 | MiddleClick |
62 | }; |
63 | |
64 | explicit SystemTray(QWidget *parent); |
65 | virtual ~SystemTray(); |
66 | virtual void init(); |
67 | |
68 | inline Mode mode() const; |
69 | inline State state() const; |
70 | inline bool isAlerted() const; |
71 | virtual inline bool isSystemTrayAvailable() const; |
72 | |
73 | void setAlert(bool alerted); |
74 | virtual inline bool isVisible() const { return false; } |
75 | |
76 | QWidget *associatedWidget() const; |
77 | |
78 | public slots: |
79 | virtual void setState(State); |
80 | virtual void setVisible(bool visible = true); |
81 | virtual void setToolTip(const QString &title, const QString &subtitle); |
82 | virtual void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int msTimeout = 10000, uint notificationId = 0); |
83 | virtual void closeMessage(uint notificationId) { Q_UNUSED(notificationId) } |
84 | |
85 | signals: |
86 | void activated(SystemTray::ActivationReason); |
87 | void iconChanged(const Icon &); |
88 | void animationEnabledChanged(bool); |
89 | void toolTipChanged(const QString &title, const QString &subtitle); |
90 | void messageClicked(uint notificationId); |
91 | void messageClosed(uint notificationId); |
92 | |
93 | protected slots: |
94 | virtual void activate(SystemTray::ActivationReason = Trigger); |
95 | |
96 | protected: |
97 | virtual void setMode(Mode mode); |
98 | inline bool shouldBeVisible() const; |
99 | |
100 | virtual Icon stateIcon() const; |
101 | Icon stateIcon(State state) const; |
102 | inline QString toolTipTitle() const; |
103 | inline QString toolTipSubTitle() const; |
104 | inline QMenu *trayMenu() const; |
105 | |
106 | inline bool animationEnabled() const; |
107 | |
108 | private slots: |
109 | void minimizeRestore(); |
110 | void (); |
111 | void enableAnimationChanged(const QVariant &); |
112 | |
113 | private: |
114 | Mode _mode; |
115 | State _state; |
116 | bool _shouldBeVisible; |
117 | |
118 | QString _toolTipTitle, _toolTipSubTitle; |
119 | Icon _passiveIcon, _activeIcon, _needsAttentionIcon; |
120 | bool _animationEnabled; |
121 | |
122 | QMenu *; |
123 | QWidget *_associatedWidget; |
124 | Action *_minimizeRestoreAction; |
125 | }; |
126 | |
127 | |
128 | // inlines |
129 | |
130 | bool SystemTray::isSystemTrayAvailable() const { return false; } |
131 | bool SystemTray::isAlerted() const { return state() == NeedsAttention; } |
132 | SystemTray::Mode SystemTray::mode() const { return _mode; } |
133 | SystemTray::State SystemTray::state() const { return _state; } |
134 | bool SystemTray::shouldBeVisible() const { return _shouldBeVisible; } |
135 | QMenu *SystemTray::() const { return _trayMenu; } |
136 | QString SystemTray::toolTipTitle() const { return _toolTipTitle; } |
137 | QString SystemTray::toolTipSubTitle() const { return _toolTipSubTitle; } |
138 | bool SystemTray::animationEnabled() const { return _animationEnabled; } |
139 | |
140 | #endif |
141 | |