Bug 386330 - Ability for QML plasmoids to detect when a notification action is clicked
Summary: Ability for QML plasmoids to detect when a notification action is clicked
Status: RESOLVED INTENTIONAL
Alias: None
Product: plasmashell
Classification: Plasma
Component: Notifications (show other bugs)
Version: 5.10.5
Platform: Other Linux
: NOR wishlist
Target Milestone: 1.0
Assignee: Kai Uwe Broulik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-29 17:01 UTC by Chris Holland
Modified: 2021-12-22 21:39 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Holland 2017-10-29 17:01:46 UTC
I'm abusing the notification dataengine to create notifications in my widgets. Right now I can send notifications (with action buttons), but I can't tell what button the user clicked.

The "invokeAction" operation (notifcation applet => dataengine), emits:

emit m_engine->ActionInvoked(id, parameters()[QStringLiteral("actionId")].toString());

https://github.com/KDE/plasma-workspace/blob/master/dataengines/notifications/notificationaction.cpp#L53

however, a QML widget can't connect to that since the DataEngine isn't exposed. PlasmaCore.DataSource wraps m_dataEngine, but doesn't expose it.

https://github.com/KDE/plasma-framework/blob/91eb0749ed7f0d1439a60e67bc7a23c41636c93c/src/declarativeimports/core/datasource.h#L190

I'm not sure what would be the best way to expose the ActionInvoked signal to QML.

-----

If your wondering what I'm using:
https://github.com/Zren/plasma-applets/blob/master/org.kde.plasma.eventcalendar/package/contents/ui/NotificationManager.qml



I use dataSource.serviceForSource("notifications") to get a Plasma::DataService. In our case, we get NotificationService.

https://github.com/KDE/plasma-workspace/blob/master/dataengines/notifications/notificationservice.h

Which also doesn't expose the DataEngine.

https://api.kde.org/frameworks/plasma-framework/html/service_8cpp_source.html#l00087

The NotificationService returns a NotiticationAction (which extends Plasma::ServiceJob).
When we use the "createNotification" operation on that serviceJob, its "result" is the notificationId, which is useful for later.

int rv = m_engine->createNotification(...);
setResult(rv);

https://github.com/KDE/plasma-workspace/blob/master/dataengines/notifications/notificationaction.cpp#L60

The NotificationAction/ServiceJob has a reference to the NotificationEngine, so it might be possible to have it connect to the ActionInvoked/NotificationClosed signals.
Comment 1 Nicolas Fella 2021-12-22 20:13:10 UTC
KNotifications now offers a QML API. Consider the dataengine deprecated
Comment 2 Chris Holland 2021-12-22 21:39:22 UTC
Oh neat! It was added 2021 Oct, so since KF5 v5.88.0

* https://www.volkerkrause.eu/2021/09/18/kf5-notifications-in-qml.html
* https://github.com/KDE/knotifications/blob/master/docs/qml-notifications.md
* https://github.com/KDE/knotifications/commit/16e92d643faff27d52f10b14aab68b73d11a4481

Hmm, looks like I'll have to wait for Ubuntu 22.04 at least to use it on the KDE Store.

* https://repology.org/project/knotifications/versions

I've stopped using the notifications dataengine anyways since it had problems in Latte-Dock.

* https://github.com/Zren/plasma-applet-eventcalendar/issues/60

I'm currently using the executable dataengine + python script. I'll see about trying to use the new KNotification API in a QML Loader, then using the python script as a fallback.