on b98b649 help sign in
unity8/qml/GreeterShell.qml
277 lines 8.3 kB history raw
1/*
2 * Copyright (C) 2013 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 AccountsService 0.1
18import GSettings 1.0
19import LightDM 0.1 as LightDM
20import Powerd 0.1
21import QtQuick 2.0
22import SessionBroadcast 0.1
23import Ubuntu.Components 0.1
24import Unity.Application 0.1
25import Unity.Launcher 0.1
26import "Components"
27import "Greeter"
28import "Launcher"
29import "Panel"
30import "Notifications"
31import Unity.Notifications 1.0 as NotificationBackend
33BasicShell {
34 id: shell
36 function activateApplication(appId) {
37 SessionBroadcast.requestApplicationStart(LightDM.Greeter.authenticationUser, appId)
38 greeter.hide()
39 }
41 GSettings {
42 id: backgroundSettings
43 schema.id: "org.gnome.desktop.background"
44 }
45 backgroundFallbackSource: backgroundSettings.pictureUri // for ease of customization by system builders
46 backgroundSource: AccountsService.backgroundFile
48 Lockscreen {
49 id: lockscreen
50 objectName: "lockscreen"
52 hides: [launcher, panel.indicators]
53 shown: false
54 enabled: true
55 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
56 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
57 y: panel.panelHeight
58 x: required ? 0 : - width
59 width: parent.width
60 height: parent.height - panel.panelHeight
61 pinLength: 4
63 onEntered: LightDM.Greeter.respond(passphrase);
64 onCancel: greeter.show()
66 Component.onCompleted: {
67 if (LightDM.Users.count == 1) {
68 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
69 greeter.selected(0)
70 }
71 }
72 }
74 Connections {
75 target: LightDM.Greeter
77 onShowPrompt: {
78 if (LightDM.Users.count == 1) {
79 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
80 if (text == "PIN") {
81 lockscreen.alphaNumeric = false
82 } else {
83 lockscreen.alphaNumeric = true
84 }
85 lockscreen.placeholderText = i18n.tr("Please enter %1").arg(text);
86 lockscreen.show();
87 }
88 }
90 onAuthenticationComplete: {
91 if (LightDM.Greeter.promptless) {
92 return;
93 }
94 if (LightDM.Greeter.authenticated) {
95 lockscreen.hide();
96 } else {
97 lockscreen.clear(true);
98 }
99 }
100 }
102 Greeter {
103 id: greeter
104 objectName: "greeter"
106 available: true
107 hides: [launcher, panel.indicators]
108 shown: true
109 background: shell.background
111 y: panel.panelHeight
112 width: parent.width
113 height: parent.height - panel.panelHeight
115 dragHandleWidth: shell.edgeSize
117 function login() {
118 enabled = false;
119 LightDM.Greeter.startSessionSync();
120 }
122 onShownChanged: {
123 if (shown) {
124 lockscreen.reset();
125 // If there is only one user, we start authenticating with that one here.
126 // If there are more users, the Greeter will handle that
127 if (LightDM.Users.count == 1) {
128 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
129 greeter.selected(0);
130 }
131 greeter.forceActiveFocus();
132 }
133 }
135 onShowProgressChanged: if (LightDM.Greeter.promptless && showProgress == 0) login()
137 onUnlocked: login()
138 onSelected: {
139 // Update launcher items for new user
140 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
141 AccountsService.user = user;
142 LauncherModel.setUser(user);
143 }
145 onLeftTeaserPressedChanged: {
146 if (leftTeaserPressed) {
147 launcher.tease();
148 }
149 }
150 }
152 InputFilterArea {
153 anchors.fill: parent
154 blockInput: true
155 }
157 Revealer {
158 id: greeterRevealer
159 objectName: "greeterRevealer"
161 property real animatedProgress: MathUtils.clamp(-dragPosition / closedValue, 0, 1)
162 target: greeter
163 width: greeter.width
164 height: greeter.height
165 handleSize: shell.edgeSize
166 orientation: Qt.Horizontal
167 enabled: !greeter.locked
168 }
170 Item {
171 id: overlay
173 anchors.fill: parent
175 Panel {
176 id: panel
177 anchors.fill: parent //because this draws indicator menus
178 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
179 indicators {
180 hides: [launcher]
181 available: !edgeDemo.active
182 }
183 fullscreenMode: false
184 searchVisible: false
185 }
187 Launcher {
188 id: launcher
190 anchors.top: parent.top
191 anchors.bottom: parent.bottom
192 width: parent.width
193 dragAreaWidth: shell.edgeSize
194 available: greeter.narrowMode && !edgeDemo.active
195 onLauncherApplicationSelected: {
196 shell.activateApplication(appId)
197 }
198 onShownChanged: {
199 if (shown) {
200 panel.indicators.hide()
201 }
202 }
203 onShowDashHome: greeter.show()
204 }
206 Notifications {
207 id: notifications
209 model: NotificationBackend.Model
210 anchors {
211 top: parent.top
212 right: parent.right
213 bottom: parent.bottom
214 leftMargin: units.gu(1)
215 rightMargin: units.gu(1)
216 topMargin: panel.panelHeight + units.gu(1)
217 }
218 states: [
219 State {
220 name: "narrow"
221 when: overlay.width <= units.gu(60)
222 AnchorChanges { target: notifications; anchors.left: parent.left }
223 },
224 State {
225 name: "wide"
226 when: overlay.width > units.gu(60)
227 AnchorChanges { target: notifications; anchors.left: undefined }
228 PropertyChanges { target: notifications; width: units.gu(38) }
229 }
230 ]
232 InputFilterArea {
233 anchors { left: parent.left; right: parent.right }
234 height: parent.contentHeight
235 blockInput: height > 0
236 }
237 }
238 }
240 Connections {
241 id: powerConnection
242 target: Powerd
244 onDisplayPowerStateChange: {
245 if (status == Powerd.Off) {
246 greeter.show();
247 edgeDemo.paused = true;
248 } else if (status == Powerd.On) {
249 edgeDemo.paused = false;
250 }
251 }
252 }
254/*
255 Connections {
256 target: applicationManager
257 ignoreUnknownSignals: true
258 // If any app is focused when greeter is open, it's due to a user action
259 // like a snap decision (say, an incoming call).
260 // TODO: these should be protected to only unlock for certain applications / certain usecases
261 // potentially only in connection with a notification.
262 // TODO: what about the app the shell will restore focus to by itself?
263 onMainStageFocusedApplicationChanged: greeter.hide()
264 onSideStageFocusedApplicationChanged: greeter.hide()
265 }
266*/
268 Connections {
269 target: LightDM.Upstart
270 onDispatchURL: shell.activateApplication(url)
271 }
273 GreeterEdgeDemo {
274 id: edgeDemo
275 greeter: greeter
276 }