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 // Explicitly use the right domain for this widget because it might be used
28 // in other applications like the welcome wizard.
29 readonly property string domain: "unity8"
31 function onPowerKeyPressed() {
32 // FIXME: event.isAutoRepeat is always false on Nexus 4.
33 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
34 // https://launchpad.net/bugs/1349416
35 if (!powerKeyTimer.running) {
36 powerKeyTimer.restart();
40 function onPowerKeyReleased() {
44 signal powerOffClicked();
47 id: d // private stuff
49 property bool dialogShown: false
51 function showPowerDialog() {
54 PopupUtils.open(powerDialog, root, {"z": root.z});
63 triggeredOnStart: false
74 title: i18n.dtr(root.domain, "Log out")
75 text: i18n.dtr(root.domain, "Are you sure you want to log out?")
77 text: i18n.dtr(root.domain, "No")
79 PopupUtils.close(dialogueLogout);
80 d.dialogShown = false;
84 text: i18n.dtr(root.domain, "Yes")
86 DBusUnitySessionService.Logout();
87 PopupUtils.close(dialogueLogout);
88 d.dialogShown = false;
98 title: i18n.dtr(root.domain, "Shut down")
99 text: i18n.dtr(root.domain, "Are you sure you want to shut down?")
101 text: i18n.dtr(root.domain, "No")
103 PopupUtils.close(dialogueShutdown);
104 d.dialogShown = false;
108 text: i18n.dtr(root.domain, "Yes")
110 dBusUnitySessionServiceConnection.closeAllApps();
111 DBusUnitySessionService.Shutdown();
112 PopupUtils.close(dialogueShutdown);
113 d.dialogShown = false;
123 title: i18n.dtr(root.domain, "Reboot")
124 text: i18n.dtr(root.domain, "Are you sure you want to reboot?")
126 text: i18n.dtr(root.domain, "No")
128 PopupUtils.close(dialogueReboot)
129 d.dialogShown = false;
133 text: i18n.dtr(root.domain, "Yes")
135 dBusUnitySessionServiceConnection.closeAllApps();
136 DBusUnitySessionService.Reboot();
137 PopupUtils.close(dialogueReboot);
138 d.dialogShown = false;
148 title: i18n.dtr(root.domain, "Power")
149 text: i18n.dtr(root.domain, "Are you sure you would like\nto power off?")
151 text: i18n.dtr(root.domain, "Power off")
153 dBusUnitySessionServiceConnection.closeAllApps();
154 PopupUtils.close(dialoguePower);
155 d.dialogShown = false;
156 root.powerOffClicked();
158 color: UbuntuColors.red
161 text: i18n.dtr(root.domain, "Restart")
163 dBusUnitySessionServiceConnection.closeAllApps();
164 DBusUnitySessionService.Reboot();
165 PopupUtils.close(dialoguePower);
166 d.dialogShown = false;
168 color: UbuntuColors.green
171 text: i18n.dtr(root.domain, "Cancel")
173 PopupUtils.close(dialoguePower);
174 d.dialogShown = false;
176 color: UbuntuColors.coolGrey
183 id: dBusUnitySessionServiceConnection
184 objectName: "dBusUnitySessionServiceConnection"
185 target: DBusUnitySessionService
187 function closeAllApps() {
189 var app = ApplicationManager.get(0);
193 ApplicationManager.stopApplication(app.appId);
198 // Display a dialog to ask the user to confirm.
199 if (!d.dialogShown) {
200 d.dialogShown = true;
201 PopupUtils.open(logoutDialog, root, {"z": root.z});
205 onShutdownRequested: {
206 // Display a dialog to ask the user to confirm.
207 if (!d.dialogShown) {
208 d.dialogShown = true;
209 PopupUtils.open(shutdownDialog, root, {"z": root.z});
214 // Display a dialog to ask the user to confirm.
215 if (!d.dialogShown) {
216 d.dialogShown = true;
217 PopupUtils.open(rebootDialog, root, {"z": root.z});