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 Ubuntu.Components 1.1
22 import GlobalShortcut 1.0
28 // to be set from outside, useful mostly for testing purposes
29 property var unitySessionService: DBusUnitySessionService
30 property var closeAllApps: function() {
32 var app = ApplicationManager.get(0);
36 ApplicationManager.stopApplication(app.appId);
39 property string usageScenario
41 signal powerOffClicked();
43 function showPowerDialog() {
47 GlobalShortcut { // reboot/shutdown dialog
48 shortcut: Qt.Key_PowerDown
49 active: root.usageScenario === "desktop"
50 onTriggered: root.unitySessionService.RequestShutdown()
53 GlobalShortcut { // reboot/shutdown dialog
54 shortcut: Qt.Key_PowerOff
55 active: root.usageScenario === "desktop"
56 onTriggered: root.unitySessionService.RequestShutdown()
59 GlobalShortcut { // sleep
60 shortcut: Qt.Key_Sleep
61 onTriggered: root.unitySessionService.Suspend()
64 GlobalShortcut { // hibernate
65 shortcut: Qt.Key_Hibernate
66 onTriggered: root.unitySessionService.Hibernate()
69 GlobalShortcut { // logout/lock dialog
70 shortcut: Qt.Key_LogOff
71 onTriggered: root.unitySessionService.RequestLogout()
74 GlobalShortcut { // logout/lock dialog
75 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
76 onTriggered: root.unitySessionService.RequestLogout()
79 GlobalShortcut { // lock screen
80 shortcut: Qt.Key_ScreenSaver
81 onTriggered: lightDM.greeter.showGreeter()
84 GlobalShortcut { // lock screen
85 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
86 onTriggered: lightDM.greeter.showGreeter()
90 id: d // private stuff
91 objectName: "dialogsPrivate"
93 function showPowerDialog() {
94 if (!dialogLoader.active) {
95 dialogLoader.sourceComponent = powerDialogComponent;
96 dialogLoader.focus = true;
97 dialogLoader.active = true;
104 objectName: "dialogLoader"
109 LightDM {id: lightDM} // Provide backend access
112 id: logoutDialogComponent
115 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
116 text: i18n.tr("Are you sure you want to log out?")
118 text: i18n.ctr("Button: Lock the system", "Lock")
120 lightDM.greeter.showGreeter()
125 text: i18n.ctr("Button: Log out from the system", "Log Out")
127 unitySessionService.logout();
132 text: i18n.tr("Cancel")
141 id: shutdownDialogComponent
144 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
145 text: i18n.tr("Are you sure you want to shut down?")
147 text: i18n.ctr("Button: Reboot the system", "Reboot")
150 unitySessionService.reboot();
151 shutdownDialog.hide();
153 color: UbuntuColors.lightGrey
156 text: i18n.ctr("Button: Shut down the system", "Shut down")
159 unitySessionService.shutdown();
160 shutdownDialog.hide();
162 color: UbuntuColors.red
165 text: i18n.tr("Cancel")
167 shutdownDialog.hide();
169 color: UbuntuColors.lightGrey
175 id: rebootDialogComponent
178 title: i18n.ctr("Title: Reboot dialog", "Reboot")
179 text: i18n.tr("Are you sure you want to reboot?")
185 color: UbuntuColors.lightGrey
191 unitySessionService.reboot();
194 color: UbuntuColors.red
200 id: powerDialogComponent
203 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
204 text: i18n.tr("Are you sure you would like\nto power off?")
206 text: i18n.ctr("Button: Power off the system", "Power off")
210 root.powerOffClicked();
212 color: UbuntuColors.red
215 text: i18n.ctr("Button: Restart the system", "Restart")
218 unitySessionService.reboot();
221 color: UbuntuColors.lightGrey
224 text: i18n.tr("Cancel")
228 color: UbuntuColors.lightGrey
234 target: root.unitySessionService
237 // Display a dialog to ask the user to confirm.
238 if (!dialogLoader.active) {
239 dialogLoader.sourceComponent = logoutDialogComponent;
240 dialogLoader.focus = true;
241 dialogLoader.active = true;
245 onShutdownRequested: {
246 // Display a dialog to ask the user to confirm.
247 if (!dialogLoader.active) {
248 dialogLoader.sourceComponent = shutdownDialogComponent;
249 dialogLoader.focus = true;
250 dialogLoader.active = true;
255 // Display a dialog to ask the user to confirm.
256 if (!dialogLoader.active) {
257 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
258 // than shutdown when clicking on the "Shutdown..." menu item
259 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
260 dialogLoader.sourceComponent = shutdownDialogComponent;
261 dialogLoader.focus = true;
262 dialogLoader.active = true;
269 unitySessionService.endSession();