on ffe76cc help sign in
unity8/qml/Components/Dialogs.qml
195 lines 5.8 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 Ubuntu.Components.Popups 0.1
24Item {
25 id: root
27 signal powerOffClicked();
29 property bool dialogShown: false
31 function showPowerDialog() {
32 if (!dialogShown) {
33 dialogShown = true;
34 PopupUtils.open(powerDialog, root, {"z": root.z});
35 }
36 }
38 Component {
39 id: logoutDialog
40 Dialog {
41 id: dialogueLogout
42 title: i18n.tr("Log out")
43 text: i18n.tr("Are you sure you want to log out?")
44 Button {
45 text: i18n.tr("No")
46 onClicked: {
47 PopupUtils.close(dialogueLogout);
48 d.dialogShown = false;
49 }
50 }
51 Button {
52 text: i18n.tr("Yes")
53 onClicked: {
54 DBusUnitySessionService.Logout();
55 PopupUtils.close(dialogueLogout);
56 d.dialogShown = false;
57 }
58 }
59 }
60 }
62 Component {
63 id: shutdownDialog
64 Dialog {
65 id: dialogueShutdown
66 title: i18n.tr("Shut down")
67 text: i18n.tr("Are you sure you want to shut down?")
68 Button {
69 text: i18n.tr("No")
70 onClicked: {
71 PopupUtils.close(dialogueShutdown);
72 d.dialogShown = false;
73 }
74 }
75 Button {
76 text: i18n.tr("Yes")
77 onClicked: {
78 dBusUnitySessionServiceConnection.closeAllApps();
79 DBusUnitySessionService.Shutdown();
80 PopupUtils.close(dialogueShutdown);
81 d.dialogShown = false;
82 }
83 }
84 }
85 }
87 Component {
88 id: rebootDialog
89 Dialog {
90 id: dialogueReboot
91 title: i18n.tr("Reboot")
92 text: i18n.tr("Are you sure you want to reboot?")
93 Button {
94 text: i18n.tr("No")
95 onClicked: {
96 PopupUtils.close(dialogueReboot)
97 d.dialogShown = false;
98 }
99 }
100 Button {
101 text: i18n.tr("Yes")
102 onClicked: {
103 dBusUnitySessionServiceConnection.closeAllApps();
104 DBusUnitySessionService.Reboot();
105 PopupUtils.close(dialogueReboot);
106 d.dialogShown = false;
107 }
108 }
109 }
110 }
112 Component {
113 id: powerDialog
114 Dialog {
115 id: dialoguePower
116 title: i18n.tr("Power")
117 text: i18n.tr("Are you sure you would like\nto power off?")
118 Button {
119 text: i18n.tr("Power off")
120 onClicked: {
121 dBusUnitySessionServiceConnection.closeAllApps();
122 PopupUtils.close(dialoguePower);
123 d.dialogShown = false;
124 root.powerOffClicked();
125 }
126 color: UbuntuColors.red
127 }
128 Button {
129 text: i18n.tr("Restart")
130 onClicked: {
131 dBusUnitySessionServiceConnection.closeAllApps();
132 DBusUnitySessionService.Reboot();
133 PopupUtils.close(dialoguePower);
134 d.dialogShown = false;
135 }
136 color: UbuntuColors.green
137 }
138 Button {
139 text: i18n.tr("Cancel")
140 onClicked: {
141 PopupUtils.close(dialoguePower);
142 d.dialogShown = false;
143 }
144 color: UbuntuColors.coolGrey
145 }
146 }
147 }
150 Connections {
151 id: dBusUnitySessionServiceConnection
152 objectName: "dBusUnitySessionServiceConnection"
153 target: DBusUnitySessionService
155 function closeAllApps() {
156 while (true) {
157 var app = ApplicationManager.get(0);
158 if (app === null) {
159 break;
160 }
161 ApplicationManager.stopApplication(app.appId);
162 }
163 }
165 onLogoutRequested: {
166 // Display a dialog to ask the user to confirm.
167 if (!d.dialogShown) {
168 d.dialogShown = true;
169 PopupUtils.open(logoutDialog, root, {"z": root.z});
170 }
171 }
173 onShutdownRequested: {
174 // Display a dialog to ask the user to confirm.
175 if (!d.dialogShown) {
176 d.dialogShown = true;
177 PopupUtils.open(shutdownDialog, root, {"z": root.z});
178 }
179 }
181 onRebootRequested: {
182 // Display a dialog to ask the user to confirm.
183 if (!d.dialogShown) {
184 d.dialogShown = true;
185 PopupUtils.open(rebootDialog, root, {"z": root.z});
186 }
187 }
189 onLogoutReady: {
190 closeAllApps();
191 Qt.quit();
192 }
193 }