@@ -19,7 +19,6 @@ import AccountsService 0.1
1919import GSettings 1.0
2020import Unity.Application 0.1
2121import Ubuntu.Components 0.1
22−import Ubuntu.Components.Popups 0.1
2322import Ubuntu.Gestures 0.1
2423import Unity.Launcher 0.1
2524import Utils 0.1
@@ -95,9 +94,7 @@ Item {
9594
9695 Keys.onPressed: {
9796 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
98− if (!powerKeyTimer.running) {
99− powerKeyTimer.start();
100− }
97+ dialogs.onPowerKeyPressed();
10198 event.accepted = true;
10299 } else {
103100 event.accepted = false;
@@ -106,7 +103,7 @@ Item {
106103
107104 Keys.onReleased: {
108105 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
109− powerKeyTimer.stop();
106+ dialogs.onPowerKeyReleased();
110107 event.accepted = true;
111108 } else {
112109 event.accepted = false;
@@ -162,170 +159,6 @@ Item {
162159 }
163160 }
164161
165− property bool dialogShown: false
166−
167− Component {
168− id: logoutDialog
169− Dialog {
170− id: dialogueLogout
171− title: "Logout"
172− text: "Are you sure that you want to logout?"
173− Button {
174− text: "Cancel"
175− onClicked: {
176− PopupUtils.close(dialogueLogout);
177− stages.dialogShown = false;
178− }
179− }
180− Button {
181− text: "Yes"
182− onClicked: {
183− DBusUnitySessionService.Logout();
184− PopupUtils.close(dialogueLogout);
185− stages.dialogShown = false;
186− }
187− }
188− }
189− }
190−
191− Component {
192− id: shutdownDialog
193− Dialog {
194− id: dialogueShutdown
195− title: "Shutdown"
196− text: "Are you sure that you want to shutdown?"
197− Button {
198− text: "Cancel"
199− onClicked: {
200− PopupUtils.close(dialogueShutdown);
201− stages.dialogShown = false;
202− }
203− }
204− Button {
205− text: "Yes"
206− onClicked: {
207− dBusUnitySessionServiceConnection.closeAllApps();
208− DBusUnitySessionService.Shutdown();
209− PopupUtils.close(dialogueShutdown);
210− stages.dialogShown = false;
211− }
212− }
213− }
214− }
215−
216− Component {
217− id: rebootDialog
218− Dialog {
219− id: dialogueReboot
220− title: "Reboot"
221− text: "Are you sure that you want to reboot?"
222− Button {
223− text: "Cancel"
224− onClicked: {
225− PopupUtils.close(dialogueReboot)
226− stages.dialogShown = false;
227− }
228− }
229− Button {
230− text: "Yes"
231− onClicked: {
232− dBusUnitySessionServiceConnection.closeAllApps();
233− DBusUnitySessionService.Reboot();
234− PopupUtils.close(dialogueReboot);
235− stages.dialogShown = false;
236− }
237− }
238− }
239− }
240−
241− Component {
242− id: powerDialog
243− Dialog {
244− id: dialoguePower
245− title: "Power"
246− text: i18n.tr("Are you sure you would like to turn power off?")
247− Button {
248− text: i18n.tr("Power off")
249− onClicked: {
250− dBusUnitySessionServiceConnection.closeAllApps();
251− PopupUtils.close(dialoguePower);
252− stages.dialogShown = false;
253− shutdownFadeOutRectangle.enabled = true;
254− shutdownFadeOutRectangle.visible = true;
255− shutdownFadeOut.start();
256− }
257− }
258− Button {
259− text: i18n.tr("Restart")
260− onClicked: {
261− dBusUnitySessionServiceConnection.closeAllApps();
262− DBusUnitySessionService.Reboot();
263− PopupUtils.close(dialoguePower);
264− stages.dialogShown = false;
265− }
266− }
267− Button {
268− text: i18n.tr("Cancel")
269− onClicked: {
270− PopupUtils.close(dialoguePower);
271− stages.dialogShown = false;
272− }
273− }
274− }
275− }
276−
277− function showPowerDialog() {
278− if (!stages.dialogShown) {
279− stages.dialogShown = true;
280− PopupUtils.open(powerDialog);
281− }
282− }
283−
284− Connections {
285− id: dBusUnitySessionServiceConnection
286− objectName: "dBusUnitySessionServiceConnection"
287− target: DBusUnitySessionService
288−
289− function closeAllApps() {
290− while (true) {
291− var app = ApplicationManager.get(0);
292− if (app === null) {
293− break;
294− }
295− ApplicationManager.stopApplication(app.appId);
296− }
297− }
298−
299− onLogoutRequested: {
300− // Display a dialog to ask the user to confirm.
301− if (!stages.dialogShown) {
302− stages.dialogShown = true;
303− PopupUtils.open(logoutDialog);
304− }
305− }
306−
307− onShutdownRequested: {
308− // Display a dialog to ask the user to confirm.
309− if (!stages.dialogShown) {
310− stages.dialogShown = true;
311− PopupUtils.open(shutdownDialog);
312− }
313− }
314−
315− onRebootRequested: {
316− // Display a dialog to ask the user to confirm.
317− if (!stages.dialogShown) {
318− stages.dialogShown = true;
319− PopupUtils.open(rebootDialog);
320− }
321− }
322−
323− onLogoutReady: {
324− closeAllApps();
325− Qt.quit();
326− }
327− }
328−
329162 Loader {
330163 id: applicationsDisplayLoader
331164 anchors.fill: parent
@@ -702,11 +535,22 @@ Item {
702535 value: "unity8"
703536 }
704537
538+ Dialogs {
539+ id: dialogs
540+ anchors.fill: parent
541+ z: overlay.z + 10
542+ onPowerOffClicked: {
543+ shutdownFadeOutRectangle.enabled = true;
544+ shutdownFadeOutRectangle.visible = true;
545+ shutdownFadeOut.start();
546+ }
547+ }
548+
705549 Label {
706550 id: alphaDisclaimerLabel
707551 anchors.centerIn: parent
708552 visible: ApplicationManager.fake ? ApplicationManager.fake : false
709− z: overlay.z + 10
553+ z: dialogs.z + 10
710554 text: "EARLY ALPHA\nNOT READY FOR USE"
711555 color: "lightgrey"
712556 opacity: 0.2
@@ -732,19 +576,9 @@ Item {
732576 onShowHome: showHome()
733577 }
734578
735− Timer {
736− id: powerKeyTimer
737− interval: 2000
738− repeat: false
739− triggeredOnStart: false
740−
741− onTriggered: {
742− stages.showPowerDialog();
743− }
744− }
745−
746579 Rectangle {
747580 id: shutdownFadeOutRectangle
581+ z: edgeDemo.z + 10
748582 enabled: false
749583 visible: false
750584 color: "black"
@@ -761,4 +595,5 @@ Item {
761595 }
762596 }
763597 }
598+
764599}