Merge lp:~attente/indicator-keyboard/lightdm-layout-fallback into lp:indicator-keyboard

Proposed by William Hua
Status: Merged
Approved by: Lars Karlitski
Approved revision: 121
Merged at revision: 115
Proposed branch: lp:~attente/indicator-keyboard/lightdm-layout-fallback
Merge into: lp:indicator-keyboard
Diff against target: 162 lines (+80/-22)
2 files modified
lib/main.vala (+79/-21)
po/indicator-keyboard.pot (+1/-1)
To merge this branch: bzr merge lp:~attente/indicator-keyboard/lightdm-layout-fallback
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+186907@code.launchpad.net

Commit message

Fall-back on old unity-greeter keyboard layouts in case migration hasn't occurred.

Description of the change

indicator-keyboard should fall-back on the old unity-greeter keyboard layouts in the case that their layouts haven't yet been migrated into accountsservice (this can potentially happen if they haven't done an upgrade in a long time).

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
120. By William Hua

Always add the default layout.

121. By William Hua

Prevent index out of bounds.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Code looks good to me and is working. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/main.vala'
2--- lib/main.vala 2013-08-29 02:22:25 +0000
3+++ lib/main.vala 2013-09-21 16:21:16 +0000
4@@ -41,6 +41,8 @@
5 private MenuModel? menu_model;
6 private Menu? sources_menu;
7
8+ private uint lightdm_current;
9+
10 [DBus (visible = false)]
11 public Service (ref unowned string[] args) {
12 force = "--force" in args;
13@@ -112,7 +114,9 @@
14 [DBus (visible = false)]
15 private void migrate_keyboard_layouts () {
16 if (is_login_user ()) {
17- Act.UserManager manager = Act.UserManager.get_default ();
18+ lightdm_current = source_settings.get_uint ("current");
19+
20+ var manager = Act.UserManager.get_default ();
21
22 if (manager.is_loaded) {
23 users = manager.list_users ();
24@@ -147,6 +151,15 @@
25 }
26 });
27 }
28+
29+ var user_list = LightDM.UserList.get_instance ();
30+
31+ user_list.user_added.connect ((user) => { migrate_input_sources (); });
32+ user_list.user_changed.connect ((user) => { migrate_input_sources (); });
33+ user_list.user_removed.connect ((user) => { migrate_input_sources (); });
34+
35+ /* Force the loading of the user list. */
36+ user_list.get_user_by_name ("");
37 } else {
38 if (!indicator_settings.get_boolean ("migrated")) {
39 var builder = new VariantBuilder (new VariantType ("a(ss)"));
40@@ -209,12 +222,12 @@
41
42 foreach (var user in users) {
43 if (user.is_loaded) {
44- var sources = user.input_sources;
45- var layouts = user.xkeyboard_layouts;
46+ var done = false;
47
48 VariantIter outer;
49 VariantIter inner;
50
51+ var sources = user.input_sources;
52 sources.get ("aa{ss}", out outer);
53
54 while (outer.next ("a{ss}", out inner)) {
55@@ -223,31 +236,76 @@
56
57 while (inner.next ("{&s&s}", out key, out source)) {
58 if (key == "xkb") {
59- if (!added.contains (source)) {
60- list.add (source);
61- added.add (source);
62- }
63- }
64- }
65- }
66-
67- foreach (var layout in layouts) {
68- var source = layout;
69- source = source.replace (" ", "+");
70- source = source.replace ("\t", "+");
71-
72- if (!added.contains (source)) {
73- list.add (source);
74- added.add (source);
75+ done = true;
76+
77+ if (!added.contains (source)) {
78+ list.add (source);
79+ added.add (source);
80+ }
81+ }
82+ }
83+ }
84+
85+ if (!done) {
86+ var layouts = user.xkeyboard_layouts;
87+ foreach (var layout in layouts) {
88+ done = true;
89+
90+ var source = layout;
91+ source = source.replace (" ", "+");
92+ source = source.replace ("\t", "+");
93+
94+ if (!added.contains (source)) {
95+ list.add (source);
96+ added.add (source);
97+ }
98+ }
99+ }
100+
101+ if (!done) {
102+ var user_list = LightDM.UserList.get_instance ();
103+ LightDM.User? light_user = user_list.get_user_by_name (user.user_name);
104+
105+ if (light_user != null) {
106+ var layouts = ((!) light_user).get_layouts ();
107+ foreach (var layout in layouts) {
108+ done = true;
109+
110+ var source = layout;
111+ source = source.replace (" ", "+");
112+ source = source.replace ("\t", "+");
113+
114+ if (!added.contains (source)) {
115+ list.add (source);
116+ added.add (source);
117+ }
118+ }
119 }
120 }
121 }
122 }
123
124+ var layout = LightDM.get_layout ();
125+
126+ var source = layout.name;
127+ source = source.replace (" ", "+");
128+ source = source.replace ("\t", "+");
129+
130+ if (!added.contains (source)) {
131+ list.add (source);
132+ added.add (source);
133+ }
134+
135 var builder = new VariantBuilder (new VariantType ("a(ss)"));
136
137- foreach (var layout in list) {
138- builder.add ("(ss)", "xkb", layout);
139+ foreach (var name in list) {
140+ builder.add ("(ss)", "xkb", name);
141+ }
142+
143+ if (lightdm_current < list.size) {
144+ source_settings.set_uint ("current", lightdm_current);
145+ } else {
146+ source_settings.set_uint ("current", list.size - 1);
147 }
148
149 source_settings.set_value ("sources", builder.end ());
150
151=== modified file 'po/indicator-keyboard.pot'
152--- po/indicator-keyboard.pot 2013-08-29 02:22:25 +0000
153+++ po/indicator-keyboard.pot 2013-09-21 16:21:16 +0000
154@@ -8,7 +8,7 @@
155 msgstr ""
156 "Project-Id-Version: PACKAGE VERSION\n"
157 "Report-Msgid-Bugs-To: \n"
158-"POT-Creation-Date: 2013-08-29 10:20+0800\n"
159+"POT-Creation-Date: 2013-09-20 20:56-0400\n"
160 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
161 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
162 "Language-Team: LANGUAGE <LL@li.org>\n"

Subscribers

People subscribed via source and target branches

to all changes: