@@ -33,15 +33,6 @@ MouseArea {
3333
3434 // to be set from outside, useful mostly for testing purposes
3535 property var unitySessionService: DBusUnitySessionService
36− property var closeAllApps: function() {
37− while (true) {
38− var app = ApplicationManager.get(0);
39− if (app === null) {
40− break;
41− }
42− ApplicationManager.stopApplication(app.appId);
43− }
44− }
4536 property string usageScenario
4637 property size screenSize: Qt.size(Screen.width, Screen.height)
4738 property bool hasKeyboard: false
@@ -52,6 +43,15 @@ MouseArea {
5243 d.showPowerDialog();
5344 }
5445
46+ property var doOnClosedAllWindows: function() {}
47+ Connections {
48+ target: topLevelSurfaceList
49+
50+ onClosedAllWindows: {
51+ doOnClosedAllWindows();
52+ }
53+ }
54+
5555 onUsageScenarioChanged: {
5656 // if we let the user switch manually to desktop mode, don't display the warning dialog
5757 // see MenuItemFactory.qml, for the Desktop Mode switch logic
@@ -222,9 +222,11 @@ MouseArea {
222222 focus: true
223223 text: i18n.tr("Yes")
224224 onClicked: {
225− root.closeAllApps();
226− unitySessionService.reboot();
227− rebootDialog.hide();
225+ topLevelSurfaceList.closeAllWindows();
226+ doOnClosedAllWindows = function() {
227+ unitySessionService.reboot();
228+ rebootDialog.hide();
229+ }
228230 }
229231 color: theme.palette.normal.negative
230232 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -243,9 +245,11 @@ MouseArea {
243245 focus: true
244246 text: i18n.ctr("Button: Power off the system", "Power off")
245247 onClicked: {
246− root.closeAllApps();
247− powerDialog.hide();
248− root.powerOffClicked();
248+ topLevelSurfaceList.closeAllWindows();
249+ doOnClosedAllWindows = function() {
250+ powerDialog.hide();
251+ root.powerOffClicked();
252+ }
249253 }
250254 color: theme.palette.normal.negative
251255 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
@@ -254,9 +258,11 @@ MouseArea {
254258 width: parent.width
255259 text: i18n.ctr("Button: Restart the system", "Restart")
256260 onClicked: {
257− root.closeAllApps();
258− unitySessionService.reboot();
259− powerDialog.hide();
261+ topLevelSurfaceList.closeAllWindows();
262+ doOnClosedAllWindows = function() {
263+ unitySessionService.reboot();
264+ powerDialog.hide();
265+ }
260266 }
261267 }
262268 Button {
@@ -296,9 +302,11 @@ MouseArea {
296302 }
297303
298304 onLogoutReady: {
299− root.closeAllApps();
300− Qt.quit();
301− unitySessionService.endSession();
305+ topLevelSurfaceList.closeAllWindows();
306+ doOnClosedAllWindows = function() {
307+ Qt.quit();
308+ unitySessionService.endSession();
309+ }
302310 }
303311 }
304312}