Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
NotificationServer.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceNotifications/phosphorservicenotifications_export.h>
7
8#include <QDBusConnection>
9#include <QList>
10#include <QObject>
11#include <QString>
12#include <QStringList>
13#include <QVariantMap>
14
15#include <memory>
16
18
19class Notification;
20
41class PHOSPHORSERVICENOTIFICATIONS_EXPORT NotificationServer : public QObject
42{
43 Q_OBJECT
44 Q_PROPERTY(bool nameAcquired READ nameAcquired NOTIFY nameAcquiredChanged)
47
48public:
50 explicit NotificationServer(QObject* parent = nullptr);
53 NotificationServer(QDBusConnection connection, QString service, QObject* parent = nullptr);
55
58 [[nodiscard]] bool nameAcquired() const;
59
65 bool acquireName(bool replaceExisting = false);
66
68 [[nodiscard]] static QString serviceName();
69 [[nodiscard]] static QString objectPath();
70
75 [[nodiscard]] QList<Notification*> notifications() const;
76
81 [[nodiscard]] int defaultExpireTimeout() const;
83
87 Q_INVOKABLE void dismissNotification(uint id);
88
95 Q_INVOKABLE void invokeAction(uint id, const QString& actionKey, const QString& activationToken = QString());
97 Q_INVOKABLE bool reply(uint id, const QString& text);
99 Q_INVOKABLE void setExpiryPaused(uint id, bool paused);
100
101public Q_SLOTS:
102 // org.freedesktop.Notifications, forwarded here by the transport adaptor.
103 // Signatures mirror the spec exactly; the PascalCase names are spec-dictated
104 // (as with the bluetooth Agent1 slots) and intentionally break the project's
105 // action-verb slot-naming rule. All reply synchronously.
106 uint Notify(const QString& appName, uint replacesId, const QString& appIcon, const QString& summary,
107 const QString& body, const QStringList& actions, const QVariantMap& hints, int expireTimeout,
108 const QString& sender = QString());
109 void CloseNotification(uint id);
110 [[nodiscard]] QStringList GetCapabilities();
111 QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
112
113Q_SIGNALS:
117 void notificationAdded(Notification* notification);
118
123 void NotificationClosed(uint id, uint reason);
126 void ActionInvoked(uint id, const QString& actionKey);
129 void ActivationToken(uint id, const QString& activationToken);
131 void replySent(uint id, const QString& text);
132
135
136private:
137 Q_DISABLE_COPY_MOVE(NotificationServer)
138
139
141 void closeInternal(uint id, uint reason);
144 void armExpiry(Notification* notification);
145
146 class Private;
147 std::unique_ptr<Private> d;
148};
149
150} // namespace PhosphorServiceNotifications
QString GetServerInformation(QString &vendor, QString &version, QString &specVersion)
void setExpiryPaused(uint id, bool paused)
Preserve the remaining lifetime while a surface is being read/edited.
void replySent(uint id, const QString &text)
Local confirmation only. Reply text is sent as a targeted D-Bus signal.
QList< Notification * > notifications() const
The live notifications, in ascending id order.
bool nameAcquired() const
True once this process owns the well-known name and is the active notification server.
NotificationServer(QObject *parent=nullptr)
Construct on the session bus under the spec's well-known name.
void ActivationToken(uint id, const QString &activationToken)
Carries the XDG activation token for id ahead of an ActionInvoked, so the activated app can raise its...
NotificationServer(QDBusConnection connection, QString service, QObject *parent=nullptr)
Dependency-injected ctor (tests drive a private peer-to-peer bus, so the whole ingest path runs with ...
void ActionInvoked(uint id, const QString &actionKey)
The user invoked action actionKey on notification id.
bool acquireName(bool replaceExisting=false)
(Re)acquire the well-known name.
void notificationAdded(Notification *notification)
A fresh notification (new id) was ingested and decoded.
void dismissNotification(uint id)
The user dismissed id (close reason 2): for a shell/toast to call when the user swipes or clicks the ...
void invokeAction(uint id, const QString &actionKey, const QString &activationToken=QString())
Invoke actionKey on id.
void NotificationClosed(uint id, uint reason)
A notification was closed; reason is the spec close-reason code (1 expired, 2 dismissed,...
static QString serviceName()
The well-known name + object path defined by the spec.
int defaultExpireTimeout() const
Timeout (ms) applied to a Notify whose expire_timeout is -1 (the spec's "server decides").
bool reply(uint id, const QString &text)
KDE inline-reply extension; only advertised actions accept replies.
uint Notify(const QString &appName, uint replacesId, const QString &appIcon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expireTimeout, const QString &sender=QString())
One live notification, decoded from an org.freedesktop.Notifications Notify call.
Definition Notification.h:36
Definition Notification.h:15