2 * Copyright (C) 2013-2016 Canonical Ltd.
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.
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.
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/>.
18import QtGraphicalEffects 1.0
19import Lomiri.Components 1.3
27 property alias model: userList.model
28 property alias alphanumeric: promptList.alphanumeric
29 property alias hasKeyboard: promptList.hasKeyboard
30 property int currentIndex
33 property alias boxVerticalOffset: highlightItem.y
34 property string _realName
36 readonly property int numAboveBelow: 4
37 readonly property int cellHeight: units.gu(5)
38 readonly property int highlightedHeight: highlightItem.height
39 readonly property int moveDuration: LomiriAnimation.FastDuration
40 property string currentSession // Initially set by LightDM
41 readonly property string currentUser: userList.currentItem.username
43 readonly property alias currentUserIndex: userList.currentIndex
45 signal responded(string response)
46 signal selected(int index)
47 signal sessionChooserButtonClicked()
49 function tryToUnlock() {
50 promptList.forceActiveFocus();
53 function showError() {
54 promptList.loginError = true;
55 wrongPasswordAnimation.start();
58 function showFakePassword() {
59 promptList.interactive = false;
60 promptList.showFakePassword();
63 theme: ThemeSettings {
64 name: "Lomiri.Components.Themes.Ambiance"
68 if (currentIndex > 0) {
69 selected(currentIndex - 1);
71 event.accepted = true;
74 if (currentIndex + 1 < model.count) {
75 selected(currentIndex + 1);
77 event.accepted = true;
79 Keys.onEscapePressed: {
80 selected(currentIndex);
81 event.accepted = true;
84 onCurrentIndexChanged: {
85 userList.currentIndex = currentIndex;
86 promptList.loginError = false;
91 objectName: "highlightItem"
94 leftMargin: units.gu(2)
96 rightMargin: units.gu(2)
99 height: Math.max(units.gu(15), promptList.height + units.gu(8))
100 Behavior on height { NumberAnimation { duration: root.moveDuration; easing.type: Easing.InOutQuad; } }
105 objectName: "userList"
108 anchors.leftMargin: units.gu(2)
109 anchors.rightMargin: units.gu(2)
111 preferredHighlightBegin: highlightItem.y + units.gu(1.5)
112 preferredHighlightEnd: highlightItem.y + units.gu(1.5)
113 highlightRangeMode: ListView.StrictlyEnforceRange
114 highlightMoveDuration: root.moveDuration
115 interactive: count > 1
117 readonly property bool movingInternally: moveTimer.running || userList.moving
119 onMovingChanged: if (!moving) root.selected(currentIndex)
121 onCurrentIndexChanged: {
126 width: userList.width
127 height: root.cellHeight
129 readonly property bool belowHighlight: (userList.currentIndex < 0 && index > 0) || (userList.currentIndex >= 0 && index > userList.currentIndex)
130 readonly property bool aboveCurrent: (userList.currentIndex > 0 && index < 0) || (userList.currentIndex >= 0 && index < userList.currentIndex)
131 readonly property int belowOffset: root.highlightedHeight - root.cellHeight
132 readonly property string userSession: session
133 readonly property string username: name
136 // The goal here is to make names less and less opaque as they
137 // leave the highlight area. Can't simply use index, because
138 // that can change quickly if the user clicks at edges of
139 // list. So we use actual pixel distance.
140 var highlightDist = 0;
141 var realY = y - userList.contentY;
143 realY += belowOffset;
144 if (realY + height <= highlightItem.y)
145 highlightDist = realY + height - highlightItem.y;
146 else if (realY >= highlightItem.y + root.highlightedHeight)
147 highlightDist = realY - highlightItem.y - root.highlightedHeight;
150 return 1 - Math.min(1, (Math.abs(highlightDist) + root.cellHeight) / ((root.numAboveBelow + 1) * root.cellHeight))
155// visible: userList.count != 1 // HACK Hide username label until someone sorts out the anchoring with the keyboard-dismiss animation, Work around https://github.com/ubports/unity8/issues/185
158 leftMargin: units.gu(2)
159 rightMargin: units.gu(2)
160 horizontalCenter: parent.horizontalCenter
162 // Add an offset to bottomMargin for any items below the highlight
163 bottomMargin: -(units.gu(4) + (parent.belowHighlight ? parent.belowOffset : parent.aboveCurrent ? -units.gu(5) : 0))
168 anchors.verticalCenter: parent.verticalCenter
169 color: theme.palette.normal.raised
170 visible: userList.count > 1 && loggedIn
171 height: visible ? units.gu(0.5) : 0
178 height: userList.currentIndex === index ? units.gu(4.5) : units.gu(3)
180 color: theme.palette.normal.raisedSecondaryText
181 anchors.verticalCenter: parent.verticalCenter
185 anchors.verticalCenter: parent.verticalCenter
186 spacing: units.gu(0.25)
189 objectName: "username" + index
191 text: userList.currentIndex === index
193 && LightDMService.greeter.authenticationUser !== ""
194 ? LightDMService.greeter.authenticationUser : realName
195 color: userList.currentIndex !== index ? theme.palette.normal.raised
196 : theme.palette.normal.raisedSecondaryText
197 font.weight: userList.currentIndex === index ? Font.Normal : Font.Light
198 font.pointSize: units.gu(2)
200 width: highlightItem.width
201 && contentWidth > highlightItem.width - userIcon.width - units.gu(4)
202 ? highlightItem.width - userIcon.width - units.gu(4)
205 Component.onCompleted: _realName = realName
207 Behavior on anchors.topMargin { NumberAnimation { duration: root.moveDuration; easing.type: Easing.InOutQuad; } }
214 text: root.alphanumeric ? "Login with password" : "Login with pin"
215 color: theme.palette.normal.raisedSecondaryText
216 visible: userList.currentIndex === index && false
217 font.weight: Font.Light
218 font.pointSize: units.gu(1.25)
229 // Add an offset to topMargin for any items below the highlight
230 topMargin: parent.belowHighlight ? parent.belowOffset : parent.aboveCurrent ? -units.gu(5) : 0
232 height: parent.height
233 enabled: userList.currentIndex !== index && parent.opacity > 0
234 onClicked: root.selected(index)
236 Behavior on anchors.topMargin { NumberAnimation { duration: root.moveDuration; easing.type: Easing.InOutQuad; } }
240 // This is needed because ListView.moving is not true if the ListView
241 // moves because of an internal event (e.g. currentIndex has changed)
246 interval: root.moveDuration
252 objectName: "promptList"
254 bottom: highlightItem.bottom
255 horizontalCenter: highlightItem.horizontalCenter
258 width: highlightItem.width - anchors.margins * 2
265 root.selected(currentIndex);
272 root.responded(text);
276 root.selected(currentIndex);
280 target: LightDMService.prompts
281 onModelReset: promptList.interactive = true
285 WrongPasswordAnimation {
286 id: wrongPasswordAnimation
287 objectName: "wrongPasswordAnimation"