on c9aaa2b help sign in
unity8/plugins/Unity/Session/dbusunitysessionservice.cpp
125 lines 3.9 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17// local
18#include "dbusunitysessionservice.h"
20// Qt
21#include <QDBusPendingCall>
23DBusUnitySessionService::DBusUnitySessionService()
24 : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
28void DBusUnitySessionService::Logout()
30 // TODO ask the apps to quit and then emit the signal
31 Q_EMIT logoutReady();
34void DBusUnitySessionService::EndSession()
36 const QDBusMessage msg = QDBusMessage::createMethodCall("com.ubuntu.Upstart",
37 "/com/ubuntu/Upstart",
38 "com.ubuntu.Upstart0_6",
39 "EndSession");
40 QDBusConnection::sessionBus().asyncCall(msg);
43void DBusUnitySessionService::RequestLogout()
45 Q_EMIT logoutRequested(false);
48void DBusUnitySessionService::Reboot()
50 QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
51 "/org/freedesktop/login1",
52 "org.freedesktop.login1.Manager",
53 "Reboot");
54 msg << false;
55 QDBusConnection::systemBus().asyncCall(msg);
58void DBusUnitySessionService::RequestReboot()
60 Q_EMIT rebootRequested(false);
63void DBusUnitySessionService::Shutdown()
65 QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.login1",
66 "/org/freedesktop/login1",
67 "org.freedesktop.login1.Manager",
68 "PowerOff");
69 msg << false;
70 QDBusConnection::systemBus().asyncCall(msg);
73void DBusUnitySessionService::RequestShutdown()
75 Q_EMIT shutdownRequested(false);
78enum class Action : unsigned
80 LOGOUT = 0,
81 SHUTDOWN,
82 REBOOT,
83 NONE
84};
86DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
87 : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
91void DBusGnomeSessionManagerWrapper::performAsyncCall(const QString &method)
93 const QDBusMessage msg = QDBusMessage::createMethodCall("com.canonical.Unity",
94 "/com/canonical/Unity/Session",
95 "com.canonical.Unity.Session",
96 method);
97 QDBusConnection::sessionBus().asyncCall(msg);
100void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
102 Q_UNUSED(arg_1);
103 Q_UNUSED(max_wait);
104 Q_UNUSED(inhibitors);
106 const Action action = (Action)type;
108 switch (action)
109 {
110 case Action::LOGOUT:
111 performAsyncCall("RequestLogout");
112 break;
114 case Action::REBOOT:
115 performAsyncCall("RequestReboot");
116 break;
118 case Action::SHUTDOWN:
119 performAsyncCall("RequestShutdown");
120 break;
122 default:
123 break;
124 }