Add a notication service to inhibit certain notifications based on metadata

Summary:
Sometimes we get notifications for events that are also displayed by
Plasma, giving us some rather annoying popups.

This patch provides a service on the notification dataengine so that
other plasmoids can block the notification applet from processing those
notifications.

Intended use case is for the network manager plasomid to not show a
notification whilst the dialog is open, as notifications come from kded.

However it's kept generic enough that other plasmoids can filter on
other hints, such as category or desktop file.

Test Plan:
Wrote relevant patch for plasma-nm
Didn't get notification toggling a network whilst the popup was open
Did after I closed the popup

Reviewers: #plasma, mart

Reviewed By: mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3589
wilder-5.14
David Edmundson 9 years ago
parent 7ad88dc2ad
commit 7f7d229843
  1. 5
      dataengines/notifications/notificationaction.cpp
  2. 7
      dataengines/notifications/notifications.operations
  3. 21
      dataengines/notifications/notificationsengine.cpp
  4. 19
      dataengines/notifications/notificationsengine.h

@ -77,6 +77,11 @@ void NotificationAction::start()
} else if (operationName() == QLatin1String("configureNotification")) {
m_engine->configureNotification(parameters()[QStringLiteral("appRealName")].toString(),
parameters()[QStringLiteral("eventId")].toString());
} else if (operationName() == QLatin1String("inhibit")) {
const QString hint = parameters()[QStringLiteral("hint")].toString();
const QString value = parameters()[QStringLiteral("value")].toString();
auto t = m_engine->createInhibition(hint, value);
setResult(QVariant::fromValue(t));
}
emitResult();

@ -47,4 +47,11 @@
</entry>
</group>
<group name="inhibit">
<entry name="hint" type="String">
</entry>
<entry name="value" type="String">
</entry>
</group>
</kcfg>

@ -186,6 +186,13 @@ uint NotificationsEngine::Notify(const QString &app_name, uint replaces_id,
const QString &app_icon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantMap &hints, int timeout)
{
foreach(NotificationInhibiton *ni, m_inhibitions) {
if (hints[ni->hint] == ni->value) {
qDebug() << "notification inhibited. Skipping";
return -1;
}
}
uint partOf = 0;
const QString appRealName = hints[QStringLiteral("x-kde-appname")].toString();
const QString eventId = hints[QStringLiteral("x-kde-eventId")].toString();
@ -413,6 +420,20 @@ void NotificationsEngine::configureNotification(const QString &appName, const QS
}
}
QSharedPointer<NotificationInhibiton> NotificationsEngine::createInhibition(const QString &hint, const QString &value) {
auto ni = new NotificationInhibiton;
ni->hint = hint;
ni->value = value;
QSharedPointer<NotificationInhibiton> rc(ni, [this](NotificationInhibiton *ni) {
m_inhibitions.removeOne(ni);
delete ni;
});
m_inhibitions.append(ni);
return rc;
}
K_EXPORT_PLASMA_DATAENGINE_WITH_JSON(notifications, NotificationsEngine, "plasma-dataengine-notifications.json")
#include "notificationsengine.moc"

@ -25,6 +25,14 @@
#include <QSet>
#include <QHash>
struct NotificationInhibiton
{
QString hint;
QString value;
};
typedef QSharedPointer<NotificationInhibiton> NotificationInhibitonPtr;
/**
* Engine which provides data sources for notifications.
* Each notification is represented by one source.
@ -58,6 +66,13 @@ public:
void configureNotification(const QString &appName, const QString &eventId = QString());
/*
* Block all notification where a given notification hint matches a given value.
*
* Inhibition is dropped when dereferenced.
*/
NotificationInhibitonPtr createInhibition(const QString &hint, const QString &value);
public Q_SLOTS:
void removeNotification(uint id, uint closeReason);
bool registerDBusService();
@ -90,7 +105,11 @@ private:
*/
QHash<QString, uint> m_notificationsFromReplaceableApp;
QList<NotificationInhibiton*> m_inhibitions;
friend class NotificationAction;
};
Q_DECLARE_METATYPE(NotificationInhibitonPtr);
#endif

Loading…
Cancel
Save