on 086eb86 help sign in
unity8/plugins/Unity/Session/dbusunitysessionservice.cpp
133 lines 3.4 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 <QDBusConnection>
22#include <QDBusInterface>
24DBusUnitySessionService::DBusUnitySessionService()
25 : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
29DBusUnitySessionService::~DBusUnitySessionService()
33void DBusUnitySessionService::Logout()
35 Q_EMIT logoutReady();
38void DBusUnitySessionService::EndSession()
40 QDBusConnection connection = QDBusConnection::sessionBus();
41 QDBusInterface iface1 ("com.ubuntu.Upstart",
42 "/com/ubuntu/Upstart",
43 "com.ubuntu.Upstart0_6",
44 connection);
46 iface1.call("EndSession");
49void DBusUnitySessionService::RequestLogout()
51 Q_EMIT logoutRequested(false);
54void DBusUnitySessionService::Reboot()
56 QDBusConnection connection = QDBusConnection::systemBus();
57 QDBusInterface iface1 ("org.freedesktop.login1",
58 "/org/freedesktop/login1",
59 "org.freedesktop.login1.Manager",
60 connection);
62 iface1.call("Reboot", false);
65void DBusUnitySessionService::RequestReboot()
67 Q_EMIT rebootRequested(false);
70void DBusUnitySessionService::Shutdown()
72 QDBusConnection connection = QDBusConnection::systemBus();
73 QDBusInterface iface1 ("org.freedesktop.login1",
74 "/org/freedesktop/login1",
75 "org.freedesktop.login1.Manager",
76 connection);
78 iface1.call("PowerOff", false);
81void DBusUnitySessionService::RequestShutdown()
83 Q_EMIT shutdownRequested(false);
86enum class Action : unsigned
88 LOGOUT = 0,
89 SHUTDOWN,
90 REBOOT,
91 NONE
92};
94DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
95 : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
99DBusGnomeSessionManagerWrapper::~DBusGnomeSessionManagerWrapper()
103void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
105 Q_UNUSED(arg_1);
106 Q_UNUSED(max_wait);
107 Q_UNUSED(inhibitors);
109 QDBusConnection connection = QDBusConnection::sessionBus();
110 QDBusInterface iface1 ("com.canonical.Unity",
111 "/com/canonical/Unity/Session",
112 "com.canonical.Unity.Session",
113 connection);
115 Action action = (Action)type;
117 switch (action)
118 {
119 case Action::LOGOUT:
120 iface1.call("RequestLogout");
121 break;
123 case Action::REBOOT:
124 iface1.call("RequestShutdown");
125 break;
127 case Action::SHUTDOWN:
128 break;
130 default:
131 break;
132 }