Receiving system D-Bus signals and responding to them
-
I already asked this last month but nobody answered plus I've got some new stuff.
Basically, I need to respond to the
org.freedesktop.login1.Manager.PrepareForSleep
signal, closing out the application and deallocating all memory in order to prevent users from accessing sensitive data if the computer is hibernated and writes the contents of RAM to disk.Here are the two things I've tried:
class Test : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.freedesktop.login1.Manager") public: Test(QObject *obj) : QDBusAbstractAdaptor(obj) { } signals: void PrepareForSleep(); }; int main() { // ... QObject obj; Test *test = new Test(&obj); QObject::connect(pong, &Test::PrepareForSleep, test, [] { qDebug() << "Preparing for sleep"; }); QDBusConnection::sessionBus().registerObject("/", &obj); }
Which simply did nothing, and:
QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep")
Which also did nothing. I'm pretty sure the latter not working is because it's using incorrect arguments, but I haven't found any documentation for like, what I should even make the arguments to match the PrepareForSleep signal.
In general I just can't figure anything out from any of the documentation and examples. All of them seem to deal with either custom signals/slots, and just listing the names from
org.freedesktop.DBus
, nothing else.