Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorServiceNotifications::NotificationServer Class Reference

The session-bus server for org.freedesktop.Notifications (Desktop Notifications Spec 1.3). More...

#include <PhosphorServiceNotifications/NotificationServer.h>

Inheritance diagram for PhosphorServiceNotifications::NotificationServer:
[legend]

Public Slots

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())
void CloseNotification (uint id)
QStringList GetCapabilities ()
QString GetServerInformation (QString &vendor, QString &version, QString &specVersion)

Signals

void notificationAdded (Notification *notification)
 A fresh notification (new id) was ingested and decoded.
void NotificationClosed (uint id, uint reason)
 A notification was closed; reason is the spec close-reason code (1 expired, 2 dismissed, 3 closed by CloseNotification, 4 undefined).
void ActionInvoked (uint id, const QString &actionKey)
 The user invoked action actionKey on notification id.
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 window.
void replySent (uint id, const QString &text)
 Local confirmation only. Reply text is sent as a targeted D-Bus signal.
void nameAcquiredChanged ()
void defaultExpireTimeoutChanged ()

Public Member Functions

 NotificationServer (QObject *parent=nullptr)
 Construct on the session bus under the spec's well-known name.
 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 no real session daemon and no name conflict).
 ~NotificationServer () override
bool nameAcquired () const
 True once this process owns the well-known name and is the active notification server.
bool acquireName (bool replaceExisting=false)
 (Re)acquire the well-known name.
QList< Notification * > notifications () const
 The live notifications, in ascending id order.
int defaultExpireTimeout () const
 Timeout (ms) applied to a Notify whose expire_timeout is -1 (the spec's "server decides").
void setDefaultExpireTimeout (int ms)
void dismissNotification (uint id)
 The user dismissed id (close reason 2): for a shell/toast to call when the user swipes or clicks the notification away.
void invokeAction (uint id, const QString &actionKey, const QString &activationToken=QString())
 Invoke actionKey on id.
bool reply (uint id, const QString &text)
 KDE inline-reply extension; only advertised actions accept replies.
void setExpiryPaused (uint id, bool paused)
 Preserve the remaining lifetime while a surface is being read/edited.

Static Public Member Functions

static QString serviceName ()
 The well-known name + object path defined by the spec.
static QString objectPath ()

Detailed Description

The session-bus server for org.freedesktop.Notifications (Desktop Notifications Spec 1.3).

This library OWNS the well-known name org.freedesktop.Notifications and answers it: it is the notification daemon, not a client of one. Because exactly one process may own the name, a notification daemon already running (dunst / mako / Plasma) is a hard conflict, surfaced as nameAcquired() == false rather than a degraded backend. The server then stays inert.

The four spec methods are exported through NotificationsAdaptor, which forwards synchronous calls and records their transport sender. Standard action/close signals are relayed; inline reply text is sent only to its origin.

Notify decodes the hint set (including the image-data → QImage path) into a typed Notification, allocates ids, and updates in place on replaces_id. Notifications expire per their expire_timeout (Critical never auto-expires), can be dismissed or have an action invoked, and are exposed as a list through NotificationModel.

Constructor & Destructor Documentation

◆ NotificationServer() [1/2]

PhosphorServiceNotifications::NotificationServer::NotificationServer ( QObject * parent = nullptr)
explicit

Construct on the session bus under the spec's well-known name.

◆ NotificationServer() [2/2]

PhosphorServiceNotifications::NotificationServer::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 no real session daemon and no name conflict).

◆ ~NotificationServer()

PhosphorServiceNotifications::NotificationServer::~NotificationServer ( )
override

Member Function Documentation

◆ acquireName()

bool PhosphorServiceNotifications::NotificationServer::acquireName ( bool replaceExisting = false)

(Re)acquire the well-known name.

The constructor calls this with replaceExisting false (inert when the name is taken). A daemon that wants to take over from another notification server (the CLI's --replace path) calls it with true, which succeeds when the current owner allows replacement. Returns nameAcquired(). A no-op once the name is held.

◆ ActionInvoked

void PhosphorServiceNotifications::NotificationServer::ActionInvoked ( uint id,
const QString & actionKey )
signal

The user invoked action actionKey on notification id.

Auto-relayed to the bus by the adaptor.

◆ ActivationToken

void PhosphorServiceNotifications::NotificationServer::ActivationToken ( uint id,
const QString & activationToken )
signal

Carries the XDG activation token for id ahead of an ActionInvoked, so the activated app can raise its window.

Auto-relayed by the adaptor.

◆ CloseNotification

void PhosphorServiceNotifications::NotificationServer::CloseNotification ( uint id)
slot

◆ defaultExpireTimeout()

int PhosphorServiceNotifications::NotificationServer::defaultExpireTimeout ( ) const
nodiscard

Timeout (ms) applied to a Notify whose expire_timeout is -1 (the spec's "server decides").

Critical notifications ignore this and never auto-expire. Default 5000. Changing it affects only future notifications, not timers already armed.

◆ defaultExpireTimeoutChanged

void PhosphorServiceNotifications::NotificationServer::defaultExpireTimeoutChanged ( )
signal

◆ dismissNotification()

void PhosphorServiceNotifications::NotificationServer::dismissNotification ( uint id)

The user dismissed id (close reason 2): for a shell/toast to call when the user swipes or clicks the notification away.

Q_INVOKABLE (not a slot) so it is callable from QML/CLI but never exported on the bus.

◆ GetCapabilities

QStringList PhosphorServiceNotifications::NotificationServer::GetCapabilities ( )
nodiscardslot

◆ GetServerInformation

QString PhosphorServiceNotifications::NotificationServer::GetServerInformation ( QString & vendor,
QString & version,
QString & specVersion )
slot

◆ invokeAction()

void PhosphorServiceNotifications::NotificationServer::invokeAction ( uint id,
const QString & actionKey,
const QString & activationToken = QString() )

Invoke actionKey on id.

When activationToken is non-empty it is announced via ActivationToken(id, token) first (XDG activation, so the target app can raise its window), then ActionInvoked(id, key). A non-resident notification is closed afterwards (reason 2); a resident one stays open. Q_INVOKABLE, not a slot: callable from QML/CLI, never exported (the bluetooth Agent1 keeps its respond* methods off the bus the same way).

◆ nameAcquired()

bool PhosphorServiceNotifications::NotificationServer::nameAcquired ( ) const
nodiscard

True once this process owns the well-known name and is the active notification server.

False when another daemon holds it (see class docs).

◆ nameAcquiredChanged

void PhosphorServiceNotifications::NotificationServer::nameAcquiredChanged ( )
signal

◆ notificationAdded

void PhosphorServiceNotifications::NotificationServer::notificationAdded ( Notification * notification)
signal

A fresh notification (new id) was ingested and decoded.

A replaces_id update does NOT re-emit this; it mutates the existing object in place and fires that object's Notification::changed() instead.

◆ NotificationClosed

void PhosphorServiceNotifications::NotificationServer::NotificationClosed ( uint id,
uint reason )
signal

A notification was closed; reason is the spec close-reason code (1 expired, 2 dismissed, 3 closed by CloseNotification, 4 undefined).

Auto-relayed to the bus by the adaptor. The matching object is deleted right after this fires, so consumers must drop their pointer here.

◆ notifications()

QList< Notification * > PhosphorServiceNotifications::NotificationServer::notifications ( ) const
nodiscard

The live notifications, in ascending id order.

Each is owned by this server; the list is a snapshot (pointers stay valid until the matching NotificationClosed fires). The NotificationModel (milestone 5) seeds itself from this and tracks notificationAdded / NotificationClosed.

◆ Notify

uint PhosphorServiceNotifications::NotificationServer::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() )
slot

◆ objectPath()

QString PhosphorServiceNotifications::NotificationServer::objectPath ( )
staticnodiscard

◆ reply()

bool PhosphorServiceNotifications::NotificationServer::reply ( uint id,
const QString & text )

KDE inline-reply extension; only advertised actions accept replies.

◆ replySent

void PhosphorServiceNotifications::NotificationServer::replySent ( uint id,
const QString & text )
signal

Local confirmation only. Reply text is sent as a targeted D-Bus signal.

◆ serviceName()

QString PhosphorServiceNotifications::NotificationServer::serviceName ( )
staticnodiscard

The well-known name + object path defined by the spec.

◆ setDefaultExpireTimeout()

void PhosphorServiceNotifications::NotificationServer::setDefaultExpireTimeout ( int ms)

◆ setExpiryPaused()

void PhosphorServiceNotifications::NotificationServer::setExpiryPaused ( uint id,
bool paused )

Preserve the remaining lifetime while a surface is being read/edited.


The documentation for this class was generated from the following file: