~aacid/unity8/scopesListFinger

« back to all changes in this revision

Viewing changes to qml/Components/Dialogs.qml

  • Committer: CI Train Bot
  • Author(s): Daniel d'Andrada
  • Date: 2014-12-15 22:41:44 UTC
  • mfrom: (1481.3.2 properInSceneDialogs)
  • Revision ID: ci-train-bot@canonical.com-20141215224144-d6qm73qat4p8rqes
Refactor Dialogs.qml to use proper in-scene dialogs

Proper in-scene dialogs keep its Loader as parent and
therefore carry on all its transformations, following its
rotation, etc.

It needs Dialog from ubuntu-ui-toolkit to comply with the
reparentToRootItem property. 
Approved by: Michał Sawicz, Ying-Chun Liu

Show diffs side-by-side

added added

removed removed

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