retrieve login1 session object from manager (#3339)

This commit is contained in:
Kjell Braden 2020-01-21 11:32:47 +01:00 committed by Jonathan White
parent 796b5ceacb
commit 6ff3e8801d
2 changed files with 34 additions and 6 deletions

View File

@ -19,7 +19,9 @@
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDebug>
#include <QProcessEnvironment>
ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent)
@ -57,12 +59,14 @@ ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent)
SLOT(logindPrepareForSleep(bool)));
QString sessionId = QProcessEnvironment::systemEnvironment().value("XDG_SESSION_ID");
systemBus.connect("", // service
QString("/org/freedesktop/login1/session/") + sessionId, // path
"org.freedesktop.login1.Session", // interface
"Lock", // signal name
this, // receiver
SLOT(unityLocked()));
QDBusInterface loginManager("org.freedesktop.login1", // service
"/org/freedesktop/login1", // path
"org.freedesktop.login1.Manager", // interface
systemBus);
if (loginManager.isValid()) {
QList<QVariant> args = {sessionId};
loginManager.callWithCallback("GetSession", args, this, SLOT(login1SessionObjectReceived(QDBusMessage)));
}
sessionBus.connect("com.canonical.Unity", // service
"/com/canonical/Unity/Session", // path
@ -72,6 +76,28 @@ ScreenLockListenerDBus::ScreenLockListenerDBus(QWidget* parent)
SLOT(unityLocked()));
}
void ScreenLockListenerDBus::login1SessionObjectReceived(QDBusMessage response)
{
if (response.arguments().isEmpty()) {
qDebug() << "org.freedesktop.login1.Manager.GetSession did not return results";
return;
}
QVariant arg0 = response.arguments().at(0);
if (!arg0.canConvert<QDBusObjectPath>()) {
qDebug() << "org.freedesktop.login1.Manager.GetSession did not return a QDBusObjectPath";
return;
}
QDBusObjectPath path = arg0.value<QDBusObjectPath>();
QDBusConnection systemBus = QDBusConnection::systemBus();
systemBus.connect("", // service
path.path(), // path
"org.freedesktop.login1.Session", // interface
"Lock", // signal name
this, // receiver
SLOT(unityLocked()));
}
void ScreenLockListenerDBus::gnomeSessionStatusChanged(uint status)
{
if (status != 0) {

View File

@ -18,6 +18,7 @@
#ifndef SCREENLOCKLISTENERDBUS_H
#define SCREENLOCKLISTENERDBUS_H
#include "ScreenLockListenerPrivate.h"
#include <QDBusMessage>
#include <QObject>
#include <QWidget>
@ -32,6 +33,7 @@ private slots:
void logindPrepareForSleep(bool beforeSleep);
void unityLocked();
void freedesktopScreenSaver(bool status);
void login1SessionObjectReceived(QDBusMessage);
};
#endif // SCREENLOCKLISTENERDBUS_H