@@ -23,6 +23,8 @@ import Ubuntu.Components 1.3
2323import Ubuntu.SystemImage 0.1
2424import Unity.Launcher 0.1
2525import Unity.Session 0.1
26+
27+import "." 0.1
2628import "../Components"
2729
2830Showable {
@@ -48,7 +50,7 @@ Showable {
4850 readonly property bool hasLockedApp: lockedApp !== ""
4951
5052 property bool forcedUnlock
51− readonly property bool locked: lightDM.greeter.active && !lightDM.greeter.authenticated && !forcedUnlock
53+ readonly property bool locked: LightDMService.greeter.active && !LightDMService.greeter.authenticated && !forcedUnlock
5254
5355 property bool tabletMode
5456 property url viewSource // only used for testing
@@ -120,12 +122,12 @@ Showable {
120122 return d.startUnlock(true /* toTheRight */);
121123 }
122124
123− LightDM{id:lightDM} // Provide backend access
124125 QtObject {
125126 id: d
126127
127− readonly property bool multiUser: lightDM.users.count > 1
128− property int currentIndex
128+ readonly property bool multiUser: LightDMService.users.count > 1
129+ readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
130+ property int currentIndex: Math.max(selectUserIndex, 0)
129131 property bool waiting
130132 property bool isLockscreen // true when we are locking an active session, rather than first user login
131133 readonly property bool secureFingerprint: isLockscreen &&
@@ -147,21 +149,37 @@ Showable {
147149 UbuntuNumberAnimation {}
148150 }
149151
152+ function getUserIndex(username) {
153+ if (username === "")
154+ return -1;
155+
156+ // Find index for requested user, if it exists
157+ for (var i = 0; i < LightDMService.users.count; i++) {
158+ if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
159+ return i;
160+ }
161+ }
162+
163+ return -1;
164+ }
165+
150166 function selectUser(uid, reset) {
167+ if (uid < 0)
168+ return;
151169 d.waiting = true;
152170 if (reset) {
153171 loader.item.reset();
154172 }
155173 currentIndex = uid;
156− var user = lightDM.users.data(uid, lightDM.userRoles.NameRole);
174+ var user = LightDMService.users.data(uid, LightDMService.userRoles.NameRole);
157175 AccountsService.user = user;
158176 LauncherModel.setUser(user);
159− lightDM.greeter.authenticate(user); // always resets auth state
177+ LightDMService.greeter.authenticate(user); // always resets auth state
160178 }
161179
162180 function login() {
163181 enabled = false;
164− if (lightDM.greeter.startSessionSync()) {
182+ if (LightDMService.greeter.startSessionSync()) {
165183 sessionStarted();
166184 if (loader.item) {
167185 loader.item.notifyAuthenticationSucceeded(false /* showFakePassword */);
@@ -307,7 +325,7 @@ Showable {
307325 root.lockedApp = "";
308326 root.forceActiveFocus();
309327 d.selectUser(d.currentIndex, true);
310− lightDM.infographic.readyForDataChange();
328+ LightDMService.infographic.readyForDataChange();
311329 }
312330
313331 Connections {
@@ -315,13 +333,12 @@ Showable {
315333 onSelected: {
316334 d.selectUser(index, true);
317335 }
336+ onPromptlessLogin: d.login();
318337 onResponded: {
319338 if (root.locked) {
320− lightDM.greeter.respond(response);
339+ LightDMService.greeter.respond(response);
321340 } else {
322− if (lightDM.greeter.active && !lightDM.greeter.authenticated) { // could happen if forcedUnlock
323− d.login();
324− }
341+ d.login();
325342 loader.item.hide();
326343 }
327344 }
@@ -385,18 +402,18 @@ Showable {
385402 Binding {
386403 target: loader.item
387404 property: "userModel"
388− value: lightDM.users
405+ value: LightDMService.users
389406 }
390407
391408 Binding {
392409 target: loader.item
393410 property: "infographicModel"
394− value: lightDM.infographic
411+ value: LightDMService.infographic
395412 }
396413 }
397414
398415 Connections {
399− target: lightDM.greeter
416+ target: LightDMService.greeter
400417
401418 onShowGreeter: root.forceShow()
402419
@@ -431,13 +448,13 @@ Showable {
431448 onAuthenticationComplete: {
432449 d.waiting = false;
433450
434− if (lightDM.greeter.authenticated) {
435− d.login();
436− if (!lightDM.greeter.promptless) {
451+ if (LightDMService.greeter.authenticated) {
452+ if (!LightDMService.greeter.promptless) {
453+ d.login();
437454 loader.item.hide();
438455 }
439456 } else {
440− if (!lightDM.greeter.promptless) {
457+ if (!LightDMService.greeter.promptless) {
441458 AccountsService.failedLogins++;
442459 }
443460
@@ -458,21 +475,13 @@ Showable {
458475 }
459476
460477 loader.item.notifyAuthenticationFailed();
461− if (!lightDM.greeter.promptless) {
478+ if (!LightDMService.greeter.promptless) {
462479 d.selectUser(d.currentIndex, false);
463480 }
464481 }
465482 }
466483
467− onRequestAuthenticationUser: {
468− // Find index for requested user, if it exists
469− for (var i = 0; i < lightDM.users.count; i++) {
470− if (user === lightDM.users.data(i, lightDM.userRoles.NameRole)) {
471− d.selectUser(i, true);
472− return;
473− }
474− }
475− }
484+ onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user), true)
476485 }
477486
478487 Connections {
@@ -485,20 +494,20 @@ Showable {
485494 }
486495
487496 Binding {
488− target: lightDM.greeter
497+ target: LightDMService.greeter
489498 property: "active"
490499 value: root.active
491500 }
492501
493502 Binding {
494− target: lightDM.infographic
503+ target: LightDMService.infographic
495504 property: "username"
496− value: AccountsService.statsWelcomeScreen ? lightDM.users.data(d.currentIndex, lightDM.userRoles.NameRole) : ""
505+ value: AccountsService.statsWelcomeScreen ? LightDMService.users.data(d.currentIndex, LightDMService.userRoles.NameRole) : ""
497506 }
498507
499508 Connections {
500509 target: i18n
501− onLanguageChanged: lightDM.infographic.readyForDataChange()
510+ onLanguageChanged: LightDMService.infographic.readyForDataChange()
502511 }
503512
504513 Observer {
@@ -550,7 +559,7 @@ Showable {
550559 failOperation("fingerprint reader is locked");
551560 return;
552561 }
553− if (result !== lightDM.users.data(d.currentIndex, lightDM.userRoles.UidRole)) {
562+ if (result !== LightDMService.users.data(d.currentIndex, LightDMService.userRoles.UidRole)) {
554563 AccountsService.failedFingerprintLogins++;
555564 failOperation("not the selected user");
556565 return;