Plasma-workspace

server.h
1/*
2 SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include <QObject>
10#include <QQmlEngine>
11
12#include "notificationmanager_export.h"
13#include "notifications.h"
14
15#include <qqmlregistration.h>
16
17namespace NotificationManager
18{
19class Notification;
20
21class ServerInfo;
22class ServerPrivate;
23
24/**
25 * @short A notification DBus server
26 *
27 * @author Kai Uwe Broulik <kde@privat.broulik.de>
28 **/
29class NOTIFICATIONMANAGER_EXPORT Server : public QObject
30{
32 QML_ELEMENT
33 QML_SINGLETON
34
35 /**
36 * Whether the notification service could be registered.
37 * Call @c init() to register.
38 */
40
41 /**
42 * Information about the current owner of the Notification service.
43 *
44 * This can be used to tell the user which application is currently
45 * owning the service in case service registration failed.
46 *
47 * This is never null, even if there is no notification service running.
48 *
49 * @since 5.18
50 */
51 Q_PROPERTY(NotificationManager::ServerInfo *currentOwner READ currentOwner CONSTANT)
52
53 /**
54 * Whether notifications are currently inhibited.
55 *
56 * This is what is announced to other applications on the bus.
57 *
58 * @note This does not keep track of inhibitions on its own,
59 * you need to calculate this yourself and update the property accordingly.
60 */
62
63public:
64 ~Server() override;
65
66 /**
67 * The reason a notification was closed
68 */
69 enum class CloseReason {
70 Expired = 1, ///< The notification timed out
71 DismissedByUser = 2, ///< The user explicitly closed or acknowledged the notification
72 Revoked = 3, ///< The notification was revoked by the issuing app because it is no longer relevant
73 };
74 Q_ENUM(CloseReason)
75
76 static Server &self();
77
78 static Server *create(QQmlEngine *, QJSEngine *);
79
80 /**
81 * Registers the Notification Service on DBus.
82 *
83 * @return true if it succeeded, false otherwise.
84 */
85 bool init();
86
87 /**
88 * Whether the notification service could be registered
89 */
90 bool isValid() const;
91
92 /**
93 * Information about the current owner of the Notification service.
94 * @since 5.18
95 */
96 ServerInfo *currentOwner() const;
97
98 /**
99 * Whether notifications are currently inhibited.
100 * @since 5.17
101 */
102 bool inhibited() const;
103
104 /**
105 * Whether notifications are currently effectively inhibited.
106 *
107 * @note You need to keep track of inhibitions and call this
108 * yourself when appropriate.
109 * @since 5.17
110 */
111 void setInhibited(bool inhibited);
112
113 /**
114 * Whether an application requested to inhibit notifications.
115 */
116 bool inhibitedByApplication() const;
117
118 // should we return a struct or pair or something?
119 QStringList inhibitionApplications() const;
120 QStringList inhibitionReasons() const;
121
122 /**
123 * Remove all inhibitions.
124 *
125 * @note The applications are not explicitly informed about this.
126 */
127 void clearInhibitions();
128
129 /**
130 * Sends a notification closed event
131 *
132 * @param id The notification ID
133 * @param reason The reason why it was closed
134 */
135 void closeNotification(uint id, CloseReason reason);
136 /**
137 * Sends an action invocation request
138 *
139 * @param id The notification ID
140 * @param actionName The name of the action, e.g. "Action 1", or "default"
141 * @param xdgActivationToken The token the application needs to send to raise itself.
142 * @param window the window that invokes the action
143 */
144 void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior, QWindow *window);
145
146 /**
147 * Convenience call to maintain ABI
148 *
149 * @deprecated
150 */
151 void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior)
152 {
153 invokeAction(id, actionName, xdgActivationToken, behavior, nullptr);
154 }
155
156 /**
157 * Sends a notification reply text
158 *
159 * @param dbusService The bus name of the receiving application
160 * @param id The notification ID
161 * @param text The reply message text
162 * @since 5.18
163 */
164 void reply(const QString &dbusService, uint id, const QString &text, Notifications::InvokeBehavior behavior);
165
166 /**
167 * Adds a notification
168 *
169 * @note The notification isn't actually broadcast
170 * but just emitted locally.
171 *
172 * @return the ID of the notification
173 */
174 uint add(const Notification &notification);
175
176Q_SIGNALS:
177 /**
178 * Emitted when the notification service validity changes,
179 * because it successfully registered the service or lost
180 * ownership of it.
181 * @since 5.18
182 */
184
185 /**
186 * Emitted when a notification was added.
187 * This is emitted regardless of any filtering rules or user settings.
188 * @param notification The notification
189 */
190 void notificationAdded(const Notification &notification);
191 /**
192 * Emitted when a notification is supposed to be updated
193 * This is emitted regardless of any filtering rules or user settings.
194 * @param replacedId The ID of the notification it replaces
195 * @param notification The new notification to use instead
196 */
197 void notificationReplaced(uint replacedId, const Notification &notification);
198 /**
199 * Emitted when a notification got removed (closed)
200 * @param id The notification ID
201 * @param reason The reason why it was closed
202 */
203 void notificationRemoved(uint id, CloseReason reason);
204
205 /**
206 * Emitted when the inhibited state changed.
207 */
209
210 /**
211 * Emitted when inhibitions by application have been changed.
212 * Becomes true as soon as there is one inhibition and becomes
213 * false again when all inhibitions have been lifted.
214 * @since 5.17
215 */
217
218 /**
219 * Emitted when the list of applications holding a notification
220 * inhibition changes.
221 * Normally you would only want to listen do @c inhibitedChanged
222 */
224
225 /**
226 * Emitted when the ownership of the Notification DBus Service is lost.
227 */
229
230private:
231 explicit Server(QObject *parent = nullptr);
232 Q_DISABLE_COPY(Server)
233 // FIXME we also need to disable move and other stuff?
234
235 std::unique_ptr<ServerPrivate> d;
236};
237
238} // namespace NotificationManager
Represents a single notification.
Information about the notification server.
Definition serverinfo.h:27
A notification DBus server.
Definition server.h:30
void setInhibited(bool inhibited)
Whether notifications are currently effectively inhibited.
Definition server.cpp:125
void inhibitedByApplicationChanged(bool inhibited)
Emitted when inhibitions by application have been changed.
CloseReason
The reason a notification was closed.
Definition server.h:69
@ Expired
The notification timed out.
Definition server.h:70
@ DismissedByUser
The user explicitly closed or acknowledged the notification.
Definition server.h:71
@ Revoked
The notification was revoked by the issuing app because it is no longer relevant.
Definition server.h:72
void notificationReplaced(uint replacedId, const Notification &notification)
Emitted when a notification is supposed to be updated This is emitted regardless of any filtering rul...
bool isValid() const
Whether the notification service could be registered.
Definition server.cpp:57
NotificationManager::ServerInfo * currentOwner
Information about the current owner of the Notification service.
Definition server.h:51
void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior, QWindow *window)
Sends an action invocation request.
Definition server.cpp:73
bool inhibited
Whether notifications are currently inhibited.
Definition server.h:61
void serviceOwnershipLost()
Emitted when the ownership of the Notification DBus Service is lost.
void inhibitedChanged(bool inhibited)
Emitted when the inhibited state changed.
void notificationRemoved(uint id, CloseReason reason)
Emitted when a notification got removed (closed)
void validChanged()
Emitted when the notification service validity changes, because it successfully registered the servic...
void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior)
Convenience call to maintain ABI.
Definition server.h:151
void inhibitionApplicationsChanged()
Emitted when the list of applications holding a notification inhibition changes.
QML_SINGLETONbool valid
Whether the notification service could be registered.
Definition server.h:39
void notificationAdded(const Notification &notification)
Emitted when a notification was added.
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 31 2025 12:05:31 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.