on 0ec5075 help sign in
unity8/qml/GreeterShell.qml
293 lines 8.7 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: initialPanelDelay.running
199 searchVisible: false
200 }
202 Timer {
203 id: initialPanelDelay
204 running: true
205 interval: 300
206 }
208 Launcher {
209 id: launcher
211 anchors.top: parent.top
212 anchors.bottom: parent.bottom
213 width: parent.width
214 dragAreaWidth: shell.edgeSize
215 available: greeter.narrowMode && !edgeDemo.active
216 onLauncherApplicationSelected: {
217 shell.activateApplication("application:///" + appId + ".desktop")
218 }
219 onShownChanged: {
220 if (shown) {
221 panel.indicators.hide()
222 }
223 }
224 onDash: {
225 greeter.hideRight()
226 hide()
227 }
228 onShowDashHome: greeter.show()
229 }
231 Notifications {
232 id: notifications
234 model: NotificationBackend.Model
235 anchors {
236 top: parent.top
237 right: parent.right
238 bottom: parent.bottom
239 leftMargin: units.gu(1)
240 rightMargin: units.gu(1)
241 topMargin: panel.panelHeight + units.gu(1)
242 }
243 states: [
244 State {
245 name: "narrow"
246 when: overlay.width <= units.gu(60)
247 AnchorChanges { target: notifications; anchors.left: parent.left }
248 },
249 State {
250 name: "wide"
251 when: overlay.width > units.gu(60)
252 AnchorChanges { target: notifications; anchors.left: undefined }
253 PropertyChanges { target: notifications; width: units.gu(38) }
254 }
255 ]
257 InputFilterArea {
258 anchors { left: parent.left; right: parent.right }
259 height: parent.contentHeight
260 blockInput: height > 0
261 }
262 }
263 }
265 OSKController {
266 anchors.topMargin: panel.panelHeight
267 anchors.fill: parent // as needs to know the geometry of the shell
268 }
270 Connections {
271 id: powerConnection
272 target: Powerd
274 onDisplayPowerStateChange: {
275 if (status == Powerd.Off) {
276 greeter.show();
277 edgeDemo.paused = true;
278 } else if (status == Powerd.On) {
279 edgeDemo.paused = false;
280 }
281 }
282 }
284 Connections {
285 target: LightDM.URLDispatcher
286 onDispatchURL: shell.activateApplication(url)
287 }
289 GreeterEdgeDemo {
290 id: edgeDemo
291 greeter: greeter
292 }