Unity 8
dbusunitysessionservice.h
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  */
16 
17 #ifndef DBUSUNITYSESSIONSERVICE_H
18 #define DBUSUNITYSESSIONSERVICE_H
19 
20 #include <QDBusObjectPath>
21 
22 #include "unitydbusobject.h"
23 
24 typedef QList<QDBusObjectPath> QDbusList;
25 Q_DECLARE_METATYPE(QList<QDBusObjectPath>)
26 
27 
34 class DBusUnitySessionService : public UnityDBusObject
35 {
36  Q_OBJECT
37  Q_CLASSINFO("D-Bus Interface", "com.canonical.Unity.Session")
38 
39 public:
41  ~DBusUnitySessionService() = default;
42 
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(); }
48 
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
51 Q_SIGNALS:
60  Q_SCRIPTABLE void LogoutRequested(bool have_inhibitors);
61  void logoutRequested(bool have_inhibitors);
62 
71  Q_SCRIPTABLE void RebootRequested(bool have_inhibitors);
72  void rebootRequested(bool have_inhibitors);
73 
82  Q_SCRIPTABLE void ShutdownRequested(bool have_inhibitors);
83  void shutdownRequested(bool have_inhibitors);
84 
91  Q_SCRIPTABLE void LogoutReady();
92  void logoutReady();
93 
97  Q_SCRIPTABLE void LockRequested();
98  void lockRequested();
99 
103  Q_SCRIPTABLE void Locked();
104 
108  Q_SCRIPTABLE void Unlocked();
109 
110 public Q_SLOTS:
118  Q_SCRIPTABLE void Logout();
119 
127  Q_SCRIPTABLE void Reboot();
128 
136  Q_SCRIPTABLE void Shutdown();
137 
143  Q_SCRIPTABLE void Suspend();
144 
150  Q_SCRIPTABLE void Hibernate();
151 
159  Q_SCRIPTABLE void HybridSleep();
160 
169  Q_SCRIPTABLE void RequestLogout();
170 
179  Q_SCRIPTABLE void RequestReboot();
180 
190  Q_SCRIPTABLE void RequestShutdown();
191 
198  Q_SCRIPTABLE void EndSession();
199 
203  Q_SCRIPTABLE bool CanHibernate() const;
204 
208  Q_SCRIPTABLE bool CanSuspend() const;
209 
214  Q_SCRIPTABLE bool CanHybridSleep() const;
215 
220  Q_SCRIPTABLE bool CanReboot() const;
221 
225  Q_SCRIPTABLE bool CanShutdown() const;
226 
230  Q_SCRIPTABLE bool CanLock() const;
231 
235  Q_SCRIPTABLE QString UserName() const;
236 
240  Q_SCRIPTABLE QString RealName() const;
241 
245  Q_SCRIPTABLE QString HostName() const;
246 
250  Q_SCRIPTABLE void PromptLock();
251 
255  Q_SCRIPTABLE void Lock();
256 
260  Q_SCRIPTABLE bool IsLocked() const;
261 };
262 
263 class DBusGnomeSessionManagerWrapper : public UnityDBusObject
264 {
265  Q_OBJECT
266  Q_CLASSINFO("D-Bus Interface", "org.gnome.SessionManager.EndSessionDialog")
267 
268 public:
269  DBusGnomeSessionManagerWrapper();
270  ~DBusGnomeSessionManagerWrapper() = default;
271 
272 public 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);
274 
275 private:
276  void performAsyncCall(const QString &method);
277 };
278 
279 class DBusGnomeScreensaverWrapper: public UnityDBusObject
280 {
281  Q_OBJECT
282  Q_CLASSINFO("D-Bus Interface", "org.gnome.ScreenSaver")
283 
284 public:
285  DBusGnomeScreensaverWrapper();
286  ~DBusGnomeScreensaverWrapper() = default;
287 
288 public Q_SLOTS:
292  Q_SCRIPTABLE bool GetActive() const;
293 
297  Q_SCRIPTABLE void SetActive(bool lock);
298 
302  Q_SCRIPTABLE void Lock();
303 
307  Q_SCRIPTABLE quint32 GetActiveTime() const;
308 
309  Q_SCRIPTABLE void SimulateUserActivity();
310 
311 Q_SIGNALS:
312  void ActiveChanged(bool active);
313 };
314 
315 class DBusScreensaverWrapper: public UnityDBusObject
316 {
317  Q_OBJECT
318  Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
319 
320 public:
321  DBusScreensaverWrapper();
322  ~DBusScreensaverWrapper() = default;
323 
324 public Q_SLOTS:
328  Q_SCRIPTABLE bool GetActive() const;
329 
333  Q_SCRIPTABLE bool SetActive(bool lock);
334 
338  Q_SCRIPTABLE void Lock();
339 
343  Q_SCRIPTABLE quint32 GetActiveTime() const;
344 
348  Q_SCRIPTABLE quint32 GetSessionIdleTime() const;
349 
350  Q_SCRIPTABLE void SimulateUserActivity();
351 
352 Q_SIGNALS:
353  void ActiveChanged(bool active);
354 };
355 
356 #endif // DBUSUNITYSESSIONSERVICE_H