on 4cd8d7c help sign in
unity8/qml/Components/Dialogs.qml
217 lines 6.5 kB history raw
1/*
2 * Copyright (C) 2014 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.0
19import Unity.Application 0.1
20import Unity.Session 0.1
21import Ubuntu.Components 1.1
22import "../Greeter"
24Item {
25 id: root
27 // to be set from outside, useful mostly for testing purposes
28 property var unitySessionService: DBusUnitySessionService
29 property var closeAllApps: function() {
30 while (true) {
31 var app = ApplicationManager.get(0);
32 if (app === null) {
33 break;
34 }
35 ApplicationManager.stopApplication(app.appId);
36 }
37 }
39 signal powerOffClicked();
41 function showPowerDialog() {
42 d.showPowerDialog();
43 }
45 QtObject {
46 id: d // private stuff
47 objectName: "dialogsPrivate"
50 function showPowerDialog() {
51 if (!dialogLoader.active) {
52 dialogLoader.sourceComponent = powerDialogComponent;
53 dialogLoader.active = true;
54 dialogLoader.item.forceActiveFocus();
55 }
56 }
57 }
58 Loader {
59 id: dialogLoader
60 objectName: "dialogLoader"
61 anchors.fill: parent
62 active: false
63 }
65 LightDM{id: lightDM} // Provide backend access
66 Component {
67 id: logoutDialogComponent
68 ShellDialog {
69 id: logoutDialog
70 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
71 text: i18n.tr("Are you sure you want to log out?")
72 Button {
73 text: i18n.ctr("Button: Lock the system", "Lock")
74 onClicked: {
75 lightDM.greeter.showGreeter()
76 logoutDialog.hide();
77 }
78 }
79 Button {
80 text: i18n.ctr("Button: Log out from the system", "Log Out")
81 onClicked: {
82 unitySessionService.logout();
83 logoutDialog.hide();
84 }
85 }
86 Button {
87 text: i18n.tr("Cancel")
88 onClicked: {
89 logoutDialog.hide();
90 }
91 }
92 }
93 }
95 Component {
96 id: shutdownDialogComponent
97 ShellDialog {
98 id: shutdownDialog
99 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
100 text: i18n.tr("Are you sure you want to shut down?")
101 Button {
102 text: i18n.ctr("Button: Reboot the system", "Reboot")
103 onClicked: {
104 root.closeAllApps();
105 unitySessionService.reboot();
106 shutdownDialog.hide();
107 }
108 }
109 Button {
110 text: i18n.ctr("Button: Shut down the system", "Shut down")
111 onClicked: {
112 root.closeAllApps();
113 unitySessionService.shutdown();
114 shutdownDialog.hide();
115 }
116 }
117 Button {
118 text: i18n.tr("Cancel")
119 onClicked: {
120 shutdownDialog.hide();
121 }
122 }
123 }
124 }
126 Component {
127 id: rebootDialogComponent
128 ShellDialog {
129 id: rebootDialog
130 title: i18n.ctr("Title: Reboot dialog", "Reboot")
131 text: i18n.tr("Are you sure you want to reboot?")
132 Button {
133 text: i18n.tr("No")
134 onClicked: {
135 rebootDialog.hide();
136 }
137 }
138 Button {
139 text: i18n.tr("Yes")
140 onClicked: {
141 root.closeAllApps();
142 unitySessionService.reboot();
143 rebootDialog.hide();
144 }
145 }
146 }
147 }
149 Component {
150 id: powerDialogComponent
151 ShellDialog {
152 id: powerDialog
153 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
154 text: i18n.tr("Are you sure you would like\nto power off?")
155 Button {
156 text: i18n.ctr("Button: Power off the system", "Power off")
157 onClicked: {
158 root.closeAllApps();
159 powerDialog.hide();
160 root.powerOffClicked();
161 }
162 color: UbuntuColors.red
163 }
164 Button {
165 text: i18n.ctr("Button: Restart the system", "Restart")
166 onClicked: {
167 root.closeAllApps();
168 unitySessionService.reboot();
169 powerDialog.hide();
170 }
171 color: UbuntuColors.green
172 }
173 Button {
174 text: i18n.tr("Cancel")
175 onClicked: {
176 powerDialog.hide();
177 }
178 color: UbuntuColors.coolGrey
179 }
180 }
181 }
183 Connections {
184 target: root.unitySessionService
186 onLogoutRequested: {
187 // Display a dialog to ask the user to confirm.
188 if (!dialogLoader.active) {
189 dialogLoader.sourceComponent = logoutDialogComponent;
190 dialogLoader.active = true;
191 }
192 }
194 onShutdownRequested: {
195 // Display a dialog to ask the user to confirm.
196 if (!dialogLoader.active) {
197 dialogLoader.sourceComponent = shutdownDialogComponent;
198 dialogLoader.active = true;
199 }
200 }
202 onRebootRequested: {
203 // Display a dialog to ask the user to confirm.
204 if (!dialogLoader.active) {
205 dialogLoader.sourceComponent = rebootDialogComponent;
206 dialogLoader.active = true;
207 }
208 }
210 onLogoutReady: {
211 root.closeAllApps();
212 Qt.quit();
213 unitySessionService.endSession();
214 }
215 }