diff --git a/dataengines/notifications/notificationaction.cpp b/dataengines/notifications/notificationaction.cpp --- a/dataengines/notifications/notificationaction.cpp +++ b/dataengines/notifications/notificationaction.cpp @@ -77,6 +77,11 @@ } 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(); diff --git a/dataengines/notifications/notifications.operations b/dataengines/notifications/notifications.operations --- a/dataengines/notifications/notifications.operations +++ b/dataengines/notifications/notifications.operations @@ -47,4 +47,11 @@ + + + + + + + diff --git a/dataengines/notifications/notificationsengine.h b/dataengines/notifications/notificationsengine.h --- a/dataengines/notifications/notificationsengine.h +++ b/dataengines/notifications/notificationsengine.h @@ -25,6 +25,14 @@ #include #include +struct NotificationInhibiton +{ + QString hint; + QString value; +}; + +typedef QSharedPointer NotificationInhibitonPtr; + /** * Engine which provides data sources for notifications. * Each notification is represented by one source. @@ -58,6 +66,13 @@ 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 @@ */ QHash m_notificationsFromReplaceableApp; + QList m_inhibitions; + friend class NotificationAction; }; +Q_DECLARE_METATYPE(NotificationInhibitonPtr); + #endif diff --git a/dataengines/notifications/notificationsengine.cpp b/dataengines/notifications/notificationsengine.cpp --- a/dataengines/notifications/notificationsengine.cpp +++ b/dataengines/notifications/notificationsengine.cpp @@ -186,6 +186,13 @@ 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 @@ } } +QSharedPointer NotificationsEngine::createInhibition(const QString &hint, const QString &value) { + auto ni = new NotificationInhibiton; + ni->hint = hint; + ni->value = value; + + QSharedPointer 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"