@@ -15,128 +15,12 @@
16 * Authors: Lukáš Tinkl <ltinkl@canonical.com>
16 * Authors: Lukáš Tinkl <ltinkl@canonical.com>
17 * Christopher Townsend <christopher.townsend@canonical.com>
17 * Christopher Townsend <christopher.townsend@canonical.com>
18− * Paul Liu <paul.liu@canonical.com>
18+ * Ying-Chun Liu (PaulLiu) <paul.liu@canonical.com>
22#include "dbusunitysessionservice.h"
22#include "dbusunitysessionservice.h"
23−
23+#include "dbusunitysessionservice_p.h"
25−#include <sys/types.h>
31−#include <QDBusPendingCall>
33−#include <QElapsedTimer>
35−#define LOGIN1_SERVICE QStringLiteral("org.freedesktop.login1")
36−#define LOGIN1_PATH QStringLiteral("/org/freedesktop/login1")
37−#define LOGIN1_IFACE QStringLiteral("org.freedesktop.login1.Manager")
38−#define LOGIN1_SESSION_IFACE QStringLiteral("org.freedesktop.login1.Session")
40−#define ACTIVE_KEY QStringLiteral("Active")
42−class DBusUnitySessionServicePrivate: public QObject
46− QString logindSessionPath;
47− bool isActive = true;
48− QElapsedTimer screensaverActiveTimer;
50− DBusUnitySessionServicePrivate(): QObject() {
57− // get our logind session path
58− QDBusMessage msg = QDBusMessage::createMethodCall(LOGIN1_SERVICE,
62− msg << (quint32) getpid();
64− QDBusReply<QDBusObjectPath> reply = QDBusConnection::systemBus().asyncCall(msg);
65− if (reply.isValid()) {
66− logindSessionPath = reply.value().path();
67− //qDebug() << "session path" << logindSessionPath;
69− // start watching the Active property
70− QDBusConnection::systemBus().connect(LOGIN1_SERVICE, logindSessionPath, "org.freedesktop.DBus.Properties", "PropertiesChanged",
71− this, SLOT(onPropertiesChanged(QString,QVariantMap,QStringList)));
73− qWarning() << "Failed to get logind session path" << reply.error().message();
77− bool checkLogin1Call(const QString &method) const
79− QDBusMessage msg = QDBusMessage::createMethodCall(LOGIN1_SERVICE, LOGIN1_PATH, LOGIN1_IFACE, method);
80− QDBusReply<QString> reply = QDBusConnection::systemBus().asyncCall(msg);
81− return reply.isValid() && (reply == QStringLiteral("yes") || reply == QStringLiteral("challenge"));
84− void makeLogin1Call(const QString &method, const QVariantList &args)
86− QDBusMessage msg = QDBusMessage::createMethodCall(LOGIN1_SERVICE,
90− msg.setArguments(args);
91− QDBusConnection::systemBus().asyncCall(msg);
96− if (logindSessionPath.isEmpty()) {
97− qWarning() << "Invalid session path";
101− QDBusMessage msg = QDBusMessage::createMethodCall(LOGIN1_SERVICE,
103− "org.freedesktop.DBus.Properties",
105− msg << LOGIN1_SESSION_IFACE;
108− QDBusReply<QVariant> reply = QDBusConnection::systemBus().asyncCall(msg);
109− if (reply.isValid()) {
110− isActive = reply.value().toBool();
111− qDebug() << "Session" << logindSessionPath << "is active:" << isActive;
113− qWarning() << "Failed to get Active property" << reply.error().message();
118− void onPropertiesChanged(const QString &iface, const QVariantMap &changedProps, const QStringList &invalidatedProps)
122− if (changedProps.contains(ACTIVE_KEY)) {
123− isActive = changedProps.value(ACTIVE_KEY).toBool();
124− } else if (invalidatedProps.contains(ACTIVE_KEY)) {
128− Q_EMIT screensaverActiveChanged(!isActive);
131− screensaverActiveTimer.invalidate();
133− screensaverActiveTimer.start();
138− void screensaverActiveChanged(bool active);
141Q_GLOBAL_STATIC(DBusUnitySessionServicePrivate, d)
25Q_GLOBAL_STATIC(DBusUnitySessionServicePrivate, d)
@@ -258,7 +142,7 @@ void DBusUnitySessionService::Lock()
259bool DBusUnitySessionService::IsLocked() const
143bool DBusUnitySessionService::IsLocked() const
261− return !d->isActive;
145+ return !d->isSessionActive;
264void DBusUnitySessionService::RequestLogout()
148void DBusUnitySessionService::RequestLogout()
@@ -319,6 +203,7 @@ void performAsyncUnityCall(const QString &method)
319 QDBusConnection::sessionBus().asyncCall(msg);
203 QDBusConnection::sessionBus().asyncCall(msg);
322DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
207DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
323 : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
208 : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
@@ -358,7 +243,7 @@ DBusGnomeScreensaverWrapper::DBusGnomeScreensaverWrapper()
359bool DBusGnomeScreensaverWrapper::GetActive() const
244bool DBusGnomeScreensaverWrapper::GetActive() const
361− return !d->isActive; // return whether the session is not active
246+ return !d->isSessionActive; // return whether the session is not active
364void DBusGnomeScreensaverWrapper::SetActive(bool lock)
249void DBusGnomeScreensaverWrapper::SetActive(bool lock)
@@ -375,11 +260,36 @@ void DBusGnomeScreensaverWrapper::Lock()
376quint32 DBusGnomeScreensaverWrapper::GetActiveTime() const
261quint32 DBusGnomeScreensaverWrapper::GetActiveTime() const
378− if (GetActive() && d->screensaverActiveTimer.isValid()) {
263+ return d->activeTime();
379− return d->screensaverActiveTimer.elapsed() / 1000;
264+}
267+DBusScreensaverWrapper::DBusScreensaverWrapper()
268+ : UnityDBusObject("/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver")
270+ connect(d, &DBusUnitySessionServicePrivate::screensaverActiveChanged, this, &DBusScreensaverWrapper::ActiveChanged);
273+bool DBusScreensaverWrapper::GetActive() const
275+ return !d->isSessionActive; // return whether the session is not active
278+bool DBusScreensaverWrapper::SetActive(bool lock)
382− return 0;
287+void DBusScreensaverWrapper::Lock()
289+ performAsyncUnityCall("Lock");
385−#include "dbusunitysessionservice.moc"
292+quint32 DBusScreensaverWrapper::GetActiveTime() const
294+ return d->activeTime();