on 39cfda5 help sign in
unity8/qml/GreeterShell.qml
300 lines 8.9 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.requestUrlStart(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 }
70 }
71 }
73 Connections {
74 target: LightDM.Greeter
76 onIdle: {
77 greeter.enabled = true
78 greeter.showNow()
79 }
81 onShowPrompt: {
82 if (LightDM.Users.count == 1) {
83 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
84 if (text == "PIN") {
85 lockscreen.alphaNumeric = false
86 } else {
87 lockscreen.alphaNumeric = true
88 }
89 lockscreen.placeholderText = i18n.tr("Please enter %1").arg(text);
90 lockscreen.show();
91 }
92 }
94 onAuthenticationComplete: {
95 if (LightDM.Greeter.promptless) {
96 return;
97 }
98 if (LightDM.Greeter.authenticated) {
99 lockscreen.hide();
100 } else {
101 lockscreen.clear(true);
102 }
103 }
104 }
106 Rectangle {
107 anchors.fill: parent
108 color: "black"
109 opacity: greeterWrapper.showProgress * 0.8
110 }
112 Item {
113 // Just a tiny wrapper to adjust greeter's x without messing with its own dragging
114 id: greeterWrapper
115 x: launcher.progress
116 width: parent.width
117 height: parent.height
119 Behavior on x {SmoothedAnimation{velocity: 600}}
121 readonly property real showProgress: MathUtils.clamp((1 - x/width) + greeter.showProgress - 1, 0, 1)
122 onShowProgressChanged: if (LightDM.Greeter.promptless && showProgress === 0) greeter.login()
124 Greeter {
125 id: greeter
126 objectName: "greeter"
128 available: true
129 hides: [launcher, panel.indicators]
130 shown: true
131 background: shell.background
133 y: panel.panelHeight
134 width: parent.width
135 height: parent.height - panel.panelHeight
137 dragHandleWidth: shell.edgeSize
139 function login() {
140 enabled = false;
141 LightDM.Greeter.startSessionSync();
142 }
144 onShownChanged: {
145 if (shown) {
146 lockscreen.reset();
147 // If there is only one user, we start authenticating with that one here.
148 // If there are more users, the Greeter will handle that
149 if (LightDM.Users.count == 1) {
150 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
151 }
152 greeter.forceActiveFocus();
153 }
154 }
156 onUnlocked: login()
157 onSelected: {
158 // Update launcher items for new user
159 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
160 AccountsService.user = user;
161 LauncherModel.setUser(user);
162 }
163 onTease: launcher.tease()
164 }
165 }
167 InputFilterArea {
168 anchors.fill: parent
169 blockInput: true
170 }
172 Revealer {
173 id: greeterRevealer
174 objectName: "greeterRevealer"
176 property real animatedProgress: MathUtils.clamp(-dragPosition / closedValue, 0, 1)
177 target: greeter
178 width: greeter.width
179 height: greeter.height
180 handleSize: shell.edgeSize
181 orientation: Qt.Horizontal
182 enabled: !greeter.locked
183 }
185 Item {
186 id: overlay
188 anchors.fill: parent
190 Panel {
191 id: panel
192 anchors.fill: parent //because this draws indicator menus
193 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
194 indicators {
195 hides: [launcher]
196 available: !edgeDemo.active
197 }
198 fullscreenMode: true
199 searchVisible: false
200 }
202 Timer {
203 id: initialPanelDelay
204 running: true
205 interval: 300
206 onTriggered: panel.fullscreenMode = false
207 }
209 Connections {
210 target: LightDM.Greeter
211 onIdle: {initialPanelDelay.stop(); panel.fullscreenMode = true}
212 onReset: initialPanelDelay.start()
213 }
215 Launcher {
216 id: launcher
218 anchors.top: parent.top
219 anchors.bottom: parent.bottom
220 width: parent.width
221 dragAreaWidth: shell.edgeSize
222 available: greeter.narrowMode && !edgeDemo.active
223 onLauncherApplicationSelected: {
224 shell.activateApplication("application:///" + appId + ".desktop")
225 }
226 onShownChanged: {
227 if (shown) {
228 panel.indicators.hide()
229 }
230 }
231 onDash: {
232 greeter.hideRight()
233 hide()
234 }
235 onShowDashHome: greeter.show()
236 }
238 Notifications {
239 id: notifications
241 model: NotificationBackend.Model
242 anchors {
243 top: parent.top
244 right: parent.right
245 bottom: parent.bottom
246 leftMargin: units.gu(1)
247 rightMargin: units.gu(1)
248 topMargin: panel.panelHeight + units.gu(1)
249 }
250 states: [
251 State {
252 name: "narrow"
253 when: overlay.width <= units.gu(60)
254 AnchorChanges { target: notifications; anchors.left: parent.left }
255 },
256 State {
257 name: "wide"
258 when: overlay.width > units.gu(60)
259 AnchorChanges { target: notifications; anchors.left: undefined }
260 PropertyChanges { target: notifications; width: units.gu(38) }
261 }
262 ]
264 InputFilterArea {
265 anchors { left: parent.left; right: parent.right }
266 height: parent.contentHeight
267 blockInput: height > 0
268 }
269 }
270 }
272 OSKController {
273 anchors.topMargin: panel.panelHeight
274 anchors.fill: parent // as needs to know the geometry of the shell
275 }
277 Connections {
278 id: powerConnection
279 target: Powerd
281 onDisplayPowerStateChange: {
282 if (status == Powerd.Off) {
283 greeter.show();
284 edgeDemo.paused = true;
285 } else if (status == Powerd.On) {
286 edgeDemo.paused = false;
287 }
288 }
289 }
291 Connections {
292 target: LightDM.URLDispatcher
293 onDispatchURL: shell.activateApplication(url)
294 }
296 GreeterEdgeDemo {
297 id: edgeDemo
298 greeter: greeter
299 }