on aa49fd3 help sign in
unity8/GreeterShell.qml
226 lines 6.8 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 Unity.Application 0.1
24import Unity.Launcher 0.1
25import "Components"
26import "Components/Math.js" as MathLocal
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 hides: [launcher, panel.indicators]
49 shown: false
50 enabled: true
51 showAnimation: StandardAnimation { property: "opacity"; to: 1 }
52 hideAnimation: StandardAnimation { property: "opacity"; to: 0 }
53 y: panel.panelHeight
54 x: required ? 0 : - width
55 width: parent.width
56 height: parent.height - panel.panelHeight
58 onUnlocked: lockscreen.hide()
59 onCancel: greeter.show()
61 Component.onCompleted: {
62 if (LightDM.Users.count == 1) {
63 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole))
64 greeter.selected(0)
65 }
66 }
67 }
69 Connections {
70 target: LightDM.Greeter
72 onShowPrompt: {
73 if (LightDM.Users.count == 1) {
74 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
75 if (text == "PIN") {
76 lockscreen.alphaNumeric = false
77 } else {
78 lockscreen.alphaNumeric = true
79 }
80 lockscreen.placeholderText = i18n.tr("Please enter %1").arg(text);
81 lockscreen.show();
82 }
83 }
84 }
86 Greeter {
87 id: greeter
88 objectName: "greeter"
90 available: true
91 hides: [launcher, panel.indicators]
92 shown: true
93 background: shell.background
95 y: panel.panelHeight
96 width: parent.width
97 height: parent.height - panel.panelHeight
99 dragHandleWidth: shell.edgeSize
101 function login() {
102 enabled = false;
103 LightDM.Greeter.startSessionSync();
104 }
106 onShownChanged: {
107 if (shown) {
108 lockscreen.reset();
109 // If there is only one user, we start authenticating with that one here.
110 // If there are more users, the Greeter will handle that
111 if (LightDM.Users.count == 1) {
112 LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
113 greeter.selected(0);
114 }
115 greeter.forceActiveFocus();
116 }
117 else if (LightDM.Greeter.promptless)
118 login();
119 }
121 onUnlocked: login()
122 onSelected: {
123 // Update launcher items for new user
124 var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
125 AccountsService.user = user;
126 LauncherModel.setUser(user);
127 }
129 onLeftTeaserPressedChanged: {
130 if (leftTeaserPressed) {
131 launcher.tease();
132 }
133 }
134 }
136 InputFilterArea {
137 anchors.fill: parent
138 blockInput: true
139 }
141 Revealer {
142 id: greeterRevealer
143 objectName: "greeterRevealer"
145 property real animatedProgress: MathLocal.clamp(-dragPosition / closedValue, 0, 1)
146 target: greeter
147 width: greeter.width
148 height: greeter.height
149 handleSize: shell.edgeSize
150 orientation: Qt.Horizontal
151 enabled: !greeter.locked
152 }
154 Item {
155 id: overlay
157 anchors.fill: parent
159 Panel {
160 id: panel
161 anchors.fill: parent //because this draws indicator menus
162 indicatorsMenuWidth: parent.width > units.gu(60) ? units.gu(40) : parent.width
163 indicators {
164 hides: [launcher]
165 available: !edgeDemo.active
166 }
167 fullscreenMode: false
168 searchVisible: false
169 }
171 Launcher {
172 id: launcher
174 anchors.top: parent.top
175 anchors.bottom: parent.bottom
176 width: parent.width
177 dragAreaWidth: shell.edgeSize
178 available: greeter.narrowMode && !edgeDemo.active
179 onLauncherApplicationSelected: {
180 shell.activateApplication(appId)
181 }
182 onShownChanged: {
183 if (shown) {
184 panel.indicators.hide()
185 }
186 }
187 onDashItemSelected: greeter.show()
188 }
189 }
191 OSKController {
192 anchors.topMargin: panel.panelHeight
193 anchors.fill: parent // as needs to know the geometry of the shell
194 }
196 Connections {
197 id: powerConnection
198 target: Powerd
200 onDisplayPowerStateChange: {
201 if (status == Powerd.Off) {
202 greeter.show();
203 edgeDemo.paused = true;
204 } else if (status == Powerd.On) {
205 edgeDemo.paused = false;
206 }
207 }
208 }
210 Connections {
211 target: applicationManager
212 ignoreUnknownSignals: true
213 // If any app is focused when greeter is open, it's due to a user action
214 // like a snap decision (say, an incoming call).
215 // TODO: these should be protected to only unlock for certain applications / certain usecases
216 // potentially only in connection with a notification.
217 // TODO: what about the app the shell will restore focus to by itself?
218 onMainStageFocusedApplicationChanged: greeter.hide()
219 onSideStageFocusedApplicationChanged: greeter.hide()
220 }
222 GreeterEdgeDemo {
223 id: edgeDemo
224 greeter: greeter
225 }