on xenial help sign in
Add reboot/shutdown
commitc9cffcb6fbbae0808f50bcd6a0f74155d4643195 authorYing-Chun Liu <paul.liu@canonical.com> dateTue 27 May 2014, 23:43 (12 years ago) parent0aca848
2 files changed+94−4
plugins/Unity/Session/dbusunitysessionservice.cpp+33 plugins/Unity/Session/dbusunitysessionservice.h+61−4
plugins/Unity/Session/dbusunitysessionservice.cpp+33
@@ -19,6 +19,7 @@
1919
2020// Qt
2121#include <QDBusConnection>
22+#include <QDBusInterface>
2223
2324DBusUnitySessionService::DBusUnitySessionService() : QObject()
2425{
@@ -44,3 +45,35 @@ void DBusUnitySessionService::RequestLogout()
4445{
4546 Q_EMIT logoutRequested(false);
4647}
48+
49+void DBusUnitySessionService::Reboot()
50+{
51+ QDBusConnection connection = QDBusConnection::systemBus();
52+ QDBusInterface iface1 ("org.freedesktop.login1",
53+ "/org/freedesktop/login1",
54+ "org.freedesktop.login1.Manager",
55+ connection);
56+
57+ iface1.call("Reboot", false);
58+}
59+
60+void DBusUnitySessionService::RequestReboot()
61+{
62+ Q_EMIT rebootRequested(false);
63+}
64+
65+void DBusUnitySessionService::Shutdown()
66+{
67+ QDBusConnection connection = QDBusConnection::systemBus();
68+ QDBusInterface iface1 ("org.freedesktop.login1",
69+ "/org/freedesktop/login1",
70+ "org.freedesktop.login1.Manager",
71+ connection);
72+
73+ iface1.call("PowerOff", false);
74+}
75+
76+void DBusUnitySessionService::RequestShutdown()
77+{
78+ Q_EMIT shutdownRequested(false);
79+}
plugins/Unity/Session/dbusunitysessionservice.h+61−4
@@ -46,6 +46,27 @@ Q_SIGNALS:
4646 */
4747 void logoutRequested(bool have_inhibitors);
4848
49+ /**
50+ * rebootRequested signal
51+ *
52+ * This signal is emitted when some applications request the system to
53+ * reboot.
54+ * @param have_inhibitors if there are any special running applications
55+ * which inhibit the reboot.
56+ */
57+ void rebootRequested(bool have_inhibitors);
58+
59+ /**
60+ * shutdownRequested signal
61+ *
62+ * This signal is emitted when some applications request the system to
63+ * shutdown.
64+ * @param have_inhibitors if there are any special running applications
65+ * which inhibit the shutdown.
66+ */
67+ void shutdownRequested(bool have_inhibitors);
68+
69+
4970 /**
5071 * logoutReady signal
5172 *
@@ -61,22 +82,58 @@ public Q_SLOTS:
6182 * This method directly logout the system without user's confirmation.
6283 * Ordinary applications should avoid calling this method. Please call
6384 * RequestLogout() to ask the user to decide logout or not.
64− * This method will stop all the running applications and then signal
65− * logoutReady when all the apps stopped.
6685 */
6786 Q_SCRIPTABLE void Logout();
6887
88+ /**
89+ * Reboot the system.
90+ *
91+ * This method directly reboot the system without user's confirmation.
92+ * Ordinary applications should avoid calling this method. Please call
93+ * RequestReboot() to ask the user to decide reboot or not.
94+ */
95+ Q_SCRIPTABLE void Reboot();
96+
97+ /**
98+ * Shutdown the system.
99+ *
100+ * This method directly shutdown the system without user's confirmation.
101+ * Ordinary applications should avoid calling this method. Please call
102+ * RequestShutdown() to ask the user to decide shutdown or not.
103+ */
104+ Q_SCRIPTABLE void Shutdown();
105+
69106 /**
70107 * Issue a logout request.
71108 *
72109 * This method emit the logoutRequested signal to the shell with a boolean
73110 * which indicates if there's any inhibitors. The shell should receive
74111 * this signal and display a dialog to ask the user to confirm the logout
75− * action. If confirmed, shell can call Logout() method to kill the apps
76− * and then logout
112+ * action. If confirmed, shell can call Logout() method to logout.
77113 */
78114 Q_SCRIPTABLE void RequestLogout();
79115
116+ /**
117+ * Issue a reboot request.
118+ *
119+ * This method emit the rebootRequested signal to the shell with a boolean
120+ * which indicates if there's any inhibitors. The shell should receive
121+ * this signal and display a dialog to ask the user to confirm the reboot
122+ * action. If confirmed, shell can call Reboot() method to reboot
123+ */
124+ Q_SCRIPTABLE void RequestReboot();
125+
126+ /**
127+ * Issue a shutdown request.
128+ *
129+ * This method emit the shutdownRequested signal to the shell with a
130+ * boolean which indicates if there's any inhibitors.
131+ * The shell should receive
132+ * this signal and display a dialog to ask the user to confirm the reboot
133+ * action. If confirmed, shell can call Shutdown() method to reboot
134+ */
135+ Q_SCRIPTABLE void RequestShutdown();
136+
80137};
81138
82139#endif // DBUSUNITYSESSIONSERVICE_H