diff --git a/src/knotification.h b/src/knotification.h --- a/src/knotification.h +++ b/src/knotification.h @@ -398,8 +398,33 @@ void setPixmap(const QPixmap &pix); /** + * @return the default action, or an empty string if not set + */ + QString defaultAction() const; + + /** + * Set a default action that will be triggered when the notification is + * activated (typically, by clicking on the notification popup). The default + * action should raise a window belonging to the application that sent it. + * + * The string will be used as a label for the action, so ideally it should + * be wrapped in i18n() or tr() calls. + * + * The visual representation of actions depends on the notification server. + * In Plasma and Gnome desktops, the actions are performed by clicking on + * the notification popup, and the label is not presented to the user. + * + * + * @param action Label of the default action. The label might or might not + * be displayed to the user by the notification server, depending on the + * implementation. Passing an empty string disables the default action. + */ + void setDefaultAction(const QString &defaultAction); + + /** * @return the list of actions */ + //KF6: Rename to "additionalActions"? QStringList actions() const; /** @@ -414,6 +439,7 @@ * * @param actions List of strings used as action labels */ + //KF6: Rename to "setAdditionalActions"? void setActions(const QStringList &actions); /** diff --git a/src/knotification.cpp b/src/knotification.cpp --- a/src/knotification.cpp +++ b/src/knotification.cpp @@ -52,6 +52,7 @@ QString title; QString text; QString iconName; + QString defaultAction; QStringList actions; QPixmap pixmap; ContextList contexts; @@ -210,6 +211,24 @@ } } +void KNotification::setDefaultAction(const QString &defaultAction) +{ + if (defaultAction == d->defaultAction) { + return; + } + + d->needUpdate = true; + d->defaultAction = defaultAction; + if (d->id >= 0) { + d->updateTimer.start(); + } +} + +QString KNotification::defaultAction() const +{ + return d->defaultAction; +} + KNotification::ContextList KNotification::contexts() const { return d->contexts; diff --git a/src/notifybypopup.cpp b/src/notifybypopup.cpp --- a/src/notifybypopup.cpp +++ b/src/notifybypopup.cpp @@ -477,7 +477,11 @@ KNotification *n = *iter; if (n) { - emit actionInvoked(n->id(), actionKey.toUInt()); + if (actionKey == QStringLiteral("default")) { + emit actionInvoked(n->id(), 0); + } else { + emit actionInvoked(n->id(), actionKey.toUInt()); + } } else { d->galagoNotifications.erase(iter); } @@ -667,6 +671,11 @@ // (i.e. starting from 1) QStringList actionList; if (popupServerCapabilities.contains(QStringLiteral("actions"))) { + QString defaultAction = notification->defaultAction(); + if (!defaultAction.isEmpty()) { + actionList.append(QStringLiteral("default")); + actionList.append(defaultAction); + } int actId = 0; Q_FOREACH (const QString &actionName, notification->actions()) { actId++;