Changeset View
Changeset View
Standalone View
Standalone View
libnotificationmanager/server.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | * Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #pragma once | ||||
22 | | ||||
23 | #include <QObject> | ||||
24 | | ||||
25 | #include "notificationmanager_export.h" | ||||
26 | | ||||
27 | namespace NotificationManager | ||||
28 | { | ||||
29 | | ||||
30 | class Notification; | ||||
31 | | ||||
32 | class ServerPrivate; | ||||
33 | | ||||
34 | /** | ||||
35 | * @short A notification DBus server | ||||
36 | * | ||||
37 | * @author Kai Uwe Broulik <kde@privat.broulik.de> | ||||
38 | **/ | ||||
39 | class NOTIFICATIONMANAGER_EXPORT Server : public QObject | ||||
40 | { | ||||
41 | Q_OBJECT | ||||
42 | | ||||
43 | public: | ||||
44 | ~Server() override; | ||||
45 | | ||||
46 | /** | ||||
47 | * The reason a notification was closed | ||||
48 | */ | ||||
49 | enum class CloseReason { | ||||
50 | Expired = 1, ///< The notification timed out | ||||
51 | DismissedByUser = 2, ///< The user explicitly closed or acknowledged the notification | ||||
52 | Revoked = 3 ///< The notification was revoked by the issuing app because it is no longer relevant | ||||
53 | }; | ||||
54 | Q_ENUM(CloseReason) | ||||
55 | | ||||
56 | static Server &self(); | ||||
57 | | ||||
58 | /** | ||||
59 | * Registers the Notification Service on DBus. | ||||
60 | * | ||||
61 | * @return true if it succeeded, false otherwise. | ||||
62 | */ | ||||
63 | bool init(); | ||||
64 | | ||||
65 | /** | ||||
66 | * Whether the notification service could be registered | ||||
67 | */ | ||||
68 | bool isValid() const; | ||||
69 | | ||||
70 | /** | ||||
71 | * Whether an application requested to inhibit notifications. | ||||
72 | */ | ||||
73 | bool inhibited() const; | ||||
74 | | ||||
75 | // should we return a struct or pair or something? | ||||
76 | QStringList inhibitionApplications() const; | ||||
77 | QStringList inhibitionReasons() const; | ||||
78 | | ||||
79 | /** | ||||
80 | * Remove all inhibitions. | ||||
81 | * | ||||
82 | * @note The applications are not explicitly informed about this. | ||||
83 | */ | ||||
84 | void clearInhibitions(); | ||||
85 | | ||||
86 | /** | ||||
87 | * Sends a notification closed event | ||||
88 | * | ||||
89 | * @param id The notification ID | ||||
90 | * @reason The reason why it was closed | ||||
91 | */ | ||||
92 | void closeNotification(uint id, CloseReason reason); | ||||
93 | /** | ||||
94 | * Sends an action invocation request | ||||
95 | * | ||||
96 | * @param id The notification ID | ||||
97 | * @param actionName The name of the action, e.g. "Action 1", or "default" | ||||
98 | */ | ||||
99 | void invokeAction(uint id, const QString &actionName); | ||||
100 | | ||||
101 | /** | ||||
102 | * Adds a notification | ||||
103 | * | ||||
104 | * @note The notification isn't actually broadcast | ||||
105 | * but just emitted locally. | ||||
106 | * | ||||
107 | * @return the ID of the notification | ||||
108 | */ | ||||
109 | uint add(const Notification ¬ification); | ||||
110 | | ||||
111 | Q_SIGNALS: | ||||
112 | /** | ||||
113 | * Emitted when a notification was added. | ||||
114 | * This is emitted regardless of any filtering rules or user settings. | ||||
115 | * @param notification The notification | ||||
116 | */ | ||||
117 | void notificationAdded(const Notification ¬ification); | ||||
118 | /** | ||||
119 | * Emitted when a notification is supposed to be updated | ||||
120 | * This is emitted regardless of any filtering rules or user settings. | ||||
121 | * @param replacedId The ID of the notification it replaces | ||||
122 | * @param notification The new notification to use instead | ||||
123 | */ | ||||
124 | void notificationReplaced(uint replacedId, const Notification ¬ification); | ||||
125 | /** | ||||
126 | * Emitted when a notification got removed (closed) | ||||
127 | * @param id The notification ID | ||||
128 | * @param reason The reason why it was closed | ||||
129 | */ | ||||
130 | void notificationRemoved(uint id, CloseReason reason); | ||||
131 | | ||||
132 | /** | ||||
133 | * Emitted when inhibitions have been changed. Becomes true | ||||
134 | * as soon as there is one inhibition and becomes false again | ||||
135 | * when all inhibitions have been lifted. | ||||
136 | */ | ||||
137 | void inhibitedChanged(bool inhibited); | ||||
138 | | ||||
139 | /** | ||||
140 | * Emitted when the list of applications holding a notification | ||||
141 | * inhibition changes. | ||||
142 | * Normally you would only want to listen do @c inhibitedChanged | ||||
143 | */ | ||||
144 | void inhibitionApplicationsChanged(); | ||||
145 | | ||||
146 | private: | ||||
147 | explicit Server(QObject *parent = nullptr); | ||||
148 | Q_DISABLE_COPY(Server) | ||||
149 | // FIXME we also need to disable move and other stuff? | ||||
150 | | ||||
151 | QScopedPointer<ServerPrivate> d; | ||||
152 | }; | ||||
153 | | ||||
154 | } // namespace NotificationManager |