on vivid help sign in
unity8/plugins/Unity/Session/dbusunitysessionservice.h
363 lines 10 kB history raw
1/*
2 * Copyright (C) 2014, 2015 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#ifndef DBUSUNITYSESSIONSERVICE_H
18#define DBUSUNITYSESSIONSERVICE_H
20#include <QDBusObjectPath>
22#include "unitydbusobject.h"
24typedef QList<QDBusObjectPath> QDbusList;
25Q_DECLARE_METATYPE(QList<QDBusObjectPath>)
27/**
28 * DBusUnitySessionService provides com.canonical.Unity.Session dbus
29 * interface.
30 *
31 * com.canonical.Unity.Session interface provides public methods
32 * and signals to handle eg. Logout/Reboot/Shutdown.
33 */
34class DBusUnitySessionService : public UnityDBusObject
36 Q_OBJECT
37 Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
39public:
40 DBusUnitySessionService();
41 ~DBusUnitySessionService() = default;
43 // For use in QML. Javascript doesn't accept functions beginning with capital letters
44 Q_INVOKABLE void logout() { Logout(); }
45 Q_INVOKABLE void reboot() { Reboot(); }
46 Q_INVOKABLE void shutdown() { Shutdown(); }
47 Q_INVOKABLE void endSession() { EndSession(); }
49 // TODO: remove duplicate signals and split D-Bus and QML API's
50 // Apparently QML needs the signals in lowercase, while DBUS spec needs the uppercase version
51Q_SIGNALS:
52 /**
53 * LogoutRequested signal
54 *
55 * This signal is emitted when some applications request the system to
56 * logout.
57 * @param have_inhibitors if there are any special running applications
58 * which inhibit the logout.
59 */
60 Q_SCRIPTABLE void LogoutRequested(bool have_inhibitors);
61 void logoutRequested(bool have_inhibitors);
63 /**
64 * RebootRequested signal
65 *
66 * This signal is emitted when some applications request the system to
67 * reboot.
68 * @param have_inhibitors if there are any special running applications
69 * which inhibit the reboot.
70 */
71 Q_SCRIPTABLE void RebootRequested(bool have_inhibitors);
72 void rebootRequested(bool have_inhibitors);
74 /**
75 * ShutdownRequested signal
76 *
77 * This signal is emitted when some applications request the system to
78 * shutdown.
79 * @param have_inhibitors if there are any special running applications
80 * which inhibit the shutdown.
81 */
82 Q_SCRIPTABLE void ShutdownRequested(bool have_inhibitors);
83 void shutdownRequested(bool have_inhibitors);
85 /**
86 * LogoutReady signal
87 *
88 * This signal is emitted when all the apps are closed. And the system
89 * is safe to logout.
90 */
91 Q_SCRIPTABLE void LogoutReady();
92 void logoutReady();
94 /**
95 * Emitted as a result of calling PromptLock()
96 */
97 Q_SCRIPTABLE void LockRequested();
98 void lockRequested();
100 /**
101 * Emitted after the session has been locked.
102 */
103 Q_SCRIPTABLE void Locked();
105 /**
106 * Emitted after the session has been unlocked.
107 */
108 Q_SCRIPTABLE void Unlocked();
109 void unlocked();
111public Q_SLOTS:
112 /**
113 * Logout the system.
114 *
115 * This method directly logs out the system without user's confirmation.
116 * Ordinary applications should avoid calling this method. Please call
117 * RequestLogout() to ask the user to decide logout or not.
118 */
119 Q_SCRIPTABLE void Logout();
121 /**
122 * Reboot the system.
123 *
124 * This method directly reboots the system without user's confirmation.
125 * Ordinary applications should avoid calling this method. Please call
126 * RequestReboot() to ask the user to decide reboot or not.
127 */
128 Q_SCRIPTABLE void Reboot();
130 /**
131 * Shutdown the system.
132 *
133 * This method directly shuts down the system without user's confirmation.
134 * Ordinary applications should avoid calling this method. Please call
135 * RequestShutdown() to ask the user to decide shutdown or not.
136 */
137 Q_SCRIPTABLE void Shutdown();
139 /**
140 * Suspend the system
141 *
142 * This method puts the system into sleep without user's confirmation.
143 */
144 Q_SCRIPTABLE void Suspend();
146 /**
147 * Hibernate the system
148 *
149 * This method puts the system into hibernation without user's confirmation.
150 */
151 Q_SCRIPTABLE void Hibernate();
153 /**
154 * Hybrid sleep
155 *
156 * This method puts the system into hybrid sleep without user's confirmation.
157 *
158 * @since unity8
159 */
160 Q_SCRIPTABLE void HybridSleep();
162 /**
163 * Issue a logout request.
164 *
165 * This method emits the LogoutRequested signal to the shell with a boolean
166 * which indicates if there's any inhibitors. The shell should receive
167 * this signal and display a dialog to ask the user to confirm the logout
168 * action. If confirmed, shell can call Logout() method to logout.
169 */
170 Q_SCRIPTABLE void RequestLogout();
172 /**
173 * Issue a reboot request.
174 *
175 * This method emits the RebootRequested signal to the shell with a boolean
176 * which indicates if there's any inhibitors. The shell should receive
177 * this signal and display a dialog to ask the user to confirm the reboot
178 * action. If confirmed, shell can call Reboot() method to reboot.
179 */
180 Q_SCRIPTABLE void RequestReboot();
182 /**
183 * Issue a shutdown request.
184 *
185 * This method emits the ShutdownRequested signal to the shell with a
186 * boolean which indicates if there's any inhibitors.
187 * The shell should receive
188 * this signal and display a dialog to ask the user to confirm the reboot
189 * action. If confirmed, shell can call Shutdown() method to shutdown.
190 */
191 Q_SCRIPTABLE void RequestShutdown();
193 /**
194 * Issue an EndSession request.
195 *
196 * This method calls the EndSession() Upstart DBus method on the
197 * current DBus session bus.
198 */
199 Q_SCRIPTABLE void EndSession();
201 /**
202 * @return whether the system is capable of hibernating
203 */
204 Q_SCRIPTABLE bool CanHibernate() const;
206 /**
207 * @return whether the system is capable of suspending
208 */
209 Q_SCRIPTABLE bool CanSuspend() const;
211 /**
212 * @return whether the system is capable of hybrid sleep
213 * @since unity8
214 */
215 Q_SCRIPTABLE bool CanHybridSleep() const;
217 /**
218 * @return whether the system is capable of rebooting
219 * @since unity8
220 */
221 Q_SCRIPTABLE bool CanReboot() const;
223 /**
224 * @return whether the system is capable of shutting down
225 */
226 Q_SCRIPTABLE bool CanShutdown() const;
228 /**
229 * @return whether the system is capable of locking the session
230 */
231 Q_SCRIPTABLE bool CanLock() const;
233 /**
234 * @return the login name of the current user
235 */
236 Q_SCRIPTABLE QString UserName() const;
238 /**
239 * @return the real name of the current user
240 */
241 Q_SCRIPTABLE QString RealName() const;
243 /**
244 * @return the local hostname
245 */
246 Q_SCRIPTABLE QString HostName() const;
248 /**
249 * Request that the session get locked, emits signal LockRequested()
250 */
251 Q_SCRIPTABLE void PromptLock();
253 /**
254 * Locks the session immediately
255 */
256 Q_SCRIPTABLE void Lock();
258 /**
259 * @return whether the session is currently locked
260 */
261 Q_SCRIPTABLE bool IsLocked() const;
263private Q_SLOTS:
264 void doUnlock();
266private:
267 void switchToGreeter();
268};
270class DBusGnomeSessionManagerWrapper : public UnityDBusObject
272 Q_OBJECT
273 Q_CLASSINFO("D-Bus Interface", "org.gnome.SessionManager.EndSessionDialog")
275public:
276 DBusGnomeSessionManagerWrapper();
277 ~DBusGnomeSessionManagerWrapper() = default;
279public Q_SLOTS:
280 Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
282private:
283 void performAsyncCall(const QString &method);
284};
286class DBusGnomeScreensaverWrapper: public UnityDBusObject
288 Q_OBJECT
289 Q_CLASSINFO("D-Bus Interface", "org.gnome.ScreenSaver")
291public:
292 DBusGnomeScreensaverWrapper();
293 ~DBusGnomeScreensaverWrapper() = default;
295public Q_SLOTS:
296 /**
297 * @return whether the session is currently locked (screensaver is on)
298 */
299 Q_SCRIPTABLE bool GetActive() const;
301 /**
302 * Locks the session immediately if @p lock is true
303 */
304 Q_SCRIPTABLE void SetActive(bool lock);
306 /**
307 * Locks the session immediately
308 */
309 Q_SCRIPTABLE void Lock();
311 /**
312 * @return the number of seconds elapsed since the screensaver had been active
313 */
314 Q_SCRIPTABLE quint32 GetActiveTime() const;
316 Q_SCRIPTABLE void SimulateUserActivity();
318Q_SIGNALS:
319 void ActiveChanged(bool active);
320};
322class DBusScreensaverWrapper: public UnityDBusObject
324 Q_OBJECT
325 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
327public:
328 DBusScreensaverWrapper();
329 ~DBusScreensaverWrapper() = default;
331public Q_SLOTS:
332 /**
333 * @return whether the session is currently locked (screensaver is on)
334 */
335 Q_SCRIPTABLE bool GetActive() const;
337 /**
338 * Locks the session immediately if @p lock is true
339 */
340 Q_SCRIPTABLE bool SetActive(bool lock);
342 /**
343 * Locks the session immediately
344 */
345 Q_SCRIPTABLE void Lock();
347 /**
348 * @return the number of seconds elapsed since the screensaver had been active
349 */
350 Q_SCRIPTABLE quint32 GetActiveTime() const;
352 /**
353 * @return the number of seconds that this session has been idle
354 */
355 Q_SCRIPTABLE quint32 GetSessionIdleTime() const;
357 Q_SCRIPTABLE void SimulateUserActivity();
359Q_SIGNALS:
360 void ActiveChanged(bool active);
361};
363#endif // DBUSUNITYSESSIONSERVICE_H