diff --git a/src/knotification.h b/src/knotification.h --- a/src/knotification.h +++ b/src/knotification.h @@ -507,6 +507,22 @@ void setUrls(const QList &urls); /** + * @return The notification timeout in milliseconds. + * @since 5.32 + */ + int timeout() const; + + /** + * Set the timeout of the notification. It is ignored if notification is + * persistent. Value must be greater than 0, otherwise the notification's + * server default timeout will be used. + * + * @param timeout The notification timeout in milliseconds. + * @since 5.32 + */ + void setTimeout(int timeout); + + /** * @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,11 +59,12 @@ NotificationFlags flags; QString componentName; QList urls; + int timeout; QTimer updateTimer; bool needUpdate; - Private() : id(-1), ref(0), widget(nullptr), needUpdate(false) {} + Private() : id(-1), ref(0), widget(nullptr), timeout(-1), needUpdate(false) {} /** * recursive function that raise the widget. @p w * @@ -274,6 +275,16 @@ d->urls = urls; } +int KNotification::timeout() const +{ + return d->timeout; +} + +void KNotification::setTimeout(int timeout) +{ + d->timeout = timeout; +} + void KNotification::activate(unsigned int action) { switch (action) { diff --git a/src/notifybypopup.cpp b/src/notifybypopup.cpp --- a/src/notifybypopup.cpp +++ b/src/notifybypopup.cpp @@ -251,7 +251,12 @@ // Persistent => 0 == infinite timeout // CloseOnTimeout => -1 == let the server decide - int timeout = notification->flags() & KNotification::Persistent ? 0 : -1; + int timeout = -1; + if (notification->flags() & KNotification::Persistent) { + timeout = 0; + } else if (notification->timeout() > 0) { + timeout = notification->timeout(); + } // if Growl can display our popups, use that instead if (NotifyByPopupGrowl::canPopup()) { @@ -731,7 +736,12 @@ // Persistent => 0 == infinite timeout // CloseOnTimeout => -1 == let the server decide - int timeout = notification->flags() & KNotification::Persistent ? 0 : -1; + int timeout = -1; + if (notification->flags() & KNotification::Persistent) { + timeout = 0; + } else if (notification->timeout() > 0) { + timeout = notification->timeout(); + } args.append(timeout); // expire timout