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 Ubuntu.Components.Popups 0.1
27 function onPowerKeyPressed() {
28 // FIXME: event.isAutoRepeat is always false on Nexus 4.
29 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
30 // https://launchpad.net/bugs/1349416
31 if (!powerKeyTimer.running) {
32 powerKeyTimer.restart();
36 function onPowerKeyReleased() {
40 signal powerOffClicked();
43 id: d // private stuff
45 property bool dialogShown: false
47 function showPowerDialog() {
50 PopupUtils.open(powerDialog, root, {"z": root.z});
59 triggeredOnStart: false
70 title: i18n.tr("Log out")
71 text: i18n.tr("Are you sure you want to log out?")
75 PopupUtils.close(dialogueLogout);
76 d.dialogShown = false;
82 DBusUnitySessionService.Logout();
83 PopupUtils.close(dialogueLogout);
84 d.dialogShown = false;
94 title: i18n.tr("Shut down")
95 text: i18n.tr("Are you sure you want to shut down?")
99 PopupUtils.close(dialogueShutdown);
100 d.dialogShown = false;
106 dBusUnitySessionServiceConnection.closeAllApps();
107 DBusUnitySessionService.Shutdown();
108 PopupUtils.close(dialogueShutdown);
109 d.dialogShown = false;
119 title: i18n.tr("Reboot")
120 text: i18n.tr("Are you sure you want to reboot?")
124 PopupUtils.close(dialogueReboot)
125 d.dialogShown = false;
131 dBusUnitySessionServiceConnection.closeAllApps();
132 DBusUnitySessionService.Reboot();
133 PopupUtils.close(dialogueReboot);
134 d.dialogShown = false;
144 title: i18n.tr("Power")
145 text: i18n.tr("Are you sure you would like\nto power off?")
147 text: i18n.tr("Power off")
149 dBusUnitySessionServiceConnection.closeAllApps();
150 PopupUtils.close(dialoguePower);
151 d.dialogShown = false;
152 root.powerOffClicked();
154 color: UbuntuColors.red
157 text: i18n.tr("Restart")
159 dBusUnitySessionServiceConnection.closeAllApps();
160 DBusUnitySessionService.Reboot();
161 PopupUtils.close(dialoguePower);
162 d.dialogShown = false;
164 color: UbuntuColors.green
167 text: i18n.tr("Cancel")
169 PopupUtils.close(dialoguePower);
170 d.dialogShown = false;
172 color: UbuntuColors.coolGrey
179 id: dBusUnitySessionServiceConnection
180 objectName: "dBusUnitySessionServiceConnection"
181 target: DBusUnitySessionService
183 function closeAllApps() {
185 var app = ApplicationManager.get(0);
189 ApplicationManager.stopApplication(app.appId);
194 // Display a dialog to ask the user to confirm.
195 if (!d.dialogShown) {
196 d.dialogShown = true;
197 PopupUtils.open(logoutDialog, root, {"z": root.z});
201 onShutdownRequested: {
202 // Display a dialog to ask the user to confirm.
203 if (!d.dialogShown) {
204 d.dialogShown = true;
205 PopupUtils.open(shutdownDialog, root, {"z": root.z});
210 // Display a dialog to ask the user to confirm.
211 if (!d.dialogShown) {
212 d.dialogShown = true;
213 PopupUtils.open(rebootDialog, root, {"z": root.z});