on 13eb553 help sign in
unity8/qml/Components/Dialogs.qml
197 lines 5.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
23Item {
24 id: root
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 }
38 signal powerOffClicked();
40 function showPowerDialog() {
41 d.showPowerDialog();
42 }
44 QtObject {
45 id: d // private stuff
46 objectName: "dialogsPrivate"
49 function showPowerDialog() {
50 if (!dialogLoader.active) {
51 dialogLoader.sourceComponent = powerDialogComponent;
52 dialogLoader.active = true;
53 }
54 }
55 }
56 Loader {
57 id: dialogLoader
58 anchors.fill: parent
59 active: false
60 }
62 Component {
63 id: logoutDialogComponent
64 ShellDialog {
65 id: logoutDialog
66 title: i18n.tr("Log out")
67 text: i18n.tr("Are you sure you want to log out?")
68 Button {
69 text: i18n.tr("No")
70 onClicked: {
71 logoutDialog.hide();
72 }
73 }
74 Button {
75 text: i18n.tr("Yes")
76 onClicked: {
77 unitySessionService.logout();
78 logoutDialog.hide();
79 }
80 }
81 }
82 }
84 Component {
85 id: shutdownDialogComponent
86 ShellDialog {
87 id: shutdownDialog
88 title: i18n.tr("Shut down")
89 text: i18n.tr("Are you sure you want to shut down?")
90 Button {
91 text: i18n.tr("No")
92 onClicked: {
93 shutdownDialog.hide();
94 }
95 }
96 Button {
97 text: i18n.tr("Yes")
98 onClicked: {
99 root.closeAllApps();
100 unitySessionService.shutdown();
101 shutdownDialog.hide();
102 }
103 }
104 }
105 }
107 Component {
108 id: rebootDialogComponent
109 ShellDialog {
110 id: rebootDialog
111 title: i18n.tr("Reboot")
112 text: i18n.tr("Are you sure you want to reboot?")
113 Button {
114 text: i18n.tr("No")
115 onClicked: {
116 rebootDialog.hide();
117 }
118 }
119 Button {
120 text: i18n.tr("Yes")
121 onClicked: {
122 root.closeAllApps();
123 unitySessionService.reboot();
124 rebootDialog.hide();
125 }
126 }
127 }
128 }
130 Component {
131 id: powerDialogComponent
132 ShellDialog {
133 id: powerDialog
134 title: i18n.tr("Power")
135 text: i18n.tr("Are you sure you would like\nto power off?")
136 Button {
137 text: i18n.tr("Power off")
138 onClicked: {
139 root.closeAllApps();
140 powerDialog.hide();
141 root.powerOffClicked();
142 }
143 color: UbuntuColors.red
144 }
145 Button {
146 text: i18n.tr("Restart")
147 onClicked: {
148 root.closeAllApps();
149 unitySessionService.reboot();
150 powerDialog.hide();
151 }
152 color: UbuntuColors.green
153 }
154 Button {
155 text: i18n.tr("Cancel")
156 onClicked: {
157 powerDialog.hide();
158 }
159 color: UbuntuColors.coolGrey
160 }
161 }
162 }
164 Connections {
165 target: root.unitySessionService
167 onLogoutRequested: {
168 // Display a dialog to ask the user to confirm.
169 if (!dialogLoader.active) {
170 dialogLoader.sourceComponent = logoutDialogComponent;
171 dialogLoader.active = true;
172 }
173 }
175 onShutdownRequested: {
176 // Display a dialog to ask the user to confirm.
177 if (!dialogLoader.active) {
178 dialogLoader.sourceComponent = shutdownDialogComponent;
179 dialogLoader.active = true;
180 }
181 }
183 onRebootRequested: {
184 // Display a dialog to ask the user to confirm.
185 if (!dialogLoader.active) {
186 dialogLoader.sourceComponent = rebootDialogComponent;
187 dialogLoader.active = true;
188 }
189 }
191 onLogoutReady: {
192 root.closeAllApps();
193 Qt.quit();
194 }
195 }