on 210aff0 help sign in
unity8/GreeterShell.qml
241 lines 7.1 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"
31BasicShell {
32 id: shell
34 function activateApplication(appId) {
35 SessionBroadcast.requestApplicationStart(LightDM.Greeter.authenticationUser, appId)
36 greeter.hide()
37 }
39 GSettings {
40 id: backgroundSettings
41 schema.id: "org.gnome.desktop.background"
42 }
43 backgroundFallbackSource: backgroundSettings.pictureUri // for ease of customization by system builders
44 backgroundSource: AccountsService.backgroundFile
46 Lockscreen {
47 id: lockscreen
48 objectName: "lockscreen"
50 hides: [launcher, panel.indicators]
51 shown: false
52 enabled: true
53 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
54 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
55 y: panel.panelHeight
56 x: required ? 0 : - width
57 width: parent.width
58 height: parent.height - panel.panelHeight
60 onEntered: LightDM.Greeter.respond(passphrase);
61 onCancel: greeter.show()
63 Component.onCompleted: {
64 if (LightDM.Users.count == 1) {
65 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
66 greeter.selected(0)
67 }
68 }
69 }
71 Connections {
72 target: LightDM.Greeter
74 onShowPrompt: {
75 if (LightDM.Users.count == 1) {
76 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
77 if (text == "PIN") {
78 lockscreen.alphaNumeric = false
79 } else {
80 lockscreen.alphaNumeric = true
81 }
82 lockscreen.placeholderText = i18n.tr("Please enter %1").arg(text);
83 lockscreen.show();
84 }
85 }
87 onAuthenticationComplete: {
88 if (LightDM.Greeter.promptless) {
89 return;
90 }
91 if (LightDM.Greeter.authenticated) {
92 lockscreen.hide();
93 } else {
94 lockscreen.clear(true);
95 }
96 }
97 }
99 Greeter {
100 id: greeter
101 objectName: "greeter"
103 available: true
104 hides: [launcher, panel.indicators]
105 shown: true
106 background: shell.background
108 y: panel.panelHeight
109 width: parent.width
110 height: parent.height - panel.panelHeight
112 dragHandleWidth: shell.edgeSize
114 function login() {
115 enabled = false;
116 LightDM.Greeter.startSessionSync();
117 }
119 onShownChanged: {
120 if (shown) {
121 lockscreen.reset();
122 // If there is only one user, we start authenticating with that one here.
123 // If there are more users, the Greeter will handle that
124 if (LightDM.Users.count == 1) {
125 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
126 greeter.selected(0);
127 }
128 greeter.forceActiveFocus();
129 }
130 }
132 onShowProgressChanged: if (LightDM.Greeter.promptless && showProgress == 0) login()
134 onUnlocked: login()
135 onSelected: {
136 // Update launcher items for new user
137 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
138 AccountsService.user = user;
139 LauncherModel.setUser(user);
140 }
142 onLeftTeaserPressedChanged: {
143 if (leftTeaserPressed) {
144 launcher.tease();
145 }
146 }
147 }
149 InputFilterArea {
150 anchors.fill: parent
151 blockInput: true
152 }
154 Revealer {
155 id: greeterRevealer
156 objectName: "greeterRevealer"
158 property real animatedProgress: MathUtils.clamp(-dragPosition / closedValue, 0, 1)
159 target: greeter
160 width: greeter.width
161 height: greeter.height
162 handleSize: shell.edgeSize
163 orientation: Qt.Horizontal
164 enabled: !greeter.locked
165 }
167 Item {
168 id: overlay
170 anchors.fill: parent
172 Panel {
173 id: panel
174 anchors.fill: parent //because this draws indicator menus
175 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
176 indicators {
177 hides: [launcher]
178 available: !edgeDemo.active
179 }
180 fullscreenMode: false
181 searchVisible: false
182 }
184 Launcher {
185 id: launcher
187 anchors.top: parent.top
188 anchors.bottom: parent.bottom
189 width: parent.width
190 dragAreaWidth: shell.edgeSize
191 available: greeter.narrowMode && !edgeDemo.active
192 onLauncherApplicationSelected: {
193 shell.activateApplication(appId)
194 }
195 onShownChanged: {
196 if (shown) {
197 panel.indicators.hide()
198 }
199 }
200 onDashItemSelected: greeter.show()
201 }
202 }
204 Connections {
205 id: powerConnection
206 target: Powerd
208 onDisplayPowerStateChange: {
209 if (status == Powerd.Off) {
210 greeter.show();
211 edgeDemo.paused = true;
212 } else if (status == Powerd.On) {
213 edgeDemo.paused = false;
214 }
215 }
216 }
218/*
219 Connections {
220 target: applicationManager
221 ignoreUnknownSignals: true
222 // If any app is focused when greeter is open, it's due to a user action
223 // like a snap decision (say, an incoming call).
224 // TODO: these should be protected to only unlock for certain applications / certain usecases
225 // potentially only in connection with a notification.
226 // TODO: what about the app the shell will restore focus to by itself?
227 onMainStageFocusedApplicationChanged: greeter.hide()
228 onSideStageFocusedApplicationChanged: greeter.hide()
229 }
230*/
232 Connections {
233 target: LightDM.Upstart
234 onDispatchURL: shell.activateApplication(url)
235 }
237 GreeterEdgeDemo {
238 id: edgeDemo
239 greeter: greeter
240 }