~mzanetti/unity8/fix-left-edge-on-spread

« back to all changes in this revision

Viewing changes to qml/Components/Dialogs.qml

  • Committer: Michael Zanetti
  • Date: 2015-01-12 11:21:17 UTC
  • mfrom: (1459.1.85 unity8)
  • Revision ID: michael.zanetti@canonical.com-20150112112117-0x9srs9dx0ndp60g
merge trunk

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