Merge lp:~robert-ancell/unity-greeter/bug-919298 into lp:unity-greeter

Proposed by Robert Ancell
Status: Merged
Merged at revision: 337
Proposed branch: lp:~robert-ancell/unity-greeter/bug-919298
Merge into: lp:unity-greeter
Diff against target: 540 lines (+220/-90)
4 files modified
NEWS (+1/-0)
src/fixes.vapi (+6/-0)
src/unity-greeter.vala (+119/-74)
src/user-list.vala (+94/-16)
To merge this branch: bzr merge lp:~robert-ancell/unity-greeter/bug-919298
Reviewer Review Type Date Requested Status
Michael Terry (community) Needs Fixing
Review via email: mp+96292@code.launchpad.net

Description of the change

Makes sure that the manual entry is shown if there are no user accounts listed. Adds some test behaviour for manipulating the user list - Ctrl++ to add, Ctrl+- to remove, Ctrl+0 to remove all, Ctrl+= to add all. This shows some rendering errors when users are added/removed.

To post a comment you must log in.
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Note I also changed the ordering of the user list to be sorted (otherwise it gets a bit random adding/removing) and changed the name of the long name test users to be clearer.

Revision history for this message
Michael Terry (mterry) wrote :

Sure, seems fine. I can't seem to login with the manual entry in test mode (I enter my name, the label changes to my name, but the prompt for password never comes, so I can't enter a password in the entry). Is that expected?

Aside from that though, approved.

review: Needs Fixing
Revision history for this message
Robert Ancell (robert-ancell) wrote :

That's been broken since I made the patch before this one. I just checked and it doesn't work in revisions, 327, 320, 305 so I think something must have broken in GTK+? I chased down the focus calls and we are calling focus to the entry but it appears it's not getting it for some reason.

Revision history for this message
Robert Ancell (robert-ancell) wrote :

The simpler test is to enter an invalid password and the when it retries we've lost focus.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-02-23 20:26:29 +0000
3+++ NEWS 2012-03-07 04:56:18 +0000
4@@ -1,6 +1,7 @@
5 Overview of changes in unity-greeter 0.2.5
6
7 * Don't allow dragging the window by the top bar
8+ * Show manual entry when no users available
9
10 Overview of changes in unity-greeter 0.2.4
11
12
13=== modified file 'src/fixes.vapi'
14--- src/fixes.vapi 2012-02-09 00:42:44 +0000
15+++ src/fixes.vapi 2012-03-07 04:56:18 +0000
16@@ -25,8 +25,14 @@
17 public const int KEY_KP_Up;
18 public const int KEY_KP_Down;
19 public const int KEY_F10;
20+ public const int KEY_0;
21+ public const int KEY_g;
22+ public const int KEY_G;
23 public const int KEY_s;
24 public const int KEY_h;
25+ public const int KEY_plus;
26+ public const int KEY_minus;
27+ public const int KEY_equal;
28 public const int CONTROL_MASK;
29 }
30
31
32=== modified file 'src/unity-greeter.vala'
33--- src/unity-greeter.vala 2012-03-07 02:41:53 +0000
34+++ src/unity-greeter.vala 2012-03-07 04:56:18 +0000
35@@ -52,6 +52,31 @@
36 /* User to authenticate against */
37 private string ?authenticate_user = null;
38
39+ private const TestEntry[] test_entries =
40+ {
41+ { "has-password", "Has Password", "*", "uk;us", false, false, null },
42+ { "different-prompt", "Different Prompt", "*", "uk;us", false, false, null },
43+ { "no-password", "No Password", "*", "uk;us", false, false, null },
44+ { "change-password", "Change Password", "*", "uk;us", false, false, null },
45+ { "two-factor", "Two Factor", "*", "uk;us", false, false, null },
46+ { "info-prompt", "Info Prompt", "*", "uk;us", false, false, null },
47+ { "long-info-prompt", "Long Info Prompt", "*", "uk;us", false, false, null },
48+ { "multi-info-prompt", "Multi Info Prompt", "*", "uk;us", false, false, null },
49+ { "very-very-long-name", "Long name (far too long to fit)", "*", "uk;us", false, false, null },
50+ { "long-name-and-messages", "Long name and messages", "*", "uk;us", false, true, null },
51+ { "active", "Active Account", "*", "uk;us", true, false, null },
52+ { "has-messages", "Has Messages", "*", "uk;us", false, true, null },
53+ { "gnome", "GNOME", "*", "uk;us", false, false, "gnome-shell" },
54+ { "locked", "Locked Account", "*", "uk;us", false, false, null },
55+ { "color-background", "Color Background", "#dd4814", "uk;us", false, false, null },
56+ { "white-background", "White Background", "#ffffff", "uk;us", false, false, null },
57+ { "black-background", "Black Background", "#000000", "uk;us", false, false, null },
58+ { "no-background", "No Background", null, "uk;us", false, false, null },
59+ { "unicode", "가나다라마", "*", "uk;us", false, false, null },
60+ { "", "", null, null, false, false, null }
61+ };
62+ private List<string> test_backgrounds;
63+ private int n_test_entries = 0;
64 private string? test_username = null;
65 private bool test_prompted_sso = false;
66 private bool test_request_new_password = false;
67@@ -109,7 +134,7 @@
68
69 if (test_mode)
70 {
71- var backgrounds = new List<string> ();
72+ test_backgrounds = new List<string> ();
73 try
74 {
75 var dir = Dir.open ("/usr/share/backgrounds/");
76@@ -118,45 +143,26 @@
77 var bg = dir.read_name ();
78 if (bg == null)
79 break;
80- backgrounds.append ("/usr/share/backgrounds/" + bg);
81+ test_backgrounds.append ("/usr/share/backgrounds/" + bg);
82 }
83 }
84 catch (FileError e)
85 {
86 }
87- var i = 0;
88+
89+ while (add_test_entry ());
90+ user_list.add_entry ("*guest", _("Guest Session"));
91
92- var layout_list = make_layout_list ("uk;us");
93-
94- user_list.add_entry ("has-password", "Has Password", next_background (backgrounds, ref i), layout_list);
95- user_list.add_entry ("different-prompt", "Different Prompt", next_background (backgrounds, ref i), layout_list);
96- user_list.add_entry ("no-password", "No Password", next_background (backgrounds, ref i), layout_list);
97- user_list.add_entry ("change-password", "Change Password", next_background (backgrounds, ref i), layout_list);
98- user_list.add_entry ("two-factor", "Two Factor", next_background (backgrounds, ref i), layout_list);
99- user_list.add_entry ("info-prompt", "Info Prompt", next_background (backgrounds, ref i), layout_list);
100- user_list.add_entry ("long-info-prompt", "Long Info Prompt", next_background (backgrounds, ref i), layout_list);
101- user_list.add_entry ("multi-info-prompt", "Multi Info Prompt", next_background (backgrounds, ref i), layout_list);
102- user_list.add_entry ("very-very-long-name", "User with a very very very long name", next_background (backgrounds, ref i), layout_list);
103- user_list.add_entry ("long-name-and-messages", "User with a long name and messages", next_background (backgrounds, ref i), layout_list, false, true);
104- user_list.add_entry ("active", "Active Account", next_background (backgrounds, ref i), layout_list, true);
105- user_list.add_entry ("has-messages", "Has Messages", next_background (backgrounds, ref i), layout_list, false, true);
106- user_list.add_entry ("gnome", "GNOME", next_background (backgrounds, ref i), layout_list, false, false, "gnome-shell");
107- user_list.add_entry ("locked", "Locked Account", next_background (backgrounds, ref i), layout_list);
108- user_list.add_entry ("color-background", "Color Background", "#dd4814", layout_list);
109- user_list.add_entry ("white-background", "White Background", "#ffffff", layout_list);
110- user_list.add_entry ("black-background", "Black Background", "#000000", layout_list);
111- user_list.add_entry ("no-background", "No Background", null, layout_list);
112- user_list.add_entry ("unicode", "가나다라마", next_background (backgrounds, ref i), layout_list);
113- user_list.add_entry ("*guest", _("Guest Session"), null, null, true);
114+ main_window.key_press_event.connect (key_press_cb);
115
116 if (last_user != null)
117 user_list.set_active_entry (last_user);
118 }
119 else
120 {
121- if (greeter.hide_users_hint)
122- user_list.add_entry ("*other", _("Login"), null, null, false, false, greeter.default_session_hint);
123- else
124+ user_list.default_session = greeter.default_session_hint;
125+
126+ if (!greeter.hide_users_hint)
127 {
128 var users = LightDM.UserList.get_instance ();
129 users.user_added.connect (user_added_cb);
130@@ -169,7 +175,7 @@
131 if (greeter.has_guest_account_hint)
132 {
133 debug ("Adding guest account entry");
134- user_list.add_entry ("*guest", _("Guest Session"), null, null, false, false, greeter.default_session_hint);
135+ user_list.add_entry ("*guest", _("Guest Session"));
136 }
137
138 if (greeter.select_user_hint != null)
139@@ -187,17 +193,66 @@
140 Gdk.threads_add_idle (ready_cb);
141 }
142
143- private string? next_background (List<string> backgrounds, ref int index)
144- {
145- if (backgrounds == null)
146- return null;
147-
148- if (index >= backgrounds.length ())
149- index = 0;
150- var background = backgrounds.nth_data (index);
151- index++;
152-
153- return background;
154+ private bool key_press_cb (Gdk.EventKey event)
155+ {
156+ if ((event.state & Gdk.CONTROL_MASK) == 0)
157+ return false;
158+
159+ if (event.keyval == Gdk.KEY_plus)
160+ add_test_entry ();
161+ if (event.keyval == Gdk.KEY_minus)
162+ remove_test_entry ();
163+ if (event.keyval == Gdk.KEY_0)
164+ {
165+ while (remove_test_entry ());
166+ user_list.remove_entry ("*guest");
167+ }
168+ if (event.keyval == Gdk.KEY_equal)
169+ {
170+ while (add_test_entry ());
171+ user_list.add_entry ("*guest", _("Guest Session"));
172+ }
173+ if (event.keyval == Gdk.KEY_g)
174+ user_list.remove_entry ("*guest");
175+ if (event.keyval == Gdk.KEY_G)
176+ user_list.add_entry ("*guest", _("Guest Session"));
177+
178+ return false;
179+ }
180+
181+ private bool add_test_entry ()
182+ {
183+ var e = test_entries[n_test_entries];
184+ if (e.username == "")
185+ return false;
186+
187+ var background = e.background;
188+ if (background == "*")
189+ {
190+ var background_index = 0;
191+ for (var i = 0; i < n_test_entries; i++)
192+ {
193+ if (test_entries[i].background == "*")
194+ background_index++;
195+ }
196+ if (test_backgrounds.length () > 0)
197+ background = test_backgrounds.nth_data (background_index % test_backgrounds.length ());
198+ }
199+ user_list.add_entry (e.username, e.real_name, background, make_layout_list (e.layouts), e.is_active, e.has_messages, e.session);
200+ n_test_entries++;
201+
202+ return true;
203+ }
204+
205+ private bool remove_test_entry ()
206+ {
207+ if (n_test_entries == 0)
208+ return false;
209+
210+ user_list.remove_entry (test_entries[n_test_entries - 1].username);
211+ n_test_entries--;
212+
213+ return true;
214 }
215
216 public static void add_style_class (Gtk.Widget widget)
217@@ -255,10 +310,6 @@
218 if (user.real_name == "")
219 label = user.name;
220
221- var session = user.session;
222- if (session == null)
223- session = greeter.default_session_hint;
224-
225 var layouts = new List <LightDM.Layout> ();
226 foreach (var name in user.get_layouts ())
227 {
228@@ -267,7 +318,7 @@
229 layouts.append (layout);
230 }
231
232- user_list.add_entry (user.name, label, user.background, layouts, user.logged_in, user.has_messages, session);
233+ user_list.add_entry (user.name, label, user.background, layouts, user.logged_in, user.has_messages, user.session);
234 }
235
236 private void user_removed_cb (LightDM.User user)
237@@ -290,7 +341,14 @@
238
239 private void show_prompt_cb (string text, LightDM.PromptType type)
240 {
241- update_other_label ();
242+ /* Notify the greeter on what user has been logged */
243+ if (user_list.selected == "*other" && user_list.manual_username == null)
244+ {
245+ if (test_mode)
246+ user_list.manual_username = test_username;
247+ else
248+ user_list.manual_username = greeter.authentication_user;
249+ }
250
251 prompted = true;
252 if (text == "Password: ")
253@@ -329,8 +387,6 @@
254
255 private void authentication_complete_cb ()
256 {
257- update_other_label ();
258-
259 bool is_authenticated;
260 if (test_mode)
261 is_authenticated = test_is_authenticated;
262@@ -389,30 +445,13 @@
263 start_authentication ();
264 }
265
266- private void update_other_label ()
267- {
268- if (!greeter.hide_users_hint)
269- return;
270-
271- var text = _("Other...");
272- if (test_mode)
273- {
274- if (user_list.selected == "*other" && test_username != null)
275- text = test_username;
276- }
277- else
278- {
279- if (user_list.selected == "*other" && greeter.authentication_user != null)
280- text = greeter.authentication_user;
281- }
282-
283- user_list.add_entry ("*other", text, null, null, false, false, greeter.default_session_hint);
284- }
285-
286 private void start_authentication ()
287 {
288 prompted = false;
289
290+ /* Reset manual username */
291+ user_list.manual_username = null;
292+
293 if (test_mode)
294 {
295 test_username = null;
296@@ -472,17 +511,12 @@
297 else
298 {
299 if (user_list.selected == "*other")
300- {
301- greeter.authenticate (authenticate_user);
302- authenticate_user = null;
303- }
304+ greeter.authenticate ();
305 else if (user_list.selected == "*guest")
306 greeter.authenticate_as_guest ();
307 else
308 greeter.authenticate (user_list.selected);
309 }
310-
311- update_other_label ();
312 }
313
314 private void respond_to_prompt_cb (string text)
315@@ -792,3 +826,14 @@
316 return Posix.EXIT_SUCCESS;
317 }
318 }
319+
320+private struct TestEntry
321+{
322+ string username;
323+ string real_name;
324+ string? background;
325+ string? layouts;
326+ bool is_active;
327+ bool has_messages;
328+ string? session;
329+}
330
331=== modified file 'src/user-list.vala'
332--- src/user-list.vala 2012-03-05 05:12:26 +0000
333+++ src/user-list.vala 2012-03-07 04:56:18 +0000
334@@ -121,8 +121,34 @@
335 {
336 get { if (selected_entry == null) return null; return selected_entry.name; }
337 }
338+
339+ private string? _manual_username = null;
340+ public string? manual_username
341+ {
342+ get { return _manual_username; }
343+ set
344+ {
345+ _manual_username = value;
346+ if (find_entry ("*other") != null)
347+ add_manual_entry ();
348+ }
349+ }
350+
351+ public string default_session = "ubuntu";
352
353- public string? session {get; private set;}
354+ private string? _session = null;
355+ public string? session
356+ {
357+ get
358+ {
359+ return _session;
360+ }
361+ set
362+ {
363+ _session = value;
364+ session_image.set_from_pixbuf (get_badge ());
365+ }
366+ }
367
368 private Gdk.Pixbuf? last_session_badge = null;
369
370@@ -169,7 +195,7 @@
371 session_button = new Gtk.Button ();
372 session_button.focus_on_click = false;
373 session_button.get_accessible ().set_name (_("Session Options"));
374- session_image = new Gtk.Image.from_pixbuf (SessionChooser.get_badge (session));
375+ session_image = new Gtk.Image.from_pixbuf (get_badge ());
376 session_image.show ();
377 session_button.relief = Gtk.ReliefStyle.NONE;
378 session_button.add (session_image);
379@@ -333,31 +359,76 @@
380 return null;
381 }
382
383- public void add_entry (string name, string label, string? background, List <LightDM.Layout>? keyboard_layouts, bool is_active = false, bool has_messages = false, string? session = null)
384+ public void add_entry (string name, string label, string? background = null, List <LightDM.Layout>? keyboard_layouts = null, bool is_active = false, bool has_messages = false, string? session = null)
385 {
386 var e = find_entry (name);
387 if (e == null)
388 {
389 e = new UserEntry ();
390- entries.append (e);
391 e.name = name;
392 }
393+ else
394+ entries.remove (e);
395 e.layout = create_pango_layout (label);
396 e.layout.set_font_description (Pango.FontDescription.from_string ("Ubuntu 16"));
397 e.background = background;
398 e.keyboard_layouts = keyboard_layouts.copy ();
399 e.is_active = is_active;
400 e.has_messages = has_messages;
401- e.session = (session == null) ? "ubuntu" : session;
402+ e.session = session;
403+ entries.insert_sorted (e, compare_entry);
404
405 if (selected_entry == null)
406 select_entry (e, 1.0);
407 else
408 select_entry (selected_entry, 1.0);
409
410+ /* Remove manual option when have users */
411+ if (have_users ())
412+ remove_entry ("*other");
413+
414 redraw_user_list ();
415 }
416
417+ private static int compare_entry (UserEntry a, UserEntry b)
418+ {
419+ if (a.name.has_prefix ("*") || b.name.has_prefix ("*"))
420+ {
421+ /* Special entries go after normal ones */
422+ if (!a.name.has_prefix ("*"))
423+ return -1;
424+ if (!b.name.has_prefix ("*"))
425+ return 1;
426+
427+ /* Manual comes before guest */
428+ if (a.name == "*other")
429+ return -1;
430+ if (a.name == "*guest")
431+ return 1;
432+ }
433+
434+ /* Alphabetical by label */
435+ return a.layout.get_text ().ascii_casecmp (b.layout.get_text ());
436+ }
437+
438+ private bool have_users ()
439+ {
440+ foreach (var e in entries)
441+ {
442+ if (!e.name.has_prefix ("*"))
443+ return true;
444+ }
445+ return false;
446+ }
447+
448+ private void add_manual_entry ()
449+ {
450+ var text = manual_username;
451+ if (text == null)
452+ text = _("Login");
453+ add_entry ("*other", text);
454+ }
455+
456 public void set_active_entry (string ?name)
457 {
458 var e = find_entry (name);
459@@ -374,6 +445,11 @@
460 var index = entries.index (entry);
461 entries.remove (entry);
462
463+ /* Show a manual login if no users */
464+ if (!have_users ())
465+ add_manual_entry ();
466+
467+ /* Select previous entry if the selected one was removed */
468 if (entry == selected_entry)
469 {
470 if (index >= entries.length ())
471@@ -404,12 +480,6 @@
472 scroll_timer.reset (AnimateTimer.INSTANT);
473 }
474
475- private void change_session (string session)
476- {
477- this.session = session;
478- session_image.set_from_pixbuf (SessionChooser.get_badge (session));
479- }
480-
481 private void session_clicked_cb (string? session)
482 {
483 return_if_fail (mode == Mode.SESSIONS);
484@@ -418,7 +488,7 @@
485 session_chooser.fade_out ();
486
487 if (session != null)
488- change_session (session);
489+ this.session = session;
490 }
491
492 private void session_fade_done_cb ()
493@@ -546,13 +616,13 @@
494
495 private void select_entry (UserEntry entry, double direction)
496 {
497- last_session_badge = SessionChooser.get_badge (session);
498+ last_session_badge = get_badge ();
499
500 if (!get_realized ())
501 {
502 /* Just note it for the future if we haven't been realized yet */
503 selected_entry = entry;
504- change_session (entry.session);
505+ session = entry.session;
506 return;
507 }
508
509@@ -600,13 +670,21 @@
510 if (selected_entry != entry)
511 {
512 selected_entry = entry;
513- change_session (entry.session);
514+ session = entry.session;
515 user_selected (selected_entry.name);
516
517 if (mode == Mode.LOGIN)
518 user_displayed (); /* didn't need to move, make sure we trigger side effects */
519 }
520 }
521+
522+ private Gdk.Pixbuf? get_badge ()
523+ {
524+ if (session == null)
525+ return SessionChooser.get_badge (default_session);
526+ else
527+ return SessionChooser.get_badge (session);
528+ }
529
530 public override void realize ()
531 {
532@@ -839,7 +917,7 @@
533
534 var badge = last_session_badge;
535 if (entry == selected_entry)
536- badge = SessionChooser.get_badge (session);
537+ badge = get_badge ();
538
539 if (position <= 0) /* top of box, normal pace */
540 draw_entry_at_position (c, entry, position, true, badge);

Subscribers

People subscribed via source and target branches