diff --git a/src/knotification.h b/src/knotification.h --- a/src/knotification.h +++ b/src/knotification.h @@ -127,6 +127,7 @@ Contexts=group Sound=filetoplay.ogg Action=None + Urgency=Low * * These are the default settings for each notifiable event. * Action is the string representing the action. Actions can be added to @@ -137,6 +138,8 @@ * * Contexts is a comma separated list of possible context for this event. * + * Urgency can be any of: Low, Normal, Critical. + * * \section userfile The user's config file * * This is an implementation detail, and is described here for your information. @@ -269,6 +272,14 @@ */ enum StandardEvent { Notification, Warning, Error, Catastrophe }; + /** + * The urgency of a notification. + * + * @since 5.58 + * @sa setUrgency + */ + enum Urgency { DefaultUrgency = -1, LowUrgency, NormalUrgency, CriticalUrgency }; + /** * Create a new notification. * @@ -508,6 +519,28 @@ */ void setUrls(const QList &urls); + /** + * The urgency of the notification. + * @since 5.58 + */ + Urgency urgency() const; + + /** + * Sets the urgency of the notification. + * + * This defines the importance of the notification. For example, + * a track change in a media player would be a low urgency. + * "You have new mail" would be normal urgency. "Your battery level + * is low" would be a critical urgency. + * + * Use critical notifications with care as they might be shown even + * when giving a presentation or when notifications are turned off. + * + * @param urgency The urgency. + * @since 5.58 + */ + void setUrgency(Urgency urgency); + /** * @internal * the id given by the notification manager diff --git a/src/knotification.cpp b/src/knotification.cpp --- a/src/knotification.cpp +++ b/src/knotification.cpp @@ -59,12 +59,13 @@ NotificationFlags flags; QString componentName; QList urls; + KNotification::Urgency urgency; QVariantMap hints; QTimer updateTimer; bool needUpdate; - Private() : id(-1), ref(0), widget(nullptr), needUpdate(false) {} + Private() : id(-1), ref(0), widget(nullptr), urgency(KNotification::DefaultUrgency), needUpdate(false) {} /** * recursive function that raise the widget. @p w * @@ -275,6 +276,16 @@ d->urls = urls; } +KNotification::Urgency KNotification::urgency() const +{ + return d->urgency; +} + +void KNotification::setUrgency(Urgency urgency) +{ + d->urgency = urgency; +} + void KNotification::activate(unsigned int action) { switch (action) { diff --git a/src/knotificationmanager.cpp b/src/knotificationmanager.cpp --- a/src/knotificationmanager.cpp +++ b/src/knotificationmanager.cpp @@ -312,6 +312,18 @@ d->notifications.insert(d->notifyIdCounter, n); + // TODO KF6 d-pointer KNotifyConfig and add this there + if (n->urgency() == KNotification::DefaultUrgency) { + const QString urgency = notifyConfig.readEntry(QStringLiteral("Urgency")); + if (urgency == QLatin1String("Low")) { + n->setUrgency(KNotification::LowUrgency); + } else if (urgency == QLatin1String("Normal")) { + n->setUrgency(KNotification::NormalUrgency); + } else if (urgency == QLatin1String("Critical")) { + n->setUrgency(KNotification::CriticalUrgency); + } + } + const auto actionsList = notifyActions.split(QLatin1Char('|')); for (const QString &action : actionsList) { KNotificationPlugin *notifyPlugin = pluginForAction(action); diff --git a/src/notifybypopup.cpp b/src/notifybypopup.cpp --- a/src/notifybypopup.cpp +++ b/src/notifybypopup.cpp @@ -712,6 +712,10 @@ hintsMap[QStringLiteral("desktop-entry")] = qApp->desktopFileName(); } + if (notification->urgency() != KNotification::DefaultUrgency) { + hintsMap[QStringLiteral("urgency")] = static_cast(notification->urgency()); + } + const QVariantMap hints = notification->hints(); for (auto it = hints.constBegin(); it != hints.constEnd(); ++it) { hintsMap[it.key()] = it.value();