on c42e54e help sign in
unity8/qml/Components/Dialogs.qml
216 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.3
22import LightDM 0.1 as LightDM
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 Component {
66 id: logoutDialogComponent
67 ShellDialog {
68 id: logoutDialog
69 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
70 text: i18n.tr("Are you sure you want to log out?")
71 Button {
72 text: i18n.ctr("Button: Lock the system", "Lock")
73 onClicked: {
74 LightDM.Greeter.showGreeter()
75 logoutDialog.hide();
76 }
77 }
78 Button {
79 text: i18n.ctr("Button: Log out from the system", "Log Out")
80 onClicked: {
81 unitySessionService.logout();
82 logoutDialog.hide();
83 }
84 }
85 Button {
86 text: i18n.tr("Cancel")
87 onClicked: {
88 logoutDialog.hide();
89 }
90 }
91 }
92 }
94 Component {
95 id: shutdownDialogComponent
96 ShellDialog {
97 id: shutdownDialog
98 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
99 text: i18n.tr("Are you sure you want to shut down?")
100 Button {
101 text: i18n.ctr("Button: Reboot the system", "Reboot")
102 onClicked: {
103 root.closeAllApps();
104 unitySessionService.reboot();
105 shutdownDialog.hide();
106 }
107 }
108 Button {
109 text: i18n.ctr("Button: Shut down the system", "Shut down")
110 onClicked: {
111 root.closeAllApps();
112 unitySessionService.shutdown();
113 shutdownDialog.hide();
114 }
115 }
116 Button {
117 text: i18n.tr("Cancel")
118 onClicked: {
119 shutdownDialog.hide();
120 }
121 }
122 }
123 }
125 Component {
126 id: rebootDialogComponent
127 ShellDialog {
128 id: rebootDialog
129 title: i18n.ctr("Title: Reboot dialog", "Reboot")
130 text: i18n.tr("Are you sure you want to reboot?")
131 Button {
132 text: i18n.tr("No")
133 onClicked: {
134 rebootDialog.hide();
135 }
136 }
137 Button {
138 text: i18n.tr("Yes")
139 onClicked: {
140 root.closeAllApps();
141 unitySessionService.reboot();
142 rebootDialog.hide();
143 }
144 }
145 }
146 }
148 Component {
149 id: powerDialogComponent
150 ShellDialog {
151 id: powerDialog
152 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
153 text: i18n.tr("Are you sure you would like\nto power off?")
154 Button {
155 text: i18n.ctr("Button: Power off the system", "Power off")
156 onClicked: {
157 root.closeAllApps();
158 powerDialog.hide();
159 root.powerOffClicked();
160 }
161 color: UbuntuColors.red
162 }
163 Button {
164 text: i18n.ctr("Button: Restart the system", "Restart")
165 onClicked: {
166 root.closeAllApps();
167 unitySessionService.reboot();
168 powerDialog.hide();
169 }
170 color: UbuntuColors.green
171 }
172 Button {
173 text: i18n.tr("Cancel")
174 onClicked: {
175 powerDialog.hide();
176 }
177 color: UbuntuColors.coolGrey
178 }
179 }
180 }
182 Connections {
183 target: root.unitySessionService
185 onLogoutRequested: {
186 // Display a dialog to ask the user to confirm.
187 if (!dialogLoader.active) {
188 dialogLoader.sourceComponent = logoutDialogComponent;
189 dialogLoader.active = true;
190 }
191 }
193 onShutdownRequested: {
194 // Display a dialog to ask the user to confirm.
195 if (!dialogLoader.active) {
196 dialogLoader.sourceComponent = shutdownDialogComponent;
197 dialogLoader.active = true;
198 }
199 }
201 onRebootRequested: {
202 // Display a dialog to ask the user to confirm.
203 if (!dialogLoader.active) {
204 dialogLoader.sourceComponent = rebootDialogComponent;
205 dialogLoader.active = true;
206 }
207 }
209 onLogoutReady: {
210 root.closeAllApps();
211 Qt.quit();
212 unitySessionService.endSession();
213 }
214 }