@@ -21,6 +21,8 @@ import Ubuntu.Components 1.3
2121import Ubuntu.SystemImage 0.1
2222import Unity.Launcher 0.1
2323import Unity.Session 0.1
24+
25+import "." 0.1
2426import "../Components"
2527
2628Showable {
@@ -44,7 +46,7 @@ Showable {
4446 readonly property bool hasLockedApp: lockedApp !== ""
4547
4648 property bool forcedUnlock
47− readonly property bool locked: lightDM.greeter.active && !lightDM.greeter.authenticated && !forcedUnlock
49+ readonly property bool locked: LightDMService.greeter.active && !LightDMService.greeter.authenticated && !forcedUnlock
4850
4951 property bool tabletMode
5052 property url viewSource // only used for testing
@@ -112,12 +114,12 @@ Showable {
112114 return d.startUnlock(true /* toTheRight */);
113115 }
114116
115− LightDM{id:lightDM} // Provide backend access
116117 QtObject {
117118 id: d
118119
119− readonly property bool multiUser: lightDM.users.count > 1
120− property int currentIndex
120+ readonly property bool multiUser: LightDMService.users.count > 1
121+ readonly property int selectUserIndex: d.getUserIndex(LightDMService.greeter.selectUser)
122+ property int currentIndex: Math.max(selectUserIndex, 0)
121123 property bool waiting
122124
123125 // We want 'launcherOffset' to animate down to zero. But not to animate
@@ -134,21 +136,37 @@ Showable {
134136 UbuntuNumberAnimation {}
135137 }
136138
139+ function getUserIndex(username) {
140+ if (username === "")
141+ return -1;
142+
143+ // Find index for requested user, if it exists
144+ for (var i = 0; i < LightDMService.users.count; i++) {
145+ if (username === LightDMService.users.data(i, LightDMService.userRoles.NameRole)) {
146+ return i;
147+ }
148+ }
149+
150+ return -1;
151+ }
152+
137153 function selectUser(uid, reset) {
154+ if (uid < 0)
155+ return;
138156 d.waiting = true;
139157 if (reset) {
140158 loader.item.reset();
141159 }
142160 currentIndex = uid;
143− var user = lightDM.users.data(uid, lightDM.userRoles.NameRole);
161+ var user = LightDMService.users.data(uid, LightDMService.userRoles.NameRole);
144162 AccountsService.user = user;
145163 LauncherModel.setUser(user);
146− lightDM.greeter.authenticate(user); // always resets auth state
164+ LightDMService.greeter.authenticate(user); // always resets auth state
147165 }
148166
149167 function login() {
150168 enabled = false;
151− if (lightDM.greeter.startSessionSync()) {
169+ if (LightDMService.greeter.startSessionSync()) {
152170 sessionStarted();
153171 if (loader.item) {
154172 loader.item.notifyAuthenticationSucceeded();
@@ -283,7 +301,7 @@ Showable {
283301 root.lockedApp = "";
284302 root.forceActiveFocus();
285303 d.selectUser(d.currentIndex, true);
286− lightDM.infographic.readyForDataChange();
304+ LightDMService.infographic.readyForDataChange();
287305 }
288306
289307 Connections {
@@ -291,13 +309,12 @@ Showable {
291309 onSelected: {
292310 d.selectUser(index, true);
293311 }
312+ onPromptlessLogin: d.login();
294313 onResponded: {
295314 if (root.locked) {
296− lightDM.greeter.respond(response);
315+ LightDMService.greeter.respond(response);
297316 } else {
298− if (lightDM.greeter.active && !lightDM.greeter.authenticated) { // could happen if forcedUnlock
299− d.login();
300− }
317+ d.login();
301318 loader.item.hide();
302319 }
303320 }
@@ -361,18 +378,18 @@ Showable {
361378 Binding {
362379 target: loader.item
363380 property: "userModel"
364− value: lightDM.users
381+ value: LightDMService.users
365382 }
366383
367384 Binding {
368385 target: loader.item
369386 property: "infographicModel"
370− value: lightDM.infographic
387+ value: LightDMService.infographic
371388 }
372389 }
373390
374391 Connections {
375− target: lightDM.greeter
392+ target: LightDMService.greeter
376393
377394 onShowGreeter: root.forceShow()
378395
@@ -407,14 +424,14 @@ Showable {
407424 onAuthenticationComplete: {
408425 d.waiting = false;
409426
410− if (lightDM.greeter.authenticated) {
427+ if (LightDMService.greeter.authenticated) {
411428 AccountsService.failedLogins = 0;
412− d.login();
413− if (!lightDM.greeter.promptless) {
429+ if (!LightDMService.greeter.promptless) {
430+ d.login();
414431 loader.item.hide();
415432 }
416433 } else {
417− if (!lightDM.greeter.promptless) {
434+ if (!LightDMService.greeter.promptless) {
418435 AccountsService.failedLogins++;
419436 }
420437
@@ -435,21 +452,13 @@ Showable {
435452 }
436453
437454 loader.item.notifyAuthenticationFailed();
438− if (!lightDM.greeter.promptless) {
455+ if (!LightDMService.greeter.promptless) {
439456 d.selectUser(d.currentIndex, false);
440457 }
441458 }
442459 }
443460
444− onRequestAuthenticationUser: {
445− // Find index for requested user, if it exists
446− for (var i = 0; i < lightDM.users.count; i++) {
447− if (user === lightDM.users.data(i, lightDM.userRoles.NameRole)) {
448− d.selectUser(i, true);
449− return;
450− }
451− }
452− }
461+ onRequestAuthenticationUser: d.selectUser(d.getUserIndex(user), true)
453462 }
454463
455464 Connections {
@@ -459,19 +468,19 @@ Showable {
459468 }
460469
461470 Binding {
462− target: lightDM.greeter
471+ target: LightDMService.greeter
463472 property: "active"
464473 value: root.active
465474 }
466475
467476 Binding {
468− target: lightDM.infographic
477+ target: LightDMService.infographic
469478 property: "username"
470− value: AccountsService.statsWelcomeScreen ? lightDM.users.data(d.currentIndex, lightDM.userRoles.NameRole) : ""
479+ value: AccountsService.statsWelcomeScreen ? LightDMService.users.data(d.currentIndex, LightDMService.userRoles.NameRole) : ""
471480 }
472481
473482 Connections {
474483 target: i18n
475− onLanguageChanged: lightDM.infographic.readyForDataChange()
484+ onLanguageChanged: LightDMService.infographic.readyForDataChange()
476485 }
477486}