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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
/*
SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include <QObject>
#include "notificationmanager_export.h"
#include "notifications.h"
namespace NotificationManager
{
class Notification;
class ServerInfo;
class ServerPrivate;
/**
* @short A notification DBus server
*
* @author Kai Uwe Broulik <kde@privat.broulik.de>
**/
class NOTIFICATIONMANAGER_EXPORT Server : public QObject
{
Q_OBJECT
/**
* Whether the notification service could be registered.
* Call @c init() to register.
*/
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
/**
* Information about the current owner of the Notification service.
*
* This can be used to tell the user which application is currently
* owning the service in case service registration failed.
*
* This is never null, even if there is no notification service running.
*
* @since 5.18
*/
Q_PROPERTY(NotificationManager::ServerInfo *currentOwner READ currentOwner CONSTANT)
/**
* Whether notifications are currently inhibited.
*
* This is what is announced to other applications on the bus.
*
* @note This does not keep track of inhibitions on its own,
* you need to calculate this yourself and update the property accordingly.
*/
Q_PROPERTY(bool inhibited READ inhibited WRITE setInhibited NOTIFY inhibitedChanged)
public:
~Server() override;
/**
* The reason a notification was closed
*/
enum class CloseReason {
Expired = 1, ///< The notification timed out
DismissedByUser = 2, ///< The user explicitly closed or acknowledged the notification
Revoked = 3, ///< The notification was revoked by the issuing app because it is no longer relevant
};
Q_ENUM(CloseReason)
static Server &self();
/**
* Registers the Notification Service on DBus.
*
* @return true if it succeeded, false otherwise.
*/
bool init();
/**
* Whether the notification service could be registered
*/
bool isValid() const;
/**
* Information about the current owner of the Notification service.
* @since 5.18
*/
ServerInfo *currentOwner() const;
/**
* Whether notifications are currently inhibited.
* @since 5.17
*/
bool inhibited() const;
/**
* Whether notifications are currently effectively inhibited.
*
* @note You need to keep track of inhibitions and call this
* yourself when appropriate.
* @since 5.17
*/
void setInhibited(bool inhibited);
/**
* Whether an application requested to inhibit notifications.
*/
bool inhibitedByApplication() const;
// should we return a struct or pair or something?
QStringList inhibitionApplications() const;
QStringList inhibitionReasons() const;
/**
* Remove all inhibitions.
*
* @note The applications are not explicitly informed about this.
*/
void clearInhibitions();
/**
* Sends a notification closed event
*
* @param id The notification ID
* @param reason The reason why it was closed
*/
void closeNotification(uint id, CloseReason reason);
/**
* Sends an action invocation request
*
* @param id The notification ID
* @param actionName The name of the action, e.g. "Action 1", or "default"
* @param xdgActivationToken The token the application needs to send to raise itself.
* @param window the window that invokes the action
*/
void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior, QWindow *window);
/**
* Convenience call to maintain ABI
*
* @deprecated
*/
void invokeAction(uint id, const QString &actionName, const QString &xdgActivationToken, Notifications::InvokeBehavior behavior)
{
invokeAction(id, actionName, xdgActivationToken, behavior, nullptr);
}
/**
* Sends a notification reply text
*
* @param dbusService The bus name of the receiving application
* @param id The notification ID
* @param text The reply message text
* @since 5.18
*/
void reply(const QString &dbusService, uint id, const QString &text, Notifications::InvokeBehavior behavior);
/**
* Adds a notification
*
* @note The notification isn't actually broadcast
* but just emitted locally.
*
* @return the ID of the notification
*/
uint add(const Notification ¬ification);
Q_SIGNALS:
/**
* Emitted when the notification service validity changes,
* because it successfully registered the service or lost
* ownership of it.
* @since 5.18
*/
void validChanged();
/**
* Emitted when a notification was added.
* This is emitted regardless of any filtering rules or user settings.
* @param notification The notification
*/
void notificationAdded(const Notification ¬ification);
/**
* Emitted when a notification is supposed to be updated
* This is emitted regardless of any filtering rules or user settings.
* @param replacedId The ID of the notification it replaces
* @param notification The new notification to use instead
*/
void notificationReplaced(uint replacedId, const Notification ¬ification);
/**
* Emitted when a notification got removed (closed)
* @param id The notification ID
* @param reason The reason why it was closed
*/
void notificationRemoved(uint id, CloseReason reason);
/**
* Emitted when the inhibited state changed.
*/
void inhibitedChanged(bool inhibited);
/**
* Emitted when inhibitions by application have been changed.
* Becomes true as soon as there is one inhibition and becomes
* false again when all inhibitions have been lifted.
* @since 5.17
*/
void inhibitedByApplicationChanged(bool inhibited);
/**
* Emitted when the list of applications holding a notification
* inhibition changes.
* Normally you would only want to listen do @c inhibitedChanged
*/
void inhibitionApplicationsChanged();
/**
* Emitted when the ownership of the Notification DBus Service is lost.
*/
void serviceOwnershipLost();
private:
explicit Server(QObject *parent = nullptr);
Q_DISABLE_COPY(Server)
// FIXME we also need to disable move and other stuff?
QScopedPointer<ServerPrivate> d;
};
} // namespace NotificationManager
|