on db15929 help sign in
unity8/plugins/Unity/Session/dbusunitysessionservice.h
356 lines 10.0 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();
110public Q_SLOTS:
111 /**
112 * Logout the system.
113 *
114 * This method directly logs out the system without user's confirmation.
115 * Ordinary applications should avoid calling this method. Please call
116 * RequestLogout() to ask the user to decide logout or not.
117 */
118 Q_SCRIPTABLE void Logout();
120 /**
121 * Reboot the system.
122 *
123 * This method directly reboots the system without user's confirmation.
124 * Ordinary applications should avoid calling this method. Please call
125 * RequestReboot() to ask the user to decide reboot or not.
126 */
127 Q_SCRIPTABLE void Reboot();
129 /**
130 * Shutdown the system.
131 *
132 * This method directly shuts down the system without user's confirmation.
133 * Ordinary applications should avoid calling this method. Please call
134 * RequestShutdown() to ask the user to decide shutdown or not.
135 */
136 Q_SCRIPTABLE void Shutdown();
138 /**
139 * Suspend the system
140 *
141 * This method puts the system into sleep without user's confirmation.
142 */
143 Q_SCRIPTABLE void Suspend();
145 /**
146 * Hibernate the system
147 *
148 * This method puts the system into hibernation without user's confirmation.
149 */
150 Q_SCRIPTABLE void Hibernate();
152 /**
153 * Hybrid sleep
154 *
155 * This method puts the system into hybrid sleep without user's confirmation.
156 *
157 * @since unity8
158 */
159 Q_SCRIPTABLE void HybridSleep();
161 /**
162 * Issue a logout request.
163 *
164 * This method emits the LogoutRequested signal to the shell with a boolean
165 * which indicates if there's any inhibitors. The shell should receive
166 * this signal and display a dialog to ask the user to confirm the logout
167 * action. If confirmed, shell can call Logout() method to logout.
168 */
169 Q_SCRIPTABLE void RequestLogout();
171 /**
172 * Issue a reboot request.
173 *
174 * This method emits the RebootRequested signal to the shell with a boolean
175 * which indicates if there's any inhibitors. The shell should receive
176 * this signal and display a dialog to ask the user to confirm the reboot
177 * action. If confirmed, shell can call Reboot() method to reboot.
178 */
179 Q_SCRIPTABLE void RequestReboot();
181 /**
182 * Issue a shutdown request.
183 *
184 * This method emits the ShutdownRequested signal to the shell with a
185 * boolean which indicates if there's any inhibitors.
186 * The shell should receive
187 * this signal and display a dialog to ask the user to confirm the reboot
188 * action. If confirmed, shell can call Shutdown() method to shutdown.
189 */
190 Q_SCRIPTABLE void RequestShutdown();
192 /**
193 * Issue an EndSession request.
194 *
195 * This method calls the EndSession() Upstart DBus method on the
196 * current DBus session bus.
197 */
198 Q_SCRIPTABLE void EndSession();
200 /**
201 * @return whether the system is capable of hibernating
202 */
203 Q_SCRIPTABLE bool CanHibernate() const;
205 /**
206 * @return whether the system is capable of suspending
207 */
208 Q_SCRIPTABLE bool CanSuspend() const;
210 /**
211 * @return whether the system is capable of hybrid sleep
212 * @since unity8
213 */
214 Q_SCRIPTABLE bool CanHybridSleep() const;
216 /**
217 * @return whether the system is capable of rebooting
218 * @since unity8
219 */
220 Q_SCRIPTABLE bool CanReboot() const;
222 /**
223 * @return whether the system is capable of shutting down
224 */
225 Q_SCRIPTABLE bool CanShutdown() const;
227 /**
228 * @return whether the system is capable of locking the session
229 */
230 Q_SCRIPTABLE bool CanLock() const;
232 /**
233 * @return the login name of the current user
234 */
235 Q_SCRIPTABLE QString UserName() const;
237 /**
238 * @return the real name of the current user
239 */
240 Q_SCRIPTABLE QString RealName() const;
242 /**
243 * @return the local hostname
244 */
245 Q_SCRIPTABLE QString HostName() const;
247 /**
248 * Request that the session get locked, emits signal LockRequested()
249 */
250 Q_SCRIPTABLE void PromptLock();
252 /**
253 * Locks the session immediately
254 */
255 Q_SCRIPTABLE void Lock();
257 /**
258 * @return whether the session is currently locked
259 */
260 Q_SCRIPTABLE bool IsLocked() const;
261};
263class DBusGnomeSessionManagerWrapper : public UnityDBusObject
265 Q_OBJECT
266 Q_CLASSINFO("D-Bus Interface", "org.gnome.SessionManager.EndSessionDialog")
268public:
269 DBusGnomeSessionManagerWrapper();
270 ~DBusGnomeSessionManagerWrapper() = default;
272public Q_SLOTS:
273 Q_SCRIPTABLE void Open(const unsigned int type, const unsigned int arg_1, const unsigned int max_wait, const QList<QDBusObjectPath> &inhibitors);
275private:
276 void performAsyncCall(const QString &method);
277};
279class DBusGnomeScreensaverWrapper: public UnityDBusObject
281 Q_OBJECT
282 Q_CLASSINFO("D-Bus Interface", "org.gnome.ScreenSaver")
284public:
285 DBusGnomeScreensaverWrapper();
286 ~DBusGnomeScreensaverWrapper() = default;
288public Q_SLOTS:
289 /**
290 * @return whether the session is currently locked (screensaver is on)
291 */
292 Q_SCRIPTABLE bool GetActive() const;
294 /**
295 * Locks the session immediately if @p lock is true
296 */
297 Q_SCRIPTABLE void SetActive(bool lock);
299 /**
300 * Locks the session immediately
301 */
302 Q_SCRIPTABLE void Lock();
304 /**
305 * @return the number of seconds elapsed since the screensaver had been active
306 */
307 Q_SCRIPTABLE quint32 GetActiveTime() const;
309 Q_SCRIPTABLE void SimulateUserActivity();
311Q_SIGNALS:
312 void ActiveChanged(bool active);
313};
315class DBusScreensaverWrapper: public UnityDBusObject
317 Q_OBJECT
318 Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
320public:
321 DBusScreensaverWrapper();
322 ~DBusScreensaverWrapper() = default;
324public Q_SLOTS:
325 /**
326 * @return whether the session is currently locked (screensaver is on)
327 */
328 Q_SCRIPTABLE bool GetActive() const;
330 /**
331 * Locks the session immediately if @p lock is true
332 */
333 Q_SCRIPTABLE bool SetActive(bool lock);
335 /**
336 * Locks the session immediately
337 */
338 Q_SCRIPTABLE void Lock();
340 /**
341 * @return the number of seconds elapsed since the screensaver had been active
342 */
343 Q_SCRIPTABLE quint32 GetActiveTime() const;
345 /**
346 * @return the number of seconds that this session has been idle
347 */
348 Q_SCRIPTABLE quint32 GetSessionIdleTime() const;
350 Q_SCRIPTABLE void SimulateUserActivity();
352Q_SIGNALS:
353 void ActiveChanged(bool active);
354};
356#endif // DBUSUNITYSESSIONSERVICE_H