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  void unlocked();
110 
111 public Q_SLOTS:
119  Q_SCRIPTABLE void Logout();
120 
128  Q_SCRIPTABLE void Reboot();
129 
137  Q_SCRIPTABLE void Shutdown();
138 
144  Q_SCRIPTABLE void Suspend();
145 
151  Q_SCRIPTABLE void Hibernate();
152 
160  Q_SCRIPTABLE void HybridSleep();
161 
170  Q_SCRIPTABLE void RequestLogout();
171 
180  Q_SCRIPTABLE void RequestReboot();
181 
191  Q_SCRIPTABLE void RequestShutdown();
192 
199  Q_SCRIPTABLE void EndSession();
200 
204  Q_SCRIPTABLE bool CanHibernate() const;
205 
209  Q_SCRIPTABLE bool CanSuspend() const;
210 
215  Q_SCRIPTABLE bool CanHybridSleep() const;
216 
221  Q_SCRIPTABLE bool CanReboot() const;
222 
226  Q_SCRIPTABLE bool CanShutdown() const;
227 
231  Q_SCRIPTABLE bool CanLock() const;
232 
236  Q_SCRIPTABLE QString UserName() const;
237 
241  Q_SCRIPTABLE QString RealName() const;
242 
246  Q_SCRIPTABLE QString HostName() const;
247 
251  Q_SCRIPTABLE void PromptLock();
252 
256  Q_SCRIPTABLE void Lock();
257 
261  Q_SCRIPTABLE bool IsLocked() const;
262 
263 private Q_SLOTS:
264  void doUnlock();
265 
266 private:
267  void switchToGreeter();
268 };
269 
270 class DBusGnomeSessionManagerWrapper : public UnityDBusObject
271 {
272  Q_OBJECT
273  Q_CLASSINFO("D-Bus Interface", "org.gnome.SessionManager.EndSessionDialog")
274 
275 public:
276  DBusGnomeSessionManagerWrapper();
277  ~DBusGnomeSessionManagerWrapper() = default;
278 
279 public 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);
281 
282 private:
283  void performAsyncCall(const QString &method);
284 };
285 
286 class DBusGnomeScreensaverWrapper: public UnityDBusObject
287 {
288  Q_OBJECT
289  Q_CLASSINFO("D-Bus Interface", "org.gnome.ScreenSaver")
290 
291 public:
292  DBusGnomeScreensaverWrapper();
293  ~DBusGnomeScreensaverWrapper() = default;
294 
295 public Q_SLOTS:
299  Q_SCRIPTABLE bool GetActive() const;
300 
304  Q_SCRIPTABLE void SetActive(bool lock);
305 
309  Q_SCRIPTABLE void Lock();
310 
314  Q_SCRIPTABLE quint32 GetActiveTime() const;
315 
316  Q_SCRIPTABLE void SimulateUserActivity();
317 
318 Q_SIGNALS:
319  void ActiveChanged(bool active);
320 };
321 
322 class DBusScreensaverWrapper: public UnityDBusObject
323 {
324  Q_OBJECT
325  Q_CLASSINFO("D-Bus Interface", "org.freedesktop.ScreenSaver")
326 
327 public:
328  DBusScreensaverWrapper();
329  ~DBusScreensaverWrapper() = default;
330 
331 public Q_SLOTS:
335  Q_SCRIPTABLE bool GetActive() const;
336 
340  Q_SCRIPTABLE bool SetActive(bool lock);
341 
345  Q_SCRIPTABLE void Lock();
346 
350  Q_SCRIPTABLE quint32 GetActiveTime() const;
351 
355  Q_SCRIPTABLE quint32 GetSessionIdleTime() const;
356 
357  Q_SCRIPTABLE void SimulateUserActivity();
358 
359 Q_SIGNALS:
360  void ActiveChanged(bool active);
361 };
362 
363 #endif // DBUSUNITYSESSIONSERVICE_H