2 * Copyright (C) 2014 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import Unity.Application 0.1
20 import Unity.Session 0.1
21 import GlobalShortcut 1.0
22 import Ubuntu.Components 1.3
23 import Unity.Platform 1.0
29 // to be set from outside, useful mostly for testing purposes
30 property var unitySessionService: DBusUnitySessionService
31 property var closeAllApps: function() {
33 var app = ApplicationManager.get(0);
37 ApplicationManager.stopApplication(app.appId);
40 property string usageScenario
42 signal powerOffClicked();
44 function showPowerDialog() {
48 GlobalShortcut { // reboot/shutdown dialog
49 shortcut: Qt.Key_PowerDown
51 onTriggered: root.unitySessionService.RequestShutdown()
54 GlobalShortcut { // reboot/shutdown dialog
55 shortcut: Qt.Key_PowerOff
57 onTriggered: root.unitySessionService.RequestShutdown()
60 GlobalShortcut { // sleep
61 shortcut: Qt.Key_Sleep
62 onTriggered: root.unitySessionService.Suspend()
65 GlobalShortcut { // hibernate
66 shortcut: Qt.Key_Hibernate
67 onTriggered: root.unitySessionService.Hibernate()
70 GlobalShortcut { // logout/lock dialog
71 shortcut: Qt.Key_LogOff
72 onTriggered: root.unitySessionService.RequestLogout()
75 GlobalShortcut { // logout/lock dialog
76 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
77 onTriggered: root.unitySessionService.RequestLogout()
80 GlobalShortcut { // lock screen
81 shortcut: Qt.Key_ScreenSaver
82 onTriggered: lightDM.greeter.showGreeter()
85 GlobalShortcut { // lock screen
86 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
87 onTriggered: lightDM.greeter.showGreeter()
91 id: d // private stuff
92 objectName: "dialogsPrivate"
94 function showPowerDialog() {
95 if (!dialogLoader.active) {
96 dialogLoader.sourceComponent = powerDialogComponent;
97 dialogLoader.focus = true;
98 dialogLoader.active = true;
105 objectName: "dialogLoader"
110 LightDM {id: lightDM} // Provide backend access
113 id: logoutDialogComponent
116 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
117 text: i18n.tr("Are you sure you want to log out?")
119 text: i18n.ctr("Button: Lock the system", "Lock")
121 lightDM.greeter.showGreeter()
126 text: i18n.ctr("Button: Log out from the system", "Log Out")
128 unitySessionService.logout();
133 text: i18n.tr("Cancel")
142 id: shutdownDialogComponent
145 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
146 text: i18n.tr("Are you sure you want to shut down?")
148 text: i18n.ctr("Button: Reboot the system", "Reboot")
151 unitySessionService.reboot();
152 shutdownDialog.hide();
154 color: UbuntuColors.lightGrey
157 text: i18n.ctr("Button: Shut down the system", "Shut down")
160 unitySessionService.shutdown();
161 shutdownDialog.hide();
163 color: UbuntuColors.red
166 text: i18n.tr("Cancel")
168 shutdownDialog.hide();
170 color: UbuntuColors.lightGrey
176 id: rebootDialogComponent
179 title: i18n.ctr("Title: Reboot dialog", "Reboot")
180 text: i18n.tr("Are you sure you want to reboot?")
186 color: UbuntuColors.lightGrey
192 unitySessionService.reboot();
195 color: UbuntuColors.red
201 id: powerDialogComponent
204 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
205 text: i18n.tr("Are you sure you would like\nto power off?")
207 text: i18n.ctr("Button: Power off the system", "Power off")
211 root.powerOffClicked();
213 color: UbuntuColors.red
216 text: i18n.ctr("Button: Restart the system", "Restart")
219 unitySessionService.reboot();
222 color: UbuntuColors.lightGrey
225 text: i18n.tr("Cancel")
229 color: UbuntuColors.lightGrey
235 target: root.unitySessionService
238 // Display a dialog to ask the user to confirm.
239 if (!dialogLoader.active) {
240 dialogLoader.sourceComponent = logoutDialogComponent;
241 dialogLoader.focus = true;
242 dialogLoader.active = true;
246 onShutdownRequested: {
247 // Display a dialog to ask the user to confirm.
248 if (!dialogLoader.active) {
249 dialogLoader.sourceComponent = shutdownDialogComponent;
250 dialogLoader.focus = true;
251 dialogLoader.active = true;
256 // Display a dialog to ask the user to confirm.
257 if (!dialogLoader.active) {
258 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
259 // than shutdown when clicking on the "Shutdown..." menu item
260 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
261 dialogLoader.sourceComponent = shutdownDialogComponent;
262 dialogLoader.focus = true;
263 dialogLoader.active = true;
270 unitySessionService.endSession();