on e340ac9 help sign in
unity8/qml/GreeterShell.qml
283 lines 8.4 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 minPinLength: 4
62 maxPinLength: 4
64 onEntered: LightDM.Greeter.respond(passphrase);
65 onCancel: greeter.show()
67 Component.onCompleted: {
68 if (LightDM.Users.count == 1) {
69 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
70 }
71 }
72 }
74 Connections {
75 target: LightDM.Greeter
77 onIdle: {
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 {
120 enabled: !launcher.dashSwipe
121 StandardAnimation {}
122 }
124 readonly property real showProgress: MathUtils.clamp((1 - x/width) + greeter.showProgress - 1, 0, 1)
125 onShowProgressChanged: if (LightDM.Greeter.promptless && showProgress === 0) greeter.login()
127 Greeter {
128 id: greeter
129 objectName: "greeter"
131 available: true
132 hides: [launcher, panel.indicators]
133 shown: true
134 background: shell.background
136 y: panel.panelHeight
137 width: parent.width
138 height: parent.height - panel.panelHeight
140 dragHandleWidth: shell.edgeSize
142 function login() {
143 enabled = false;
144 LightDM.Greeter.startSessionSync();
145 enabled = true;
146 }
148 onShownChanged: {
149 if (shown) {
150 lockscreen.reset();
151 // If there is only one user, we start authenticating with that one here.
152 // If there are more users, the Greeter will handle that
153 if (LightDM.Users.count == 1) {
154 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
155 }
156 greeter.forceActiveFocus();
157 }
158 }
160 onUnlocked: hide()
161 onSelected: {
162 // Update launcher items for new user
163 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
164 AccountsService.user = user;
165 LauncherModel.setUser(user);
166 }
167 onTease: launcher.tease()
168 }
169 }
171 InputFilterArea {
172 anchors.fill: parent
173 blockInput: true
174 }
176 Item {
177 id: overlay
179 anchors.fill: parent
181 Panel {
182 id: panel
183 anchors.fill: parent //because this draws indicator menus
184 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
185 indicators {
186 hides: [launcher]
187 available: !edgeDemo.active
188 }
189 fullscreenMode: false
190 searchVisible: false
191 }
193 Launcher {
194 id: launcher
196 readonly property bool dashSwipe: progress > 0
198 anchors.top: parent.top
199 anchors.bottom: parent.bottom
200 width: parent.width
201 dragAreaWidth: shell.edgeSize
202 available: !edgeDemo.active
203 onLauncherApplicationSelected: {
204 shell.activateApplication(LauncherModel.getUrlForAppId(appId))
205 }
206 onShownChanged: {
207 if (shown) {
208 panel.indicators.hide()
209 }
210 }
211 onDash: {
212 greeter.hideRight()
213 hide()
214 }
215 onShowDashHome: {
216 SessionBroadcast.requestHomeShown(LightDM.Greeter.authenticationUser)
217 greeter.hide()
218 }
219 }
221 Notifications {
222 id: notifications
224 model: NotificationBackend.Model
225 margin: units.gu(1)
227 anchors {
228 top: parent.top
229 right: parent.right
230 bottom: parent.bottom
231 topMargin: panel.panelHeight
232 }
233 states: [
234 State {
235 name: "narrow"
236 when: overlay.width <= units.gu(60)
237 AnchorChanges { target: notifications; anchors.left: parent.left }
238 },
239 State {
240 name: "wide"
241 when: overlay.width > units.gu(60)
242 AnchorChanges { target: notifications; anchors.left: undefined }
243 PropertyChanges { target: notifications; width: units.gu(38) }
244 }
245 ]
247 InputFilterArea {
248 anchors { left: parent.left; right: parent.right }
249 height: parent.contentHeight
250 blockInput: height > 0
251 }
252 }
253 }
255 OSKController {
256 anchors.topMargin: panel.panelHeight
257 anchors.fill: parent // as needs to know the geometry of the shell
258 }
260 Connections {
261 id: powerConnection
262 target: Powerd
264 onDisplayPowerStateChange: {
265 if (status == Powerd.Off) {
266 greeter.show();
267 edgeDemo.paused = true;
268 } else if (status == Powerd.On) {
269 edgeDemo.paused = false;
270 }
271 }
272 }
274 Connections {
275 target: LightDM.URLDispatcher
276 onDispatchURL: shell.activateApplication(url)
277 }
279 GreeterEdgeDemo {
280 id: edgeDemo
281 greeter: greeter
282 }