-
Notifications
You must be signed in to change notification settings - Fork 50
/
lxqtnotification.h
211 lines (182 loc) · 6.32 KB
/
lxqtnotification.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
* https://lxqt.org
*
* Copyright (C) 2012 Alec Moskvin <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef LXQTNOTIFICATION_H
#define LXQTNOTIFICATION_H
#include <QObject>
#include <QStringList>
#include "lxqtglobals.h"
namespace LXQt
{
class NotificationPrivate;
/**
* \brief Libnotify-style desktop notifications
*
* Spec: http://developer.gnome.org/notification-spec
*/
class LXQT_API Notification : public QObject
{
Q_OBJECT
public:
/*!
* \brief Notification is an object that represents a single notification.
* \param summary Summary text briefly describing the notification (required by the spec)
*/
Notification(const QString& summary = QString(), QObject* parent = nullptr);
~Notification() override;
enum CloseReason
{
//! The notification expired.
Expired = 1,
//! The notification was dismissed by the user.
Dismissed = 2,
//! The notification was closed by a call to close().
ForceClosed = 3,
//! Undefined/reserved reasons.
Unknown = 4
};
enum Urgency
{
UrgencyLow = 0,
UrgencyNormal = 1,
UrgencyCritical = 2
};
struct ServerInfo
{
//! The product name of the server.
QString name;
//! The vendor name. For example, "lxqt.org"
QString vendor;
//! The server's version number.
QString version;
//! The specification version the server is compliant with.
QString specVersion;
};
/*!
* \brief Set the summary text briefly describing the notification
*/
void setSummary(const QString& summary);
/*!
* \brief Set the detailed body text
*/
void setBody(const QString& body);
/*!
* \brief Set an icon to display
* \param iconName Name of the icon
*/
void setIcon(const QString& iconName);
/*!
* \brief Set action buttons for the notification. Whenever an action is
* activated, the actionActivated() signal is emitted with the list
* index of the activated action.
* \param actions List of action button titles
* \param defaultAction Index of the default action which gets activated
* when the notification body is clicked
* \sa actionActivated()
*/
void setActions(const QStringList& actions, int defaultAction = -1);
/*!
* \brief Set the timeout for the notification
* \param timeout Milliseconds for timeout, or zero to never time out.
*/
void setTimeout(int timeout);
/*!
* \brief Set notification hint.
* \note For description of Hints, see http://developer.gnome.org/notification-spec/#hints
* \note For D-Bus-to-Qt mappings, see https://qt-project.org/doc/qdbustypesystem.html
* \param hint Hint name
* \param value The hint data
*/
void setHint(const QString& hint, const QVariant& value);
/*!
* \brief Set the "urgency" hint
* \param urgency
*/
void setUrgencyHint(Urgency urgency);
/*!
* \brief Remove all hints that were set
* \sa setHint()
*/
void clearHints();
/*!
* \brief returns a list of optional capabilities supported by the server.
* For the list, see http://developer.gnome.org/notification-spec/#commands
*/
QStringList getCapabilities();
/*!
* \brief Returns information about the notifications server
* \note This call may block for up to 25s (default dbus timeout) if the notification server
* is not running and the info wasn't previously queried.
* \sa queryServerInfo()
*/
const ServerInfo serverInfo();
/*!
* \brief Performs an asyncronous query of the notifications server information.
* Use serverInfoReady signal to get notified (no pun intended) when the
* info will be received.
* \sa serverInfo()
* \sa serverInfoReady()
*/
void queryServerInfo();
/*!
* \brief Convenience function to create and display a notification for the most common
* cases. For anything more complex, create a Notification object, set the
* desired properties and call update(). (That's what this does internally.)
* \sa Notification()
*/
static void notify(const QString& summary,
const QString& body = QString(),
const QString& iconName = QString()
);
public Q_SLOTS:
/*!
* \brief Display the notification or update it if it's already visible
*/
void update();
/*!
* \brief Causes a notification to be forcefully closed and removed from the user's view.
* It can be used, for example, in the event that what the notification pertains to
* is no longer relevant, or to cancel a notification with no expiration time.
*/
void close();
Q_SIGNALS:
/*!
* \brief Emitted when the notification is closed
* \param reason How notification was closed
*/
void notificationClosed(LXQt::Notification::CloseReason reason);
/*!
* \brief Emitted when an action button is activated.
* \param actionNumber Index of the actions array for the activated button.
* \sa setActions()
*/
void actionActivated(int actionNumber);
/*!
* \brief Emitted when queried server info is received
* \sa queryServerInfo()
*/
void serverInfoReady();
private:
Q_DECLARE_PRIVATE(Notification)
NotificationPrivate* const d_ptr;
};
} // namespace LXQt
#endif // LXQTNOTIFICATION_H