Unity 8
dbusunitysessionservice.cpp
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  */
16 
17 // local
18 #include "dbusunitysessionservice.h"
19 
20 // Qt
21 #include <QDBusConnection>
22 #include <QDBusInterface>
23 
24 DBusUnitySessionService::DBusUnitySessionService()
25  : UnityDBusObject("/com/canonical/Unity/Session", "com.canonical.Unity")
26 {
27 }
28 
29 DBusUnitySessionService::~DBusUnitySessionService()
30 {
31 }
32 
34 {
35  Q_EMIT logoutReady();
36 }
37 
39 {
40  QDBusConnection connection = QDBusConnection::sessionBus();
41  QDBusInterface iface1 ("com.ubuntu.Upstart",
42  "/com/ubuntu/Upstart",
43  "com.ubuntu.Upstart0_6",
44  connection);
45 
46  iface1.call("EndSession");
47 }
48 
50 {
51  Q_EMIT logoutRequested(false);
52 }
53 
55 {
56  QDBusConnection connection = QDBusConnection::systemBus();
57  QDBusInterface iface1 ("org.freedesktop.login1",
58  "/org/freedesktop/login1",
59  "org.freedesktop.login1.Manager",
60  connection);
61 
62  iface1.call("Reboot", false);
63 }
64 
66 {
67  Q_EMIT rebootRequested(false);
68 }
69 
71 {
72  QDBusConnection connection = QDBusConnection::systemBus();
73  QDBusInterface iface1 ("org.freedesktop.login1",
74  "/org/freedesktop/login1",
75  "org.freedesktop.login1.Manager",
76  connection);
77 
78  iface1.call("PowerOff", false);
79 }
80 
82 {
83  Q_EMIT shutdownRequested(false);
84 }
85 
86 enum class Action : unsigned
87 {
88  LOGOUT = 0,
89  SHUTDOWN,
90  REBOOT,
91  NONE
92 };
93 
94 DBusGnomeSessionManagerWrapper::DBusGnomeSessionManagerWrapper()
95  : UnityDBusObject("/org/gnome/SessionManager/EndSessionDialog", "com.canonical.Unity")
96 {
97 }
98 
99 DBusGnomeSessionManagerWrapper::~DBusGnomeSessionManagerWrapper()
100 {
101 }
102 
103 void DBusGnomeSessionManagerWrapper::Open(const unsigned type, const unsigned arg_1, const unsigned max_wait, const QList<QDBusObjectPath> &inhibitors)
104 {
105  Q_UNUSED(arg_1);
106  Q_UNUSED(max_wait);
107  Q_UNUSED(inhibitors);
108 
109  QDBusConnection connection = QDBusConnection::sessionBus();
110  QDBusInterface iface1 ("com.canonical.Unity",
111  "/com/canonical/Unity/Session",
112  "com.canonical.Unity.Session",
113  connection);
114 
115  Action action = (Action)type;
116 
117  switch (action)
118  {
119  case Action::LOGOUT:
120  iface1.call("RequestLogout");
121  break;
122 
123  case Action::REBOOT:
124  iface1.call("RequestShutdown");
125  break;
126 
127  case Action::SHUTDOWN:
128  break;
129 
130  default:
131  break;
132  }
133 }
Q_SCRIPTABLE void RequestShutdown()
Q_SCRIPTABLE void shutdownRequested(bool have_inhibitors)
Q_SCRIPTABLE void rebootRequested(bool have_inhibitors)
Q_SCRIPTABLE void logoutRequested(bool have_inhibitors)