on ed593dc help sign in
unity8/qml/Components/Dialogs.qml
299 lines 9.6 kB history raw
1/*
2 * Copyright (C) 2014-2015 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 */
17import QtQuick 2.4
19import Unity.Application 0.1
20import Unity.Session 0.1
21import GlobalShortcut 1.0
22import Ubuntu.Components 1.3
23import Unity.Platform 1.0
24import Utils 0.1
25import "../Greeter"
27Item {
28 id: root
30 // to be set from outside, useful mostly for testing purposes
31 property var unitySessionService: DBusUnitySessionService
32 property var closeAllApps: function() {
33 while (true) {
34 var app = ApplicationManager.get(0);
35 if (app === null) {
36 break;
37 }
38 ApplicationManager.stopApplication(app.appId);
39 }
40 }
41 property string usageScenario
43 signal powerOffClicked();
45 function showPowerDialog() {
46 d.showPowerDialog();
47 }
49 onUsageScenarioChanged: {
50 if (usageScenario != "desktop" && legacyAppsModel.count > 0 && !d.modeSwitchWarningPopup) {
51 var comp = Qt.createComponent(Qt.resolvedUrl("ModeSwitchWarningDialog.qml"))
52 d.modeSwitchWarningPopup = comp.createObject(root, {model: legacyAppsModel});
53 d.modeSwitchWarningPopup.forceClose.connect(function() {
54 while (legacyAppsModel.count > 0) {
55 ApplicationManager.stopApplication(legacyAppsModel.get(0).appId);
56 }
57 d.modeSwitchWarningPopup.hide();
58 d.modeSwitchWarningPopup.destroy();
59 d.modeSwitchWarningPopup = null;
60 })
61 } else if (usageScenario == "desktop" && d.modeSwitchWarningPopup) {
62 d.modeSwitchWarningPopup.hide();
63 d.modeSwitchWarningPopup.destroy();
64 d.modeSwitchWarningPopup = null;
65 }
66 }
68 ApplicationsFilterModel {
69 id: legacyAppsModel
70 applicationsModel: ApplicationManager
71 filterTouchApps: true
72 }
74 GlobalShortcut { // reboot/shutdown dialog
75 shortcut: Qt.Key_PowerDown
76 active: Platform.isPC
77 onTriggered: root.unitySessionService.RequestShutdown()
78 }
80 GlobalShortcut { // reboot/shutdown dialog
81 shortcut: Qt.Key_PowerOff
82 active: Platform.isPC
83 onTriggered: root.unitySessionService.RequestShutdown()
84 }
86 GlobalShortcut { // sleep
87 shortcut: Qt.Key_Sleep
88 onTriggered: root.unitySessionService.Suspend()
89 }
91 GlobalShortcut { // hibernate
92 shortcut: Qt.Key_Hibernate
93 onTriggered: root.unitySessionService.Hibernate()
94 }
96 GlobalShortcut { // logout/lock dialog
97 shortcut: Qt.Key_LogOff
98 onTriggered: root.unitySessionService.RequestLogout()
99 }
101 GlobalShortcut { // logout/lock dialog
102 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
103 onTriggered: root.unitySessionService.RequestLogout()
104 }
106 GlobalShortcut { // lock screen
107 shortcut: Qt.Key_ScreenSaver
108 onTriggered: LightDMService.greeter.showGreeter()
109 }
111 GlobalShortcut { // lock screen
112 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
113 onTriggered: LightDMService.greeter.showGreeter()
114 }
116 QtObject {
117 id: d // private stuff
118 objectName: "dialogsPrivate"
120 property var modeSwitchWarningPopup: null
122 function showPowerDialog() {
123 if (!dialogLoader.active) {
124 dialogLoader.sourceComponent = powerDialogComponent;
125 dialogLoader.focus = true;
126 dialogLoader.active = true;
127 }
128 }
129 }
131 Loader {
132 id: dialogLoader
133 objectName: "dialogLoader"
134 anchors.fill: parent
135 active: false
136 }
138 Component {
139 id: logoutDialogComponent
140 ShellDialog {
141 id: logoutDialog
142 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
143 text: i18n.tr("Are you sure you want to log out?")
144 Button {
145 text: i18n.ctr("Button: Lock the system", "Lock")
146 onClicked: {
147 LightDMService.greeter.showGreeter()
148 logoutDialog.hide();
149 }
150 }
151 Button {
152 text: i18n.ctr("Button: Log out from the system", "Log Out")
153 onClicked: {
154 unitySessionService.logout();
155 logoutDialog.hide();
156 }
157 }
158 Button {
159 text: i18n.tr("Cancel")
160 onClicked: {
161 logoutDialog.hide();
162 }
163 }
164 }
165 }
167 Component {
168 id: shutdownDialogComponent
169 ShellDialog {
170 id: shutdownDialog
171 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
172 text: i18n.tr("Are you sure you want to shut down?")
173 Button {
174 text: i18n.ctr("Button: Reboot the system", "Reboot")
175 onClicked: {
176 root.closeAllApps();
177 unitySessionService.reboot();
178 shutdownDialog.hide();
179 }
180 color: UbuntuColors.lightGrey
181 }
182 Button {
183 text: i18n.ctr("Button: Shut down the system", "Shut down")
184 onClicked: {
185 root.closeAllApps();
186 unitySessionService.shutdown();
187 shutdownDialog.hide();
188 }
189 color: UbuntuColors.red
190 }
191 Button {
192 text: i18n.tr("Cancel")
193 onClicked: {
194 shutdownDialog.hide();
195 }
196 color: UbuntuColors.lightGrey
197 }
198 }
199 }
201 Component {
202 id: rebootDialogComponent
203 ShellDialog {
204 id: rebootDialog
205 title: i18n.ctr("Title: Reboot dialog", "Reboot")
206 text: i18n.tr("Are you sure you want to reboot?")
207 Button {
208 text: i18n.tr("No")
209 onClicked: {
210 rebootDialog.hide();
211 }
212 color: UbuntuColors.lightGrey
213 }
214 Button {
215 text: i18n.tr("Yes")
216 onClicked: {
217 root.closeAllApps();
218 unitySessionService.reboot();
219 rebootDialog.hide();
220 }
221 color: UbuntuColors.red
222 }
223 }
224 }
226 Component {
227 id: powerDialogComponent
228 ShellDialog {
229 id: powerDialog
230 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
231 text: i18n.tr("Are you sure you would like\nto power off?")
232 Button {
233 text: i18n.ctr("Button: Power off the system", "Power off")
234 onClicked: {
235 root.closeAllApps();
236 powerDialog.hide();
237 root.powerOffClicked();
238 }
239 color: UbuntuColors.red
240 }
241 Button {
242 text: i18n.ctr("Button: Restart the system", "Restart")
243 onClicked: {
244 root.closeAllApps();
245 unitySessionService.reboot();
246 powerDialog.hide();
247 }
248 color: UbuntuColors.lightGrey
249 }
250 Button {
251 text: i18n.tr("Cancel")
252 onClicked: {
253 powerDialog.hide();
254 }
255 color: UbuntuColors.lightGrey
256 }
257 }
258 }
260 Connections {
261 target: root.unitySessionService
263 onLogoutRequested: {
264 // Display a dialog to ask the user to confirm.
265 if (!dialogLoader.active) {
266 dialogLoader.sourceComponent = logoutDialogComponent;
267 dialogLoader.focus = true;
268 dialogLoader.active = true;
269 }
270 }
272 onShutdownRequested: {
273 // Display a dialog to ask the user to confirm.
274 if (!dialogLoader.active) {
275 dialogLoader.sourceComponent = shutdownDialogComponent;
276 dialogLoader.focus = true;
277 dialogLoader.active = true;
278 }
279 }
281 onRebootRequested: {
282 // Display a dialog to ask the user to confirm.
283 if (!dialogLoader.active) {
284 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
285 // than shutdown when clicking on the "Shutdown..." menu item
286 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
287 dialogLoader.sourceComponent = shutdownDialogComponent;
288 dialogLoader.focus = true;
289 dialogLoader.active = true;
290 }
291 }
293 onLogoutReady: {
294 root.closeAllApps();
295 Qt.quit();
296 unitySessionService.endSession();
297 }
298 }