on xenial help sign in
merge prereq
commit2c8d695dd3a02525b2474e8564a4e9e4f4ed939f authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 24 Jul 2014, 21:23 (12 years ago) parent9f383e6e9c1fc9
2 files changed+232−181
qml/Components/Dialogs.qml+216 qml/Shell.qml+16−181
qml/Components/Dialogs.qmlnew file+216
@@ -0,0 +1,216 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.0
18+
19+import Unity.Application 0.1
20+import Ubuntu.Components 0.1
21+import Ubuntu.Components.Popups 0.1
22+
23+Item {
24+ id: root
25+
26+ function onPowerKeyPressed() {
27+ if (!powerKeyTimer.running) {
28+ powerKeyTimer.start();
29+ }
30+ }
31+
32+ function onPowerKeyReleased() {
33+ powerKeyTimer.stop();
34+ }
35+
36+ signal powerOffClicked();
37+
38+ QtObject {
39+ id: d // private stuff
40+
41+ property bool dialogShown: false
42+
43+ function showPowerDialog() {
44+ if (!d.dialogShown) {
45+ d.dialogShown = true;
46+ PopupUtils.open(powerDialog, root, {"z": root.z});
47+ }
48+ }
49+ }
50+
51+ Timer {
52+ id: powerKeyTimer
53+ interval: 2000
54+ repeat: false
55+ triggeredOnStart: false
56+
57+ onTriggered: {
58+ d.showPowerDialog();
59+ }
60+ }
61+
62+ Component {
63+ id: logoutDialog
64+ Dialog {
65+ id: dialogueLogout
66+ title: "Logout"
67+ text: "Are you sure that you want to logout?"
68+ Button {
69+ text: "Cancel"
70+ onClicked: {
71+ PopupUtils.close(dialogueLogout);
72+ d.dialogShown = false;
73+ }
74+ }
75+ Button {
76+ text: "Yes"
77+ onClicked: {
78+ DBusUnitySessionService.Logout();
79+ PopupUtils.close(dialogueLogout);
80+ d.dialogShown = false;
81+ }
82+ }
83+ }
84+ }
85+
86+ Component {
87+ id: shutdownDialog
88+ Dialog {
89+ id: dialogueShutdown
90+ title: "Shutdown"
91+ text: "Are you sure that you want to shutdown?"
92+ Button {
93+ text: "Cancel"
94+ onClicked: {
95+ PopupUtils.close(dialogueShutdown);
96+ d.dialogShown = false;
97+ }
98+ }
99+ Button {
100+ text: "Yes"
101+ onClicked: {
102+ dBusUnitySessionServiceConnection.closeAllApps();
103+ DBusUnitySessionService.Shutdown();
104+ PopupUtils.close(dialogueShutdown);
105+ d.dialogShown = false;
106+ }
107+ }
108+ }
109+ }
110+
111+ Component {
112+ id: rebootDialog
113+ Dialog {
114+ id: dialogueReboot
115+ title: "Reboot"
116+ text: "Are you sure that you want to reboot?"
117+ Button {
118+ text: "Cancel"
119+ onClicked: {
120+ PopupUtils.close(dialogueReboot)
121+ d.dialogShown = false;
122+ }
123+ }
124+ Button {
125+ text: "Yes"
126+ onClicked: {
127+ dBusUnitySessionServiceConnection.closeAllApps();
128+ DBusUnitySessionService.Reboot();
129+ PopupUtils.close(dialogueReboot);
130+ d.dialogShown = false;
131+ }
132+ }
133+ }
134+ }
135+
136+ Component {
137+ id: powerDialog
138+ Dialog {
139+ id: dialoguePower
140+ title: "Power"
141+ text: i18n.tr("Are you sure you would like to turn power off?")
142+ Button {
143+ text: i18n.tr("Power off")
144+ onClicked: {
145+ dBusUnitySessionServiceConnection.closeAllApps();
146+ PopupUtils.close(dialoguePower);
147+ d.dialogShown = false;
148+ root.powerOffClicked();
149+ }
150+ }
151+ Button {
152+ text: i18n.tr("Restart")
153+ onClicked: {
154+ dBusUnitySessionServiceConnection.closeAllApps();
155+ DBusUnitySessionService.Reboot();
156+ PopupUtils.close(dialoguePower);
157+ d.dialogShown = false;
158+ }
159+ }
160+ Button {
161+ text: i18n.tr("Cancel")
162+ onClicked: {
163+ PopupUtils.close(dialoguePower);
164+ d.dialogShown = false;
165+ }
166+ }
167+ }
168+ }
169+
170+
171+ Connections {
172+ id: dBusUnitySessionServiceConnection
173+ objectName: "dBusUnitySessionServiceConnection"
174+ target: DBusUnitySessionService
175+
176+ function closeAllApps() {
177+ while (true) {
178+ var app = ApplicationManager.get(0);
179+ if (app === null) {
180+ break;
181+ }
182+ ApplicationManager.stopApplication(app.appId);
183+ }
184+ }
185+
186+ onLogoutRequested: {
187+ // Display a dialog to ask the user to confirm.
188+ if (!d.dialogShown) {
189+ d.dialogShown = true;
190+ PopupUtils.open(logoutDialog, root, {"z": root.z});
191+ }
192+ }
193+
194+ onShutdownRequested: {
195+ // Display a dialog to ask the user to confirm.
196+ if (!d.dialogShown) {
197+ d.dialogShown = true;
198+ PopupUtils.open(shutdownDialog, root, {"z": root.z});
199+ }
200+ }
201+
202+ onRebootRequested: {
203+ // Display a dialog to ask the user to confirm.
204+ if (!d.dialogShown) {
205+ d.dialogShown = true;
206+ PopupUtils.open(rebootDialog, root, {"z": root.z});
207+ }
208+ }
209+
210+ onLogoutReady: {
211+ closeAllApps();
212+ Qt.quit();
213+ }
214+ }
215+
216+}
qml/Shell.qml+16−181
@@ -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
@@ -94,9 +93,7 @@ Item {
9493
9594 Keys.onPressed: {
9695 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
97− if (!powerKeyTimer.running) {
98− powerKeyTimer.start();
99− }
96+ dialogs.onPowerKeyPressed();
10097 event.accepted = true;
10198 } else {
10299 event.accepted = false;
@@ -105,7 +102,7 @@ Item {
105102
106103 Keys.onReleased: {
107104 if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
108− powerKeyTimer.stop();
105+ dialogs.onPowerKeyReleased();
109106 event.accepted = true;
110107 } else {
111108 event.accepted = false;
@@ -271,170 +268,6 @@ Item {
271268 }
272269 }
273270
274− property bool dialogShown: false
275−
276− Component {
277− id: logoutDialog
278− Dialog {
279− id: dialogueLogout
280− title: "Logout"
281− text: "Are you sure that you want to logout?"
282− Button {
283− text: "Cancel"
284− onClicked: {
285− PopupUtils.close(dialogueLogout);
286− stages.dialogShown = false;
287− }
288− }
289− Button {
290− text: "Yes"
291− onClicked: {
292− DBusUnitySessionService.Logout();
293− PopupUtils.close(dialogueLogout);
294− stages.dialogShown = false;
295− }
296− }
297− }
298− }
299−
300− Component {
301− id: shutdownDialog
302− Dialog {
303− id: dialogueShutdown
304− title: "Shutdown"
305− text: "Are you sure that you want to shutdown?"
306− Button {
307− text: "Cancel"
308− onClicked: {
309− PopupUtils.close(dialogueShutdown);
310− stages.dialogShown = false;
311− }
312− }
313− Button {
314− text: "Yes"
315− onClicked: {
316− dBusUnitySessionServiceConnection.closeAllApps();
317− DBusUnitySessionService.Shutdown();
318− PopupUtils.close(dialogueShutdown);
319− stages.dialogShown = false;
320− }
321− }
322− }
323− }
324−
325− Component {
326− id: rebootDialog
327− Dialog {
328− id: dialogueReboot
329− title: "Reboot"
330− text: "Are you sure that you want to reboot?"
331− Button {
332− text: "Cancel"
333− onClicked: {
334− PopupUtils.close(dialogueReboot)
335− stages.dialogShown = false;
336− }
337− }
338− Button {
339− text: "Yes"
340− onClicked: {
341− dBusUnitySessionServiceConnection.closeAllApps();
342− DBusUnitySessionService.Reboot();
343− PopupUtils.close(dialogueReboot);
344− stages.dialogShown = false;
345− }
346− }
347− }
348− }
349−
350− Component {
351− id: powerDialog
352− Dialog {
353− id: dialoguePower
354− title: "Power"
355− text: i18n.tr("Are you sure you would like to turn power off?")
356− Button {
357− text: i18n.tr("Power off")
358− onClicked: {
359− dBusUnitySessionServiceConnection.closeAllApps();
360− PopupUtils.close(dialoguePower);
361− stages.dialogShown = false;
362− shutdownFadeOutRectangle.enabled = true;
363− shutdownFadeOutRectangle.visible = true;
364− shutdownFadeOut.start();
365− }
366− }
367− Button {
368− text: i18n.tr("Restart")
369− onClicked: {
370− dBusUnitySessionServiceConnection.closeAllApps();
371− DBusUnitySessionService.Reboot();
372− PopupUtils.close(dialoguePower);
373− stages.dialogShown = false;
374− }
375− }
376− Button {
377− text: i18n.tr("Cancel")
378− onClicked: {
379− PopupUtils.close(dialoguePower);
380− stages.dialogShown = false;
381− }
382− }
383− }
384− }
385−
386− function showPowerDialog() {
387− if (!stages.dialogShown) {
388− stages.dialogShown = true;
389− PopupUtils.open(powerDialog);
390− }
391− }
392−
393− Connections {
394− id: dBusUnitySessionServiceConnection
395− objectName: "dBusUnitySessionServiceConnection"
396− target: DBusUnitySessionService
397−
398− function closeAllApps() {
399− while (true) {
400− var app = ApplicationManager.get(0);
401− if (app === null) {
402− break;
403− }
404− ApplicationManager.stopApplication(app.appId);
405− }
406− }
407−
408− onLogoutRequested: {
409− // Display a dialog to ask the user to confirm.
410− if (!stages.dialogShown) {
411− stages.dialogShown = true;
412− PopupUtils.open(logoutDialog);
413− }
414− }
415−
416− onShutdownRequested: {
417− // Display a dialog to ask the user to confirm.
418− if (!stages.dialogShown) {
419− stages.dialogShown = true;
420− PopupUtils.open(shutdownDialog);
421− }
422− }
423−
424− onRebootRequested: {
425− // Display a dialog to ask the user to confirm.
426− if (!stages.dialogShown) {
427− stages.dialogShown = true;
428− PopupUtils.open(rebootDialog);
429− }
430− }
431−
432− onLogoutReady: {
433− closeAllApps();
434− Qt.quit();
435− }
436− }
437−
438271 Loader {
439272 id: applicationsDisplayLoader
440273 anchors.fill: parent
@@ -812,11 +645,22 @@ Item {
812645 value: "unity8"
813646 }
814647
648+ Dialogs {
649+ id: dialogs
650+ anchors.fill: parent
651+ z: overlay.z + 10
652+ onPowerOffClicked: {
653+ shutdownFadeOutRectangle.enabled = true;
654+ shutdownFadeOutRectangle.visible = true;
655+ shutdownFadeOut.start();
656+ }
657+ }
658+
815659 Label {
816660 id: alphaDisclaimerLabel
817661 anchors.centerIn: parent
818662 visible: ApplicationManager.fake ? ApplicationManager.fake : false
819− z: overlay.z + 10
663+ z: dialogs.z + 10
820664 text: "EARLY ALPHA\nNOT READY FOR USE"
821665 color: "lightgrey"
822666 opacity: 0.2
@@ -843,19 +687,9 @@ Item {
843687 onShowHome: showHome()
844688 }
845689
846− Timer {
847− id: powerKeyTimer
848− interval: 2000
849− repeat: false
850− triggeredOnStart: false
851−
852− onTriggered: {
853− stages.showPowerDialog();
854− }
855− }
856−
857690 Rectangle {
858691 id: shutdownFadeOutRectangle
692+ z: edgeDemo.z + 10
859693 enabled: false
860694 visible: false
861695 color: "black"
@@ -872,4 +706,5 @@ Item {
872706 }
873707 }
874708 }
709+
875710}