@@ -19,11 +19,22 @@ import QtQuick 2.0
19import Unity.Application 0.1
19import Unity.Application 0.1
20import Unity.Session 0.1
20import Unity.Session 0.1
21import Ubuntu.Components 1.1
21import Ubuntu.Components 1.1
22−import Ubuntu.Components.Popups 0.1
26+ // to be set from outside, useful mostly for testing purposes
27+ property var unitySessionService: DBusUnitySessionService
28+ property var closeAllApps: function() {
30+ var app = ApplicationManager.get(0);
34+ ApplicationManager.stopApplication(app.appId);
27 function onPowerKeyPressed() {
38 function onPowerKeyPressed() {
28 // FIXME: event.isAutoRepeat is always false on Nexus 4.
39 // FIXME: event.isAutoRepeat is always false on Nexus 4.
29 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
40 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
@@ -41,16 +52,21 @@ Item {
42 QtObject {
53 QtObject {
43 id: d // private stuff
54 id: d // private stuff
55+ objectName: "dialogsPrivate"
45− property bool dialogShown: false
47 function showPowerDialog() {
58 function showPowerDialog() {
48− if (!d.dialogShown) {
59+ if (!dialogLoader.active) {
49− d.dialogShown = true;
60+ dialogLoader.sourceComponent = powerDialogComponent;
50− PopupUtils.open(powerDialog, root, {"z": root.z});
61+ dialogLoader.active = true;
56 id: powerKeyTimer
72 id: powerKeyTimer
@@ -64,91 +80,84 @@ Item {
66 Component {
82 Component {
67− id: logoutDialog
83+ id: logoutDialogComponent
68− Dialog {
84+ ShellDialog {
69− id: dialogueLogout
85+ id: logoutDialog
70 title: i18n.tr("Log out")
86 title: i18n.tr("Log out")
71 text: i18n.tr("Are you sure you want to log out?")
87 text: i18n.tr("Are you sure you want to log out?")
73 text: i18n.tr("No")
89 text: i18n.tr("No")
74 onClicked: {
90 onClicked: {
75− PopupUtils.close(dialogueLogout);
91+ logoutDialog.hide();
76− d.dialogShown = false;
80 text: i18n.tr("Yes")
95 text: i18n.tr("Yes")
81 onClicked: {
96 onClicked: {
82− DBusUnitySessionService.Logout();
97+ unitySessionService.logout();
83− PopupUtils.close(dialogueLogout);
98+ logoutDialog.hide();
84− d.dialogShown = false;
90 Component {
104 Component {
91− id: shutdownDialog
105+ id: shutdownDialogComponent
92− Dialog {
106+ ShellDialog {
93− id: dialogueShutdown
107+ id: shutdownDialog
94 title: i18n.tr("Shut down")
108 title: i18n.tr("Shut down")
95 text: i18n.tr("Are you sure you want to shut down?")
109 text: i18n.tr("Are you sure you want to shut down?")
97 text: i18n.tr("No")
111 text: i18n.tr("No")
98 onClicked: {
112 onClicked: {
99− PopupUtils.close(dialogueShutdown);
113+ shutdownDialog.hide();
100− d.dialogShown = false;
104 text: i18n.tr("Yes")
117 text: i18n.tr("Yes")
105 onClicked: {
118 onClicked: {
106− dBusUnitySessionServiceConnection.closeAllApps();
119+ root.closeAllApps();
107− DBusUnitySessionService.Shutdown();
120+ unitySessionService.shutdown();
108− PopupUtils.close(dialogueShutdown);
121+ shutdownDialog.hide();
109− d.dialogShown = false;
115 Component {
127 Component {
116− id: rebootDialog
128+ id: rebootDialogComponent
117− Dialog {
129+ ShellDialog {
118− id: dialogueReboot
130+ id: rebootDialog
119 title: i18n.tr("Reboot")
131 title: i18n.tr("Reboot")
120 text: i18n.tr("Are you sure you want to reboot?")
132 text: i18n.tr("Are you sure you want to reboot?")
122 text: i18n.tr("No")
134 text: i18n.tr("No")
123 onClicked: {
135 onClicked: {
124− PopupUtils.close(dialogueReboot)
136+ rebootDialog.hide();
125− d.dialogShown = false;
129 text: i18n.tr("Yes")
140 text: i18n.tr("Yes")
130 onClicked: {
141 onClicked: {
131− dBusUnitySessionServiceConnection.closeAllApps();
142+ root.closeAllApps();
132− DBusUnitySessionService.Reboot();
143+ unitySessionService.reboot();
133− PopupUtils.close(dialogueReboot);
144+ rebootDialog.hide();
134− d.dialogShown = false;
140 Component {
150 Component {
141− id: powerDialog
151+ id: powerDialogComponent
142− Dialog {
152+ ShellDialog {
143− id: dialoguePower
153+ id: powerDialog
144 title: i18n.tr("Power")
154 title: i18n.tr("Power")
145 text: i18n.tr("Are you sure you would like\nto power off?")
155 text: i18n.tr("Are you sure you would like\nto power off?")
147 text: i18n.tr("Power off")
157 text: i18n.tr("Power off")
148 onClicked: {
158 onClicked: {
149− dBusUnitySessionServiceConnection.closeAllApps();
159+ root.closeAllApps();
150− PopupUtils.close(dialoguePower);
160+ powerDialog.hide();
151− d.dialogShown = false;
152 root.powerOffClicked();
161 root.powerOffClicked();
154 color: UbuntuColors.red
163 color: UbuntuColors.red
@@ -156,66 +165,51 @@ Item {
157 text: i18n.tr("Restart")
166 text: i18n.tr("Restart")
158 onClicked: {
167 onClicked: {
159− dBusUnitySessionServiceConnection.closeAllApps();
168+ root.closeAllApps();
160− DBusUnitySessionService.Reboot();
169+ unitySessionService.reboot();
161− PopupUtils.close(dialoguePower);
170+ powerDialog.hide();
162− d.dialogShown = false;
164 color: UbuntuColors.green
172 color: UbuntuColors.green
167 text: i18n.tr("Cancel")
175 text: i18n.tr("Cancel")
168 onClicked: {
176 onClicked: {
169− PopupUtils.close(dialoguePower);
177+ powerDialog.hide();
170− d.dialogShown = false;
172 color: UbuntuColors.coolGrey
179 color: UbuntuColors.coolGrey
178 Connections {
184 Connections {
179− id: dBusUnitySessionServiceConnection
185+ target: root.unitySessionService
180− objectName: "dBusUnitySessionServiceConnection"
181− target: DBusUnitySessionService
183− function closeAllApps() {
185− var app = ApplicationManager.get(0);
189− ApplicationManager.stopApplication(app.appId);
193 onLogoutRequested: {
187 onLogoutRequested: {
194 // Display a dialog to ask the user to confirm.
188 // Display a dialog to ask the user to confirm.
195− if (!d.dialogShown) {
189+ if (!dialogLoader.active) {
196− d.dialogShown = true;
190+ dialogLoader.sourceComponent = logoutDialogComponent;
197− PopupUtils.open(logoutDialog, root, {"z": root.z});
191+ dialogLoader.active = true;
201 onShutdownRequested: {
195 onShutdownRequested: {
202 // Display a dialog to ask the user to confirm.
196 // Display a dialog to ask the user to confirm.
203− if (!d.dialogShown) {
197+ if (!dialogLoader.active) {
204− d.dialogShown = true;
198+ dialogLoader.sourceComponent = shutdownDialogComponent;
205− PopupUtils.open(shutdownDialog, root, {"z": root.z});
199+ dialogLoader.active = true;
209 onRebootRequested: {
203 onRebootRequested: {
210 // Display a dialog to ask the user to confirm.
204 // Display a dialog to ask the user to confirm.
211− if (!d.dialogShown) {
205+ if (!dialogLoader.active) {
212− d.dialogShown = true;
206+ dialogLoader.sourceComponent = rebootDialogComponent;
213− PopupUtils.open(rebootDialog, root, {"z": root.z});
207+ dialogLoader.active = true;
217 onLogoutReady: {
211 onLogoutReady: {
218− closeAllApps();
212+ root.closeAllApps();
219 Qt.quit();
213 Qt.quit();