on xenial help sign in
merge prereq
commit4a9697b58eb48f45db21be95374192bbeb2105c3 authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 24 Jul 2014, 21:25 (12 years ago) parente94063f2c8d695
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
@@ -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}