Listen for broadcast notifications on system bus
ClosedPublic

Authored by broulik on Dec 6 2016, 1:29 PM.

Details

Summary

This will listen for a signal on the system DBus to show a notification to all users on the current machine. This allows prettier and more versatile notifications than using wall/write.

This is disabled by default but can be enabled in e.g. ~/.config/plasmashellrc per user or /etc/xdg/plasmashellrc globally

[Notifications]
ListenForBroadcasts=true
Test Plan

Requested by LiMux project

Little test app that works.

If "uids" is given, the notification will only be shown for the users with UIDs given. If it is omitted the notification is shown for all users.

#include <QCoreApplication>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QTimer>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/de/limux/Broadcast"),
                                                      QStringLiteral("org.kde.BroadcastNotifications"),
                                                      QStringLiteral("Notify"));
    message.setArguments({ QVariantMap{
        {QStringLiteral("summary"), "Cannot restore network shares"},
        {QStringLiteral("body"), "Please contact system administration if you cannot find your stuff."},
        {QStringLiteral("appIcon"), QStringLiteral("network-disconnect")},
        {QStringLiteral("uids"), QStringList{QStringLiteral("0"), QStringLiteral("1000"), QStringLiteral("1337")} }
    } });
    QDBusConnection::systemBus().send(message);

    QTimer::singleShot(500, &app, QCoreApplication::quit);

    return app.exec();
}

Diff Detail

Repository
R120 Plasma Workspace
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik updated this revision to Diff 8806.Dec 6 2016, 1:29 PM
broulik retitled this revision from to RFC: Listen for broadcast notifications on system bus.
broulik updated this object.
broulik edited the test plan for this revision. (Show Details)
broulik added a reviewer: Plasma.
broulik set the repository for this revision to R120 Plasma Workspace.
Restricted Application added a project: Plasma. · View Herald TranscriptDec 6 2016, 1:29 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
mart added a subscriber: mart.Dec 6 2016, 5:02 PM

since is rfc this is my comment: I like the idea a lot

broulik retitled this revision from RFC: Listen for broadcast notifications on system bus to Listen for broadcast notifications on system bus.Dec 8 2016, 1:34 PM
broulik updated this object.
broulik edited the test plan for this revision. (Show Details)

Note that actions won't work, we'd always be replying on the session bus. (this is solvable)

dataengines/notifications/notificationsengine.cpp
70

I'd get rid of the plasmashell in the iface name.
Otherwise you're tying an implementation detail into an API.

Also for whatever reason convention is to be UpperCamelCase (i.e BroadcastNotification not broadcastNotification)

426

is it intended that you can't send a message to root?

otherwise toULongLong(&rc );
if (rc) {..}

broulik updated this revision to Diff 8853.Dec 8 2016, 1:43 PM
broulik removed a subscriber: davidedmundson.
  • Support passing "uids" as stringlist, my initial QVariantList with int approach didnt really work
  • Enable only if configured
broulik updated this revision to Diff 8854.Dec 8 2016, 1:49 PM
broulik edited the test plan for this revision. (Show Details)
  • Drop plasmashell from interface name and upper camel case

What would be the best place to put a little utility (similar to notify-send or kdialog --passivepopup) for this?

Note that actions won't work, we'd always be replying on the session bus. (this is solvable)

is that even possible to add an action at all from there?

No, you're right. I mistakenly thought actions were in the hints even though the code even has "{} //no actions" documented

mart added a comment.Dec 12 2016, 9:01 AM

What would be the best place to put a little utility (similar to notify-send or kdialog --passivepopup) for this?

kde-cli-tools

davidedmundson accepted this revision.Dec 12 2016, 11:55 AM
davidedmundson added a reviewer: davidedmundson.

kbroulik: kde-cli-tools?

This revision is now accepted and ready to land.Dec 12 2016, 11:55 AM
This revision was automatically updated to reflect the committed changes.