on 08bf9db help sign in
unity8/qml/Components/Dialogs.qml
217 lines 6.1 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 0.1
22import Ubuntu.Components.Popups 0.1
24Item {
25 id: root
27 function onPowerKeyPressed() {
28 if (!powerKeyTimer.running) {
29 powerKeyTimer.start();
30 }
31 }
33 function onPowerKeyReleased() {
34 powerKeyTimer.stop();
35 }
37 signal powerOffClicked();
39 QtObject {
40 id: d // private stuff
42 property bool dialogShown: false
44 function showPowerDialog() {
45 if (!d.dialogShown) {
46 d.dialogShown = true;
47 PopupUtils.open(powerDialog, root, {"z": root.z});
48 }
49 }
50 }
52 Timer {
53 id: powerKeyTimer
54 interval: 2000
55 repeat: false
56 triggeredOnStart: false
58 onTriggered: {
59 d.showPowerDialog();
60 }
61 }
63 Component {
64 id: logoutDialog
65 Dialog {
66 id: dialogueLogout
67 title: "Logout"
68 text: "Are you sure that you want to logout?"
69 Button {
70 text: "Cancel"
71 onClicked: {
72 PopupUtils.close(dialogueLogout);
73 d.dialogShown = false;
74 }
75 }
76 Button {
77 text: "Yes"
78 onClicked: {
79 DBusUnitySessionService.Logout();
80 PopupUtils.close(dialogueLogout);
81 d.dialogShown = false;
82 }
83 }
84 }
85 }
87 Component {
88 id: shutdownDialog
89 Dialog {
90 id: dialogueShutdown
91 title: "Shutdown"
92 text: "Are you sure that you want to shutdown?"
93 Button {
94 text: "Cancel"
95 onClicked: {
96 PopupUtils.close(dialogueShutdown);
97 d.dialogShown = false;
98 }
99 }
100 Button {
101 text: "Yes"
102 onClicked: {
103 dBusUnitySessionServiceConnection.closeAllApps();
104 DBusUnitySessionService.Shutdown();
105 PopupUtils.close(dialogueShutdown);
106 d.dialogShown = false;
107 }
108 }
109 }
110 }
112 Component {
113 id: rebootDialog
114 Dialog {
115 id: dialogueReboot
116 title: "Reboot"
117 text: "Are you sure that you want to reboot?"
118 Button {
119 text: "Cancel"
120 onClicked: {
121 PopupUtils.close(dialogueReboot)
122 d.dialogShown = false;
123 }
124 }
125 Button {
126 text: "Yes"
127 onClicked: {
128 dBusUnitySessionServiceConnection.closeAllApps();
129 DBusUnitySessionService.Reboot();
130 PopupUtils.close(dialogueReboot);
131 d.dialogShown = false;
132 }
133 }
134 }
135 }
137 Component {
138 id: powerDialog
139 Dialog {
140 id: dialoguePower
141 title: "Power"
142 text: i18n.tr("Are you sure you would like to turn power off?")
143 Button {
144 text: i18n.tr("Power off")
145 onClicked: {
146 dBusUnitySessionServiceConnection.closeAllApps();
147 PopupUtils.close(dialoguePower);
148 d.dialogShown = false;
149 root.powerOffClicked();
150 }
151 }
152 Button {
153 text: i18n.tr("Restart")
154 onClicked: {
155 dBusUnitySessionServiceConnection.closeAllApps();
156 DBusUnitySessionService.Reboot();
157 PopupUtils.close(dialoguePower);
158 d.dialogShown = false;
159 }
160 }
161 Button {
162 text: i18n.tr("Cancel")
163 onClicked: {
164 PopupUtils.close(dialoguePower);
165 d.dialogShown = false;
166 }
167 }
168 }
169 }
172 Connections {
173 id: dBusUnitySessionServiceConnection
174 objectName: "dBusUnitySessionServiceConnection"
175 target: DBusUnitySessionService
177 function closeAllApps() {
178 while (true) {
179 var app = ApplicationManager.get(0);
180 if (app === null) {
181 break;
182 }
183 ApplicationManager.stopApplication(app.appId);
184 }
185 }
187 onLogoutRequested: {
188 // Display a dialog to ask the user to confirm.
189 if (!d.dialogShown) {
190 d.dialogShown = true;
191 PopupUtils.open(logoutDialog, root, {"z": root.z});
192 }
193 }
195 onShutdownRequested: {
196 // Display a dialog to ask the user to confirm.
197 if (!d.dialogShown) {
198 d.dialogShown = true;
199 PopupUtils.open(shutdownDialog, root, {"z": root.z});
200 }
201 }
203 onRebootRequested: {
204 // Display a dialog to ask the user to confirm.
205 if (!d.dialogShown) {
206 d.dialogShown = true;
207 PopupUtils.open(rebootDialog, root, {"z": root.z});
208 }
209 }
211 onLogoutReady: {
212 closeAllApps();
213 Qt.quit();
214 }
215 }