Merge lp:~teemperor/switchboard-plug-keyboard/fix-layouts into lp:~elementary-pantheon/switchboard-plug-keyboard/trunk
- fix-layouts
- Merge into trunk
Proposed by
Raphael Isemann
Status: | Merged | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Corentin Noël | ||||||||||||||||
Approved revision: | 207 | ||||||||||||||||
Merged at revision: | 206 | ||||||||||||||||
Proposed branch: | lp:~teemperor/switchboard-plug-keyboard/fix-layouts | ||||||||||||||||
Merge into: | lp:~elementary-pantheon/switchboard-plug-keyboard/trunk | ||||||||||||||||
Diff against target: |
1315 lines (+635/-485) 6 files modified
src/Pages/Layout/add_layout.vala (+2/-2) src/Pages/Layout/display.vala (+205/-224) src/Pages/Layout/handler.vala (+33/-34) src/Pages/Layout/settings.vala (+370/-154) src/Pages/layout.vala (+15/-51) src/keyboard.vala (+10/-20) |
||||||||||||||||
To merge this branch: | bzr merge lp:~teemperor/switchboard-plug-keyboard/fix-layouts | ||||||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
ilian (community) | Approve | ||
Corentin Noël | Approve | ||
Review via email: mp+230324@code.launchpad.net |
Commit message
Fix the layout panel
Description of the change
Ok, we merge that or we get just flooded with bug-reports as the plug currently doesn't work at all.
To post a comment you must log in.
Revision history for this message
ilian (9-ilian) wrote : | # |
I`ve tryed to disable or fully remove Ibus, changing stuff in 'desktop.
Also edited "org.gnome.
Same with "org.gnome.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/Pages/Layout/add_layout.vala' | |||
2 | --- src/Pages/Layout/add_layout.vala 2014-01-06 17:12:27 +0000 | |||
3 | +++ src/Pages/Layout/add_layout.vala 2014-08-11 14:54:46 +0000 | |||
4 | @@ -1,7 +1,7 @@ | |||
6 | 1 | namespace Pantheon.Keyboard.Layout | 1 | namespace Pantheon.Keyboard.LayoutPage |
7 | 2 | { | 2 | { |
8 | 3 | // pop over widget to add a new keyboard layout | 3 | // pop over widget to add a new keyboard layout |
10 | 4 | class AddLayout : Gtk.Dialog//Granite.Widgets.PopOver | 4 | class AddLayout : Gtk.Dialog |
11 | 5 | { | 5 | { |
12 | 6 | public signal void layout_added (int language, int layout = 0); | 6 | public signal void layout_added (int language, int layout = 0); |
13 | 7 | 7 | ||
14 | 8 | 8 | ||
15 | === modified file 'src/Pages/Layout/display.vala' | |||
16 | --- src/Pages/Layout/display.vala 2014-01-06 17:12:27 +0000 | |||
17 | +++ src/Pages/Layout/display.vala 2014-08-11 14:54:46 +0000 | |||
18 | @@ -1,226 +1,207 @@ | |||
20 | 1 | namespace Pantheon.Keyboard.Layout | 1 | namespace Pantheon.Keyboard.LayoutPage |
21 | 2 | { | 2 | { |
245 | 3 | // widget to display/add/remove/move keyboard layouts | 3 | // widget to display/add/remove/move keyboard layouts |
246 | 4 | // interacts with class SettingsLayout | 4 | class Display : Gtk.Grid |
247 | 5 | class Display : Gtk.Grid | 5 | { |
248 | 6 | { | 6 | |
249 | 7 | private signal void update_buttons (); | 7 | LayoutSettings settings; |
250 | 8 | 8 | Gtk.TreeView tree; | |
251 | 9 | private SettingsLayouts settings; | 9 | Gtk.ToolButton up_button; |
252 | 10 | private Gtk.TreeView tree; | 10 | Gtk.ToolButton down_button; |
253 | 11 | 11 | Gtk.ToolButton add_button; | |
254 | 12 | public Display () | 12 | Gtk.ToolButton remove_button; |
255 | 13 | { | 13 | |
256 | 14 | settings = new SettingsLayouts (); | 14 | /* |
257 | 15 | var list = make_list_store (); | 15 | * Set to true when the user has just clicked on the list to prevent |
258 | 16 | tree = new Gtk.TreeView.with_model (list); | 16 | * that settings.layouts.active_changed triggers update_cursor |
259 | 17 | var cell = new Gtk.CellRendererText (); | 17 | */ |
260 | 18 | 18 | bool cursor_changing = false; | |
261 | 19 | tree.insert_column_with_attributes (-1, null, cell, "text", 0); | 19 | |
262 | 20 | tree.headers_visible = false; | 20 | public Display () |
263 | 21 | tree.expand = true; | 21 | { |
264 | 22 | 22 | settings = LayoutSettings.get_instance (); | |
265 | 23 | var scroll = new Gtk.ScrolledWindow(null, null); | 23 | |
266 | 24 | scroll.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC; | 24 | tree = new Gtk.TreeView (); |
267 | 25 | scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; | 25 | var cell = new Gtk.CellRendererText (); |
268 | 26 | scroll.shadow_type = Gtk.ShadowType.IN; | 26 | |
269 | 27 | scroll.add(tree); | 27 | tree.insert_column_with_attributes (-1, null, cell, "text", 0); |
270 | 28 | scroll.expand = true; | 28 | tree.headers_visible = false; |
271 | 29 | 29 | tree.expand = true; | |
272 | 30 | var tbar = new Gtk.Toolbar(); | 30 | rebuild_list (); |
273 | 31 | tbar.set_style(Gtk.ToolbarStyle.ICONS); | 31 | |
274 | 32 | tbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR); | 32 | var scroll = new Gtk.ScrolledWindow(null, null); |
275 | 33 | tbar.set_show_arrow(false); | 33 | scroll.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC; |
276 | 34 | tbar.hexpand = true; | 34 | scroll.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC; |
277 | 35 | 35 | scroll.shadow_type = Gtk.ShadowType.IN; | |
278 | 36 | scroll.get_style_context().set_junction_sides(Gtk.JunctionSides.BOTTOM); | 36 | scroll.add (tree); |
279 | 37 | tbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR); | 37 | scroll.expand = true; |
280 | 38 | tbar.get_style_context().set_junction_sides(Gtk.JunctionSides.TOP); | 38 | |
281 | 39 | 39 | var tbar = new Gtk.Toolbar(); | |
282 | 40 | var add_button = new Gtk.ToolButton (null, _("Add…")); | 40 | tbar.set_style(Gtk.ToolbarStyle.ICONS); |
283 | 41 | var remove_button = new Gtk.ToolButton (null, _("Remove")); | 41 | tbar.set_icon_size(Gtk.IconSize.SMALL_TOOLBAR); |
284 | 42 | var up_button = new Gtk.ToolButton (null, _("Move up")); | 42 | tbar.set_show_arrow(false); |
285 | 43 | var down_button = new Gtk.ToolButton (null, _("Move down")); | 43 | tbar.hexpand = true; |
286 | 44 | 44 | ||
287 | 45 | add_button.set_tooltip_text (_("Add…")); | 45 | scroll.get_style_context().set_junction_sides(Gtk.JunctionSides.BOTTOM); |
288 | 46 | remove_button.set_tooltip_text (_("Remove")); | 46 | tbar.get_style_context().add_class(Gtk.STYLE_CLASS_INLINE_TOOLBAR); |
289 | 47 | up_button.set_tooltip_text (_("Move up")); | 47 | tbar.get_style_context().set_junction_sides(Gtk.JunctionSides.TOP); |
290 | 48 | down_button.set_tooltip_text (_("Move down")); | 48 | |
291 | 49 | 49 | add_button = new Gtk.ToolButton (null, _("Add…")); | |
292 | 50 | add_button.set_icon_name ("list-add-symbolic"); | 50 | remove_button = new Gtk.ToolButton (null, _("Remove")); |
293 | 51 | remove_button.set_icon_name ("list-remove-symbolic"); | 51 | up_button = new Gtk.ToolButton (null, _("Move up")); |
294 | 52 | up_button.set_icon_name ("go-up-symbolic"); | 52 | down_button = new Gtk.ToolButton (null, _("Move down")); |
295 | 53 | down_button.set_icon_name ("go-down-symbolic"); | 53 | |
296 | 54 | 54 | add_button.set_tooltip_text (_("Add…")); | |
297 | 55 | remove_button.sensitive = false; | 55 | remove_button.set_tooltip_text (_("Remove")); |
298 | 56 | up_button.sensitive = false; | 56 | up_button.set_tooltip_text (_("Move up")); |
299 | 57 | down_button.sensitive = false; | 57 | down_button.set_tooltip_text (_("Move down")); |
300 | 58 | 58 | ||
301 | 59 | tbar.insert (add_button, -1); | 59 | add_button.set_icon_name ("list-add-symbolic"); |
302 | 60 | tbar.insert (remove_button, -1); | 60 | remove_button.set_icon_name ("list-remove-symbolic"); |
303 | 61 | tbar.insert (up_button, -1); | 61 | up_button.set_icon_name ("go-up-symbolic"); |
304 | 62 | tbar.insert (down_button, -1); | 62 | down_button.set_icon_name ("go-down-symbolic"); |
305 | 63 | 63 | ||
306 | 64 | this.attach (scroll, 0, 0, 1, 1); | 64 | remove_button.sensitive = false; |
307 | 65 | this.attach (tbar, 0, 1, 1, 1); | 65 | up_button.sensitive = false; |
308 | 66 | 66 | down_button.sensitive = false; | |
309 | 67 | var pop = new AddLayout (); | 67 | |
310 | 68 | 68 | tbar.insert (add_button, -1); | |
311 | 69 | add_button.clicked.connect( () => { | 69 | tbar.insert (remove_button, -1); |
312 | 70 | // uncomment when reverting to popover | 70 | tbar.insert (up_button, -1); |
313 | 71 | //pop.move_to_widget (add_button); | 71 | tbar.insert (down_button, -1); |
314 | 72 | // and remove this line | 72 | |
315 | 73 | pop.show_all (); | 73 | this.attach (scroll, 0, 0, 1, 1); |
316 | 74 | add_item (tree, pop); | 74 | this.attach (tbar, 0, 1, 1, 1); |
317 | 75 | } ); | 75 | |
318 | 76 | 76 | var pop = new AddLayout (); | |
319 | 77 | remove_button.clicked.connect( () => { | 77 | |
320 | 78 | remove_item (tree); | 78 | add_button.clicked.connect( () => { |
321 | 79 | update_buttons (); | 79 | // uncomment when reverting to popover |
322 | 80 | } ); | 80 | //pop.move_to_widget (add_button); |
323 | 81 | 81 | // and remove this line | |
324 | 82 | up_button.clicked.connect (() => { | 82 | pop.show_all (); |
325 | 83 | move_item (tree, 0); | 83 | add_item (pop); |
326 | 84 | update_buttons (); | 84 | }); |
327 | 85 | } ); | 85 | |
328 | 86 | 86 | remove_button.clicked.connect( () => { | |
329 | 87 | down_button.clicked.connect (() => { | 87 | remove_item (); |
330 | 88 | move_item (tree, 1); | 88 | }); |
331 | 89 | update_buttons (); | 89 | |
332 | 90 | } ); | 90 | up_button.clicked.connect (() => { |
333 | 91 | 91 | settings.layouts.move_active_layout_up (); | |
334 | 92 | tree.cursor_changed.connect (() => { | 92 | rebuild_list (); |
335 | 93 | update_buttons (); | 93 | }); |
336 | 94 | } ); | 94 | |
337 | 95 | 95 | down_button.clicked.connect (() => { | |
338 | 96 | this.update_buttons.connect (() => | 96 | settings.layouts.move_active_layout_down (); |
339 | 97 | { | 97 | rebuild_list (); |
340 | 98 | Gtk.TreePath path; | 98 | }); |
341 | 99 | 99 | ||
342 | 100 | tree.get_cursor (out path, null); | 100 | tree.cursor_changed.connect (() => { |
343 | 101 | 101 | cursor_changing = true; | |
344 | 102 | if (path == null) | 102 | int new_index = get_cursor_index (); |
345 | 103 | { | 103 | if (new_index != -1) { |
346 | 104 | up_button.sensitive = false; | 104 | settings.layouts.active = new_index; |
347 | 105 | down_button.sensitive = false; | 105 | } |
348 | 106 | remove_button.sensitive = false; | 106 | update_buttons (); |
349 | 107 | return; | 107 | |
350 | 108 | } | 108 | cursor_changing = false; |
351 | 109 | 109 | }); | |
352 | 110 | int index = (path.get_indices ())[0]; | 110 | |
353 | 111 | int count = settings.layouts.length - 1; | 111 | settings.layouts.active_changed.connect (() => { |
354 | 112 | 112 | if (cursor_changing) | |
355 | 113 | up_button.sensitive = (index != 0); | 113 | return; |
356 | 114 | down_button.sensitive = (index != count); | 114 | update_cursor (); |
357 | 115 | remove_button.sensitive = (count > 0); | 115 | }); |
358 | 116 | } ); | 116 | update_cursor (); |
359 | 117 | } | 117 | } |
360 | 118 | 118 | ||
361 | 119 | private Gtk.ListStore make_list_store () | 119 | public void reset_all () |
362 | 120 | { | 120 | { |
363 | 121 | Gtk.ListStore list_store = new Gtk.ListStore (3, typeof (string), typeof(uint), typeof(uint)); | 121 | settings.reset_all (); |
364 | 122 | Gtk.TreeIter iter; | 122 | rebuild_list (); |
365 | 123 | 123 | } | |
366 | 124 | uint layout = 0, variant = 0; | 124 | |
367 | 125 | 125 | void update_buttons () { | |
368 | 126 | foreach (string item in settings.layouts) | 126 | int index = get_cursor_index (); |
369 | 127 | { | 127 | |
370 | 128 | handler.from_code (item, out layout, out variant); | 128 | // if empty list |
371 | 129 | item = handler.get_name (layout, variant); | 129 | if (index == -1) |
372 | 130 | 130 | { | |
373 | 131 | list_store.append (out iter); | 131 | up_button.sensitive = false; |
374 | 132 | list_store.set (iter, 0, item); | 132 | down_button.sensitive = false; |
375 | 133 | list_store.set (iter, 1, layout); | 133 | remove_button.sensitive = false; |
376 | 134 | list_store.set (iter, 2, variant); | 134 | } else { |
377 | 135 | } | 135 | up_button.sensitive = (index != 0); |
378 | 136 | 136 | down_button.sensitive = (index != settings.layouts.length - 1); | |
379 | 137 | return list_store; | 137 | remove_button.sensitive = (settings.layouts.length > 0); |
380 | 138 | } | 138 | } |
381 | 139 | 139 | } | |
382 | 140 | public void reset_all () | 140 | |
383 | 141 | { | 141 | /** |
384 | 142 | settings.reset_all (); | 142 | * Returns the index of the selected layout in the UI. |
385 | 143 | tree.model = make_list_store (); | 143 | * In case the list contains no layouts, it returns -1. |
386 | 144 | update_buttons (); | 144 | */ |
387 | 145 | } | 145 | int get_cursor_index () { |
388 | 146 | 146 | Gtk.TreePath path; | |
389 | 147 | void add_item (Gtk.TreeView tree, Layout.AddLayout pop) | 147 | |
390 | 148 | { | 148 | tree.get_cursor (out path, null); |
391 | 149 | pop.layout_added.connect ((layout, variant) => | 149 | |
392 | 150 | { | 150 | if (path == null) |
393 | 151 | Gtk.TreeIter iter; | 151 | { |
394 | 152 | 152 | return -1; | |
395 | 153 | var name = handler.get_name (layout, variant); | 153 | } |
396 | 154 | var code = handler.get_code (layout, variant); | 154 | |
397 | 155 | var list = tree.model as Gtk.ListStore; | 155 | return (path.get_indices ())[0]; |
398 | 156 | 156 | } | |
399 | 157 | if (settings.add_layout (code)) | 157 | |
400 | 158 | { | 158 | void update_cursor () { |
401 | 159 | list.append (out iter); | 159 | Gtk.TreePath path = new Gtk.TreePath.from_indices (settings.layouts.active); |
402 | 160 | list.set (iter, 0, name); | 160 | tree.set_cursor (path, null, false); |
403 | 161 | list.set (iter, 1, layout); | 161 | } |
404 | 162 | list.set (iter, 2, variant); | 162 | |
405 | 163 | 163 | Gtk.ListStore build_store () { | |
406 | 164 | tree.set_cursor (list.get_path(iter), null, false); | 164 | Gtk.ListStore list_store = new Gtk.ListStore (3, typeof (string), typeof(uint), typeof(uint)); |
407 | 165 | update_buttons (); | 165 | Gtk.TreeIter iter; |
408 | 166 | } | 166 | |
409 | 167 | } ); | 167 | uint layout = 0, variant = 0; |
410 | 168 | } | 168 | |
411 | 169 | 169 | for (uint i = 0; i < settings.layouts.length; i++) { | |
412 | 170 | void remove_item (Gtk.TreeView tree) | 170 | string item = settings.layouts.get_layout (i).name; |
413 | 171 | { | 171 | handler.from_code (item, out layout, out variant); |
414 | 172 | Gtk.TreeModel model; | 172 | item = handler.get_name (layout, variant); |
415 | 173 | Gtk.TreeIter iter; | 173 | |
416 | 174 | 174 | list_store.append (out iter); | |
417 | 175 | var select = tree.get_selection(); | 175 | list_store.set (iter, 0, item); |
418 | 176 | select.get_selected (out model, out iter); | 176 | list_store.set (iter, 1, layout); |
419 | 177 | 177 | list_store.set (iter, 2, variant); | |
420 | 178 | GLib.Value layout, variant; | 178 | } |
421 | 179 | model.get_value (iter, 1, out layout); | 179 | return list_store; |
422 | 180 | model.get_value (iter, 2, out variant); | 180 | } |
423 | 181 | 181 | ||
424 | 182 | settings.remove_layout (handler.get_code ((uint)layout, (uint)variant)); | 182 | void rebuild_list () { |
425 | 183 | stdout.printf ("%s\n", handler.get_code ((uint)layout, (uint)variant)); | 183 | tree.model = build_store (); |
426 | 184 | (model as Gtk.ListStore).remove(iter); | 184 | update_cursor (); |
427 | 185 | } | 185 | update_buttons (); |
428 | 186 | 186 | } | |
429 | 187 | void move_item (Gtk.TreeView tree, int dir) | 187 | |
430 | 188 | { | 188 | void remove_item () |
431 | 189 | Gtk.TreeModel model; | 189 | { |
432 | 190 | Gtk.TreeIter iter_current, iter_new; | 190 | settings.layouts.remove_active_layout (); |
433 | 191 | Gtk.TreePath path_current; | 191 | rebuild_list (); |
434 | 192 | 192 | } | |
435 | 193 | var select = tree.get_selection(); | 193 | |
436 | 194 | select.get_selected (out model, out iter_current); | 194 | void add_item (LayoutPage.AddLayout pop) |
437 | 195 | path_current = model.get_path (iter_current); | 195 | { |
438 | 196 | 196 | pop.layout_added.connect ((layout, variant) => { | |
439 | 197 | iter_new = iter_current; | 197 | |
440 | 198 | 198 | var name = handler.get_name (layout, variant); | |
441 | 199 | var store = model as Gtk.ListStore; | 199 | var code = handler.get_code (layout, variant); |
442 | 200 | 200 | ||
443 | 201 | switch (dir) | 201 | // TODO variant |
444 | 202 | { | 202 | settings.layouts.add_layout (new Layout.XKB (code, "")); |
445 | 203 | case 1: if (model.iter_next (ref iter_new) == false) | 203 | rebuild_list (); |
446 | 204 | return; | 204 | }); |
447 | 205 | break; | 205 | } |
448 | 206 | case 0: if (model.iter_previous (ref iter_new) == false) | 206 | } |
226 | 207 | return; | ||
227 | 208 | break; | ||
228 | 209 | } | ||
229 | 210 | |||
230 | 211 | store.swap (iter_current, iter_new); | ||
231 | 212 | |||
232 | 213 | tree.set_cursor (model.get_path (iter_current), null, false); | ||
233 | 214 | |||
234 | 215 | switch (dir) | ||
235 | 216 | { | ||
236 | 217 | case 1: | ||
237 | 218 | settings.layout_down ((path_current.get_indices()) [0]); | ||
238 | 219 | break; | ||
239 | 220 | case 0: | ||
240 | 221 | settings.layout_up ((path_current.get_indices()) [0]); | ||
241 | 222 | break; | ||
242 | 223 | } | ||
243 | 224 | } | ||
244 | 225 | } | ||
449 | 226 | } | 207 | } |
450 | 227 | \ No newline at end of file | 208 | \ No newline at end of file |
451 | 228 | 209 | ||
452 | === modified file 'src/Pages/Layout/handler.vala' | |||
453 | --- src/Pages/Layout/handler.vala 2014-01-06 17:12:27 +0000 | |||
454 | +++ src/Pages/Layout/handler.vala 2014-08-11 14:54:46 +0000 | |||
455 | @@ -1,85 +1,84 @@ | |||
457 | 1 | namespace Pantheon.Keyboard.Layout | 1 | namespace Pantheon.Keyboard.LayoutPage |
458 | 2 | { | 2 | { |
459 | 3 | // class that parses the layout file, provides lists of languages and | 3 | // class that parses the layout file, provides lists of languages and |
461 | 4 | // variants, and converts between layout names and their gsettings codes | 4 | // variants, and converts between layout names and their gsettings codes |
462 | 5 | class LayoutHandler : GLib.Object | 5 | class LayoutHandler : GLib.Object |
463 | 6 | { | 6 | { |
466 | 7 | Layout[] layouts; | 7 | InternalLayout[] layouts; |
467 | 8 | 8 | ||
468 | 9 | private string[] names; | 9 | private string[] names; |
469 | 10 | private string[] codes; | 10 | private string[] codes; |
471 | 11 | 11 | ||
472 | 12 | public LayoutHandler () | 12 | public LayoutHandler () |
473 | 13 | { | 13 | { |
474 | 14 | foreach (var l in parse_layouts ()) | 14 | foreach (var l in parse_layouts ()) |
475 | 15 | { | 15 | { |
476 | 16 | var parts = l.split(":", 2); | 16 | var parts = l.split(":", 2); |
478 | 17 | 17 | ||
479 | 18 | names += parts[0]; | 18 | names += parts[0]; |
480 | 19 | codes += parts[1]; | 19 | codes += parts[1]; |
483 | 20 | 20 | ||
484 | 21 | layouts += new Layout (parse_variants (l)); | 21 | layouts += new InternalLayout (parse_variants (l)); |
485 | 22 | } | 22 | } |
486 | 23 | } | 23 | } |
488 | 24 | 24 | ||
489 | 25 | public string[] get_layouts () { | 25 | public string[] get_layouts () { |
490 | 26 | return names; | 26 | return names; |
491 | 27 | } | 27 | } |
493 | 28 | 28 | ||
494 | 29 | public string[] get_variants (uint index) { | 29 | public string[] get_variants (uint index) { |
495 | 30 | return layouts[index].names; | 30 | return layouts[index].names; |
496 | 31 | } | 31 | } |
498 | 32 | 32 | ||
499 | 33 | public string get_code (uint l, uint v) | 33 | public string get_code (uint l, uint v) |
500 | 34 | { | 34 | { |
501 | 35 | if (v != 0) | 35 | if (v != 0) |
503 | 36 | return codes[l] + "\t" + layouts[l].codes[v]; | 36 | return codes[l] + "+" + layouts[l].codes[v]; |
504 | 37 | return codes[l]; | 37 | return codes[l]; |
505 | 38 | } | 38 | } |
507 | 39 | 39 | ||
508 | 40 | public string get_name (uint l, uint v) | 40 | public string get_name (uint l, uint v) |
509 | 41 | { | 41 | { |
510 | 42 | if (v != 0) | 42 | if (v != 0) |
511 | 43 | return layouts[l].names[v]; | 43 | return layouts[l].names[v]; |
512 | 44 | return names[l]; | 44 | return names[l]; |
513 | 45 | } | 45 | } |
515 | 46 | 46 | ||
516 | 47 | public bool from_code (string code, out uint l, out uint v) | 47 | public bool from_code (string code, out uint l, out uint v) |
517 | 48 | { | 48 | { |
520 | 49 | var parts = code.split("\t", 2); | 49 | var parts = code.split("+", 2); |
521 | 50 | 50 | ||
522 | 51 | l = v = 0; | 51 | l = v = 0; |
524 | 52 | 52 | ||
525 | 53 | if (parts[0] == null) return false; | 53 | if (parts[0] == null) return false; |
527 | 54 | 54 | ||
528 | 55 | while (codes[l] != parts[0]) | 55 | while (codes[l] != parts[0]) |
529 | 56 | if (l++ > codes.length) | 56 | if (l++ > codes.length) |
530 | 57 | return false; | 57 | return false; |
532 | 58 | 58 | ||
533 | 59 | if (parts[1] == null) return true; | 59 | if (parts[1] == null) return true; |
535 | 60 | 60 | ||
536 | 61 | while (layouts[l].codes[v] != parts[1]) | 61 | while (layouts[l].codes[v] != parts[1]) |
537 | 62 | if (v++ > layouts[l].codes.length) | 62 | if (v++ > layouts[l].codes.length) |
538 | 63 | return false; | 63 | return false; |
540 | 64 | 64 | ||
541 | 65 | return true; | 65 | return true; |
542 | 66 | } | 66 | } |
543 | 67 | 67 | ||
544 | 68 | // private class that contains the variants of one language | 68 | // private class that contains the variants of one language |
547 | 69 | private class Layout : GLib.Object | 69 | private class InternalLayout : GLib.Object { |
546 | 70 | { | ||
548 | 71 | public string[] names; | 70 | public string[] names; |
549 | 72 | public string[] codes; | 71 | public string[] codes; |
550 | 73 | 72 | ||
552 | 74 | public Layout( string[] variants ) | 73 | public InternalLayout (string[] variants ) |
553 | 75 | { | 74 | { |
554 | 76 | names += _("Default"); | 75 | names += _("Default"); |
555 | 77 | codes += ""; | 76 | codes += ""; |
557 | 78 | 77 | ||
558 | 79 | foreach (var v in variants) | 78 | foreach (var v in variants) |
559 | 80 | { | 79 | { |
560 | 81 | var parts = v.split(":", 2); | 80 | var parts = v.split(":", 2); |
562 | 82 | 81 | ||
563 | 83 | names += parts[0]; | 82 | names += parts[0]; |
564 | 84 | codes += parts[1]; | 83 | codes += parts[1]; |
565 | 85 | } | 84 | } |
566 | @@ -90,7 +89,7 @@ | |||
567 | 90 | private string[]? parse_layouts () | 89 | private string[]? parse_layouts () |
568 | 91 | { | 90 | { |
569 | 92 | string[] return_val = null; | 91 | string[] return_val = null; |
571 | 93 | 92 | ||
572 | 94 | var file = File.new_for_path (Build.PKGDATADIR + "/layouts.txt"); | 93 | var file = File.new_for_path (Build.PKGDATADIR + "/layouts.txt"); |
573 | 95 | 94 | ||
574 | 96 | if (!file.query_exists ()) { | 95 | if (!file.query_exists ()) { |
575 | @@ -100,23 +99,23 @@ | |||
576 | 100 | 99 | ||
577 | 101 | try { | 100 | try { |
578 | 102 | var dis = new DataInputStream (file.read ()); | 101 | var dis = new DataInputStream (file.read ()); |
580 | 103 | 102 | ||
581 | 104 | string line; | 103 | string line; |
583 | 105 | 104 | ||
584 | 106 | while ((line = dis.read_line (null)) != null) | 105 | while ((line = dis.read_line (null)) != null) |
585 | 107 | if( "#" in line ) | 106 | if( "#" in line ) |
586 | 108 | return_val += line.replace ("#", ""); | 107 | return_val += line.replace ("#", ""); |
587 | 109 | } catch (Error e) { | 108 | } catch (Error e) { |
588 | 110 | error ("%s", e.message); | 109 | error ("%s", e.message); |
589 | 111 | } | 110 | } |
591 | 112 | 111 | ||
592 | 113 | return return_val; | 112 | return return_val; |
593 | 114 | } | 113 | } |
594 | 115 | 114 | ||
595 | 116 | private string[]? parse_variants (string language) | 115 | private string[]? parse_variants (string language) |
596 | 117 | { | 116 | { |
597 | 118 | string[] return_val = null; | 117 | string[] return_val = null; |
599 | 119 | 118 | ||
600 | 120 | var file = File.new_for_path (Build.PKGDATADIR + "/layouts.txt"); | 119 | var file = File.new_for_path (Build.PKGDATADIR + "/layouts.txt"); |
601 | 121 | 120 | ||
602 | 122 | if (!file.query_exists ()) { | 121 | if (!file.query_exists ()) { |
603 | @@ -126,11 +125,11 @@ | |||
604 | 126 | 125 | ||
605 | 127 | try { | 126 | try { |
606 | 128 | var dis = new DataInputStream (file.read ()); | 127 | var dis = new DataInputStream (file.read ()); |
608 | 129 | 128 | ||
609 | 130 | string line; | 129 | string line; |
611 | 131 | 130 | ||
612 | 132 | while ((line = dis.read_line (null)) != null) { | 131 | while ((line = dis.read_line (null)) != null) { |
614 | 133 | if (line == "#"+language) { | 132 | if (line == "#" + language) { |
615 | 134 | while ((line = dis.read_line (null)) != null) { | 133 | while ((line = dis.read_line (null)) != null) { |
616 | 135 | if( "#" in line ) break; | 134 | if( "#" in line ) break; |
617 | 136 | return_val += line; | 135 | return_val += line; |
618 | 137 | 136 | ||
619 | === modified file 'src/Pages/Layout/settings.vala' | |||
620 | --- src/Pages/Layout/settings.vala 2014-01-06 17:12:27 +0000 | |||
621 | +++ src/Pages/Layout/settings.vala 2014-08-11 14:54:46 +0000 | |||
622 | @@ -1,156 +1,372 @@ | |||
624 | 1 | namespace Pantheon.Keyboard.Layout | 1 | namespace Pantheon.Keyboard.LayoutPage |
625 | 2 | { | 2 | { |
779 | 3 | // class to interact with gsettings and add/remove keyboard layouts | 3 | |
780 | 4 | class SettingsLayouts : Granite.Services.Settings | 4 | /** |
781 | 5 | { | 5 | * Type of a keyboard-layout as described in the description of |
782 | 6 | public string[] layouts { get; set; } | 6 | * "org.gnome.desktop.input-sources sources". |
783 | 7 | 7 | */ | |
784 | 8 | public void validate () | 8 | enum LayoutType { IBUS, XKB } |
785 | 9 | { | 9 | |
786 | 10 | string[] copy = {}; | 10 | /** |
787 | 11 | foreach (string str in layouts) | 11 | * Immutable class that respresents a keyboard-layout according to |
788 | 12 | { | 12 | * "org.gnome.desktop.input-sources sources". |
789 | 13 | //if (handler.valid_code(str)) | 13 | * This means that the enum parameter @layout_type equals the first string in the |
790 | 14 | copy += str; | 14 | * tupel of strings, and the @name parameter equals the second string. |
791 | 15 | } | 15 | */ |
792 | 16 | layouts = copy; | 16 | class Layout { |
793 | 17 | } | 17 | |
794 | 18 | 18 | public LayoutType layout_type { get; private set; } | |
795 | 19 | public bool add_layout (string layout) | 19 | public string name { get; private set; } |
796 | 20 | { | 20 | |
797 | 21 | foreach (string str in layouts) | 21 | public Layout (LayoutType layout_type, string name) { |
798 | 22 | { | 22 | this.layout_type = layout_type; |
799 | 23 | if (str == layout) | 23 | this.name = name; |
800 | 24 | return false; | 24 | } |
801 | 25 | } | 25 | |
802 | 26 | string[] val = layouts; | 26 | public Layout.XKB (string layout, string? variant) { |
803 | 27 | val += layout; | 27 | string full_name = layout; |
804 | 28 | layouts = val; | 28 | if (variant != null && variant != "") |
805 | 29 | return true; | 29 | full_name += "+" + variant; |
806 | 30 | } | 30 | this (LayoutType.XKB, full_name); |
807 | 31 | 31 | } | |
808 | 32 | public void remove_layout (string layout) | 32 | |
809 | 33 | { | 33 | public Layout.from_variant (GLib.Variant variant) { |
810 | 34 | string[] val = {}; | 34 | if (variant.is_of_type (new VariantType ("(ss)"))) { |
811 | 35 | 35 | unowned string type; | |
812 | 36 | foreach (string str in layouts) | 36 | unowned string name; |
813 | 37 | { | 37 | |
814 | 38 | if (str != layout) | 38 | variant.get ("(&s&s)", out type, out name); |
815 | 39 | val += str; | 39 | |
816 | 40 | } | 40 | if (type == "xkb") { |
817 | 41 | layouts = val; | 41 | layout_type = LayoutType.XKB; |
818 | 42 | } | 42 | } else if (type == "ibus") { |
819 | 43 | 43 | layout_type = LayoutType.IBUS; | |
820 | 44 | public void layout_up (int i) | 44 | } else { |
821 | 45 | { | 45 | warning ("Unkown type %s", type); |
822 | 46 | var l = layouts; | 46 | } |
823 | 47 | var tmp = l[i]; | 47 | this.name = name; |
824 | 48 | l[i] = l[i-1]; | 48 | |
825 | 49 | l[i-1] = tmp; | 49 | } else { |
826 | 50 | layouts = l; | 50 | warning ("Variant has invalid type"); |
827 | 51 | } | 51 | } |
828 | 52 | 52 | } | |
829 | 53 | public void layout_down (int i) | 53 | |
830 | 54 | { | 54 | public bool equal (Layout other) { |
831 | 55 | var l = layouts; | 55 | return this.layout_type == other.layout_type && this.name == other.name; |
832 | 56 | var tmp = l[i]; | 56 | } |
833 | 57 | l[i] = l[i+1]; | 57 | |
834 | 58 | l[i+1] = tmp; | 58 | /** |
835 | 59 | layouts = l; | 59 | * GSettings saves values in the form of GLib.Variant and this |
836 | 60 | } | 60 | * function creates a Variant representing this object. |
837 | 61 | 61 | */ | |
838 | 62 | public string[]? parse_default () | 62 | public GLib.Variant to_variant () { |
839 | 63 | { | 63 | string type_name = ""; |
840 | 64 | string[] return_val = null; | 64 | switch (layout_type) { |
841 | 65 | 65 | case LayoutType.IBUS: | |
842 | 66 | var file = File.new_for_path ("/etc/default/keyboard"); | 66 | type_name = "ibus"; |
843 | 67 | 67 | break; | |
844 | 68 | if (!file.query_exists ()) | 68 | case LayoutType.XKB: |
845 | 69 | { | 69 | type_name = "xkb"; |
846 | 70 | warning ("File '%s' doesn't exist.\n", file.get_path ()); | 70 | break; |
847 | 71 | return null; | 71 | default: |
848 | 72 | } | 72 | error ("You need to implemnt this for all possible values of" |
849 | 73 | 73 | + "the LayoutType-enum"); | |
850 | 74 | string xkb_layout = ""; | 74 | } |
851 | 75 | string xkb_variant = ""; | 75 | GLib.Variant first = new GLib.Variant.string (type_name); |
852 | 76 | 76 | GLib.Variant second = new GLib.Variant.string (name); | |
853 | 77 | try | 77 | GLib.Variant result = new GLib.Variant.tuple ({first, second}); |
854 | 78 | { | 78 | |
855 | 79 | var dis = new DataInputStream (file.read ()); | 79 | return result; |
856 | 80 | 80 | } | |
857 | 81 | string line; | 81 | |
858 | 82 | 82 | } | |
859 | 83 | while ((line = dis.read_line (null)) != null) | 83 | |
860 | 84 | { | 84 | /** |
861 | 85 | if (line.contains ("XKBLAYOUT=")) | 85 | * Represents a list of layouts. |
862 | 86 | { | 86 | */ |
863 | 87 | xkb_layout = line.replace ("XKBLAYOUT=", "").replace ("\"", ""); | 87 | class LayoutList : Object { |
864 | 88 | 88 | ||
865 | 89 | while ((line = dis.read_line (null)) != null) { | 89 | GLib.List<Layout> layouts = new GLib.List<Layout> (); |
866 | 90 | if (line.contains ("XKBVARIANT=")) { | 90 | |
867 | 91 | xkb_variant = line.replace ("XKBVARIANT=", "").replace ("\"", ""); | 91 | // signals |
868 | 92 | } | 92 | public signal void layouts_changed (); |
869 | 93 | } | 93 | public signal void active_changed (); |
870 | 94 | 94 | ||
871 | 95 | break; | 95 | public uint length { |
872 | 96 | } | 96 | get { |
873 | 97 | } | 97 | return layouts.length (); |
874 | 98 | } | 98 | } |
875 | 99 | 99 | } | |
876 | 100 | catch (Error e) | 100 | |
877 | 101 | { | 101 | uint _active; |
878 | 102 | error ("%s", e.message); | 102 | public uint active { |
879 | 103 | } | 103 | get { |
880 | 104 | 104 | return _active; | |
881 | 105 | var variants = xkb_variant.split (","); | 105 | } |
882 | 106 | var layouts = xkb_layout.split (","); | 106 | set { |
883 | 107 | 107 | if (length == 0) | |
884 | 108 | for (int i = 0; i < layouts.length; i++) | 108 | return; |
885 | 109 | { | 109 | |
886 | 110 | if (variants[i] != null && variants[i] != "") | 110 | if (_active == value) |
887 | 111 | return_val += layouts[i] + "\t" + variants[i]; | 111 | return; |
888 | 112 | else | 112 | |
889 | 113 | return_val += layouts[i]; | 113 | _active = value; |
890 | 114 | } | 114 | if (_active >= length) |
891 | 115 | 115 | _active = length - 1; | |
892 | 116 | return return_val; | 116 | active_changed (); |
893 | 117 | } | 117 | } |
894 | 118 | 118 | ||
895 | 119 | public void reset_all () | 119 | } |
896 | 120 | { | 120 | |
897 | 121 | layouts = parse_default (); | 121 | public bool contains_layout (Layout given_layout) { |
898 | 122 | validate (); | 122 | return get_layout_index (given_layout) != -1; |
899 | 123 | reverted (); | 123 | } |
900 | 124 | } | 124 | |
901 | 125 | 125 | public int get_layout_index (Layout given_layout) { | |
902 | 126 | public signal void reverted (); | 126 | int i = 0; |
903 | 127 | 127 | foreach (Layout l in layouts) { | |
904 | 128 | public SettingsLayouts() | 128 | if (l.equal (given_layout)) |
905 | 129 | { | 129 | return i; |
906 | 130 | base ("org.gnome.libgnomekbd.keyboard"); | 130 | i++; |
907 | 131 | 131 | } | |
908 | 132 | if (layouts == null || layouts.length == 0) | 132 | return -1; |
909 | 133 | layouts = parse_default (); | 133 | } |
910 | 134 | 134 | ||
911 | 135 | validate (); | 135 | private void switch_items (uint pos1, uint pos2) { |
912 | 136 | } | 136 | unowned List<Layout> container1 = layouts.nth (pos1); |
913 | 137 | } | 137 | unowned List<Layout> container2 = layouts.nth (pos2); |
914 | 138 | 138 | Layout tmp = container1.data; | |
915 | 139 | // allows for multiple kayboard layouts at a time | 139 | container1.data = container2.data; |
916 | 140 | class SettingsGroups : Granite.Services.Settings | 140 | container2.data = tmp; |
917 | 141 | { | 141 | |
918 | 142 | public int default_group { get; set; } | 142 | if (active == pos1) |
919 | 143 | public bool group_per_window { get; set; } | 143 | active = pos2; |
920 | 144 | 144 | else if (active == pos2) | |
921 | 145 | public void reset_all () | 145 | active = pos1; |
922 | 146 | { | 146 | |
923 | 147 | schema.reset ("default-group"); | 147 | layouts_changed (); |
924 | 148 | schema.reset ("group-per-window"); | 148 | } |
925 | 149 | } | 149 | |
926 | 150 | 150 | public void move_active_layout_up () { | |
927 | 151 | public SettingsGroups() | 151 | if (length == 0) |
928 | 152 | { | 152 | return; |
929 | 153 | base ("org.gnome.libgnomekbd.desktop"); | 153 | |
930 | 154 | } | 154 | // check that the active item is not the first one |
931 | 155 | } | 155 | if (active > 0) { |
932 | 156 | switch_items (active, active - 1); | ||
933 | 157 | } | ||
934 | 158 | } | ||
935 | 159 | |||
936 | 160 | public void move_active_layout_down () { | ||
937 | 161 | if (length == 0) | ||
938 | 162 | return; | ||
939 | 163 | |||
940 | 164 | // check that the active item is not the last one | ||
941 | 165 | if (active < length - 1) { | ||
942 | 166 | switch_items (active, active + 1); | ||
943 | 167 | } | ||
944 | 168 | } | ||
945 | 169 | |||
946 | 170 | public bool add_layout (Layout new_layout) { | ||
947 | 171 | if (! contains_layout (new_layout)) { | ||
948 | 172 | layouts.append (new_layout); | ||
949 | 173 | layouts_changed (); | ||
950 | 174 | return true; | ||
951 | 175 | } | ||
952 | 176 | return false; | ||
953 | 177 | } | ||
954 | 178 | |||
955 | 179 | public void remove_active_layout () { | ||
956 | 180 | layouts.remove (get_layout (active)); | ||
957 | 181 | |||
958 | 182 | if (active >= length) | ||
959 | 183 | active = length - 1; | ||
960 | 184 | layouts_changed (); | ||
961 | 185 | } | ||
962 | 186 | |||
963 | 187 | public void remove_all () { | ||
964 | 188 | layouts = new GLib.List<Layout> (); | ||
965 | 189 | layouts_changed (); | ||
966 | 190 | } | ||
967 | 191 | |||
968 | 192 | /** | ||
969 | 193 | * This method does not need call layouts_changed in any situation | ||
970 | 194 | * as a Layout-Object is immutable. | ||
971 | 195 | */ | ||
972 | 196 | public Layout? get_layout (uint index) { | ||
973 | 197 | if (index >= length) | ||
974 | 198 | return null; | ||
975 | 199 | |||
976 | 200 | return layouts.nth_data (index); | ||
977 | 201 | } | ||
978 | 202 | |||
979 | 203 | } | ||
980 | 204 | |||
981 | 205 | class LayoutSettings | ||
982 | 206 | { | ||
983 | 207 | |||
984 | 208 | public LayoutList layouts { get; private set; } | ||
985 | 209 | |||
986 | 210 | GLib.Settings settings; | ||
987 | 211 | |||
988 | 212 | /** | ||
989 | 213 | * True if and only if we are currently writing to gsettings | ||
990 | 214 | * by ourselves. | ||
991 | 215 | */ | ||
992 | 216 | bool currently_writing; | ||
993 | 217 | |||
994 | 218 | void write_list_to_gsettings () { | ||
995 | 219 | currently_writing = true; | ||
996 | 220 | try { | ||
997 | 221 | Variant[] elements = {}; | ||
998 | 222 | for (uint i = 0; i < layouts.length; i++) { | ||
999 | 223 | elements += layouts.get_layout (i).to_variant (); | ||
1000 | 224 | } | ||
1001 | 225 | GLib.Variant list = new GLib.Variant.array (new VariantType ("(ss)"), elements); | ||
1002 | 226 | settings.set_value ("sources", list); | ||
1003 | 227 | } finally { | ||
1004 | 228 | currently_writing = false; | ||
1005 | 229 | } | ||
1006 | 230 | } | ||
1007 | 231 | |||
1008 | 232 | void write_active_to_gsettings () { | ||
1009 | 233 | uint active = layouts.active; | ||
1010 | 234 | settings.set_uint ("current", active); | ||
1011 | 235 | } | ||
1012 | 236 | |||
1013 | 237 | void update_list_from_gsettings () { | ||
1014 | 238 | // We currently write to gsettings, so we caused this signal | ||
1015 | 239 | // and therefore don't need to read the list again from dconf | ||
1016 | 240 | if (currently_writing) | ||
1017 | 241 | return; | ||
1018 | 242 | |||
1019 | 243 | GLib.Variant sources = settings.get_value ("sources"); | ||
1020 | 244 | if (sources.is_of_type (VariantType.ARRAY)) { | ||
1021 | 245 | for(size_t i = 0; i < sources.n_children (); i++) { | ||
1022 | 246 | GLib.Variant child = sources.get_child_value (i); | ||
1023 | 247 | layouts.add_layout (new Layout.from_variant (child)); | ||
1024 | 248 | } | ||
1025 | 249 | } else { | ||
1026 | 250 | warning ("Unkown type"); | ||
1027 | 251 | } | ||
1028 | 252 | } | ||
1029 | 253 | |||
1030 | 254 | void update_active_from_gsettings () { | ||
1031 | 255 | layouts.active = settings.get_uint ("current"); | ||
1032 | 256 | } | ||
1033 | 257 | |||
1034 | 258 | bool _per_window; | ||
1035 | 259 | public bool per_window { | ||
1036 | 260 | get { | ||
1037 | 261 | return _per_window; | ||
1038 | 262 | } | ||
1039 | 263 | set { | ||
1040 | 264 | if (value != _per_window) { | ||
1041 | 265 | settings.set_boolean ("per-window", value); | ||
1042 | 266 | _per_window = value; | ||
1043 | 267 | } | ||
1044 | 268 | } | ||
1045 | 269 | } | ||
1046 | 270 | // signal when the variable per_window is changed by gsettings | ||
1047 | 271 | public signal void per_window_changed (); | ||
1048 | 272 | |||
1049 | 273 | public void parse_default () { | ||
1050 | 274 | var file = File.new_for_path ("/etc/default/keyboard"); | ||
1051 | 275 | |||
1052 | 276 | if (!file.query_exists ()) { | ||
1053 | 277 | warning ("File '%s' doesn't exist.\n", file.get_path ()); | ||
1054 | 278 | return; | ||
1055 | 279 | } | ||
1056 | 280 | |||
1057 | 281 | string xkb_layout = ""; | ||
1058 | 282 | string xkb_variant = ""; | ||
1059 | 283 | |||
1060 | 284 | try { | ||
1061 | 285 | var dis = new DataInputStream (file.read ()); | ||
1062 | 286 | |||
1063 | 287 | string line; | ||
1064 | 288 | |||
1065 | 289 | while ((line = dis.read_line (null)) != null) | ||
1066 | 290 | { | ||
1067 | 291 | if (line.contains ("XKBLAYOUT=")) | ||
1068 | 292 | { | ||
1069 | 293 | xkb_layout = line.replace ("XKBLAYOUT=", "").replace ("\"", ""); | ||
1070 | 294 | |||
1071 | 295 | while ((line = dis.read_line (null)) != null) { | ||
1072 | 296 | if (line.contains ("XKBVARIANT=")) { | ||
1073 | 297 | xkb_variant = line.replace ("XKBVARIANT=", "").replace ("\"", ""); | ||
1074 | 298 | } | ||
1075 | 299 | } | ||
1076 | 300 | |||
1077 | 301 | break; | ||
1078 | 302 | } | ||
1079 | 303 | } | ||
1080 | 304 | } | ||
1081 | 305 | catch (Error e) { | ||
1082 | 306 | warning ("%s", e.message); | ||
1083 | 307 | return; | ||
1084 | 308 | } | ||
1085 | 309 | |||
1086 | 310 | var variants = xkb_variant.split (","); | ||
1087 | 311 | var xkb_layouts = xkb_layout.split (","); | ||
1088 | 312 | |||
1089 | 313 | for (int i = 0; i < layouts.length; i++) { | ||
1090 | 314 | if (variants[i] != null && variants[i] != "") | ||
1091 | 315 | layouts.add_layout (new Layout (LayoutType.XKB, xkb_layouts[i] + "+" + variants[i])); | ||
1092 | 316 | else | ||
1093 | 317 | layouts.add_layout (new Layout (LayoutType.XKB, xkb_layouts[i])); | ||
1094 | 318 | } | ||
1095 | 319 | } | ||
1096 | 320 | |||
1097 | 321 | public void reset_all () | ||
1098 | 322 | { | ||
1099 | 323 | layouts.remove_all (); | ||
1100 | 324 | parse_default (); | ||
1101 | 325 | } | ||
1102 | 326 | |||
1103 | 327 | // singleton pattern | ||
1104 | 328 | static LayoutSettings? instance; | ||
1105 | 329 | public static LayoutSettings get_instance () { | ||
1106 | 330 | if (instance == null) { | ||
1107 | 331 | instance = new LayoutSettings (); | ||
1108 | 332 | } | ||
1109 | 333 | return instance; | ||
1110 | 334 | } | ||
1111 | 335 | |||
1112 | 336 | private LayoutSettings () | ||
1113 | 337 | { | ||
1114 | 338 | settings = new Settings ("org.gnome.desktop.input-sources"); | ||
1115 | 339 | layouts = new LayoutList (); | ||
1116 | 340 | |||
1117 | 341 | _per_window = settings.get_boolean ("per-window"); | ||
1118 | 342 | settings.changed["per-window"].connect (() => { | ||
1119 | 343 | _per_window = settings.get_boolean ("per-window"); | ||
1120 | 344 | per_window_changed (); | ||
1121 | 345 | }); | ||
1122 | 346 | |||
1123 | 347 | update_list_from_gsettings (); | ||
1124 | 348 | update_active_from_gsettings (); | ||
1125 | 349 | |||
1126 | 350 | layouts.layouts_changed.connect (() => { | ||
1127 | 351 | write_list_to_gsettings (); | ||
1128 | 352 | }); | ||
1129 | 353 | |||
1130 | 354 | layouts.active_changed.connect (() => { | ||
1131 | 355 | write_active_to_gsettings (); | ||
1132 | 356 | }); | ||
1133 | 357 | |||
1134 | 358 | settings.changed["sources"].connect (() => { | ||
1135 | 359 | update_list_from_gsettings (); | ||
1136 | 360 | }); | ||
1137 | 361 | |||
1138 | 362 | settings.changed["current"].connect (() => { | ||
1139 | 363 | update_active_from_gsettings (); | ||
1140 | 364 | }); | ||
1141 | 365 | |||
1142 | 366 | if (layouts.length == 0) | ||
1143 | 367 | parse_default (); | ||
1144 | 368 | |||
1145 | 369 | } | ||
1146 | 370 | } | ||
1147 | 371 | |||
1148 | 156 | } | 372 | } |
1149 | 157 | \ No newline at end of file | 373 | \ No newline at end of file |
1150 | 158 | 374 | ||
1151 | === modified file 'src/Pages/layout.vala' | |||
1152 | --- src/Pages/layout.vala 2014-01-06 17:12:27 +0000 | |||
1153 | +++ src/Pages/layout.vala 2014-08-11 14:54:46 +0000 | |||
1154 | @@ -1,12 +1,12 @@ | |||
1156 | 1 | namespace Pantheon.Keyboard.Layout | 1 | namespace Pantheon.Keyboard.LayoutPage |
1157 | 2 | { | 2 | { |
1158 | 3 | // global handler | 3 | // global handler |
1159 | 4 | LayoutHandler handler; | 4 | LayoutHandler handler; |
1160 | 5 | 5 | ||
1161 | 6 | class Page : Pantheon.Keyboard.AbstractPage | 6 | class Page : Pantheon.Keyboard.AbstractPage |
1162 | 7 | { | 7 | { |
1165 | 8 | private Layout.Display display; | 8 | private LayoutPage.Display display; |
1166 | 9 | private SettingsGroups settings; | 9 | private LayoutSettings settings; |
1167 | 10 | 10 | ||
1168 | 11 | public override void reset () | 11 | public override void reset () |
1169 | 12 | { | 12 | { |
1170 | @@ -18,18 +18,14 @@ | |||
1171 | 18 | public Page () | 18 | public Page () |
1172 | 19 | { | 19 | { |
1173 | 20 | handler = new LayoutHandler (); | 20 | handler = new LayoutHandler (); |
1174 | 21 | settings = LayoutSettings.get_instance (); | ||
1175 | 21 | 22 | ||
1176 | 22 | // first some labels | 23 | // first some labels |
1177 | 23 | var label_1 = new Gtk.Label (_("Allow different layouts for individual windows:")); | 24 | var label_1 = new Gtk.Label (_("Allow different layouts for individual windows:")); |
1178 | 24 | var label_2 = new Gtk.Label (_("New windows use:")); | ||
1179 | 25 | 25 | ||
1180 | 26 | label_1.valign = Gtk.Align.CENTER; | 26 | label_1.valign = Gtk.Align.CENTER; |
1181 | 27 | label_1.halign = Gtk.Align.END; | 27 | label_1.halign = Gtk.Align.END; |
1182 | 28 | label_2.valign = Gtk.Align.CENTER; | ||
1183 | 29 | label_2.halign = Gtk.Align.END; | ||
1184 | 30 | |||
1185 | 31 | this.attach (label_1, 4, 0, 1, 1); | 28 | this.attach (label_1, 4, 0, 1, 1); |
1186 | 32 | this.attach (label_2, 4, 1, 1, 1); | ||
1187 | 33 | 29 | ||
1188 | 34 | // widgets to change settings | 30 | // widgets to change settings |
1189 | 35 | var switch_main = new Gtk.Switch(); | 31 | var switch_main = new Gtk.Switch(); |
1190 | @@ -37,52 +33,20 @@ | |||
1191 | 37 | switch_main.halign = Gtk.Align.START; | 33 | switch_main.halign = Gtk.Align.START; |
1192 | 38 | switch_main.valign = Gtk.Align.CENTER; | 34 | switch_main.valign = Gtk.Align.CENTER; |
1193 | 39 | 35 | ||
1194 | 40 | var button1 = new Gtk.RadioButton.with_label(null, _("Default layout")); | ||
1195 | 41 | var button2 = new Gtk.RadioButton.with_label_from_widget (button1, _("Previous window's layout")); | ||
1196 | 42 | |||
1197 | 43 | this.attach (switch_main, 5, 0, 1, 1); | 36 | this.attach (switch_main, 5, 0, 1, 1); |
1237 | 44 | this.attach (button1, 5, 1, 1, 1); | 37 | |
1238 | 45 | this.attach (button2, 5, 2, 1, 1); | 38 | switch_main.active = settings.per_window; |
1239 | 46 | 39 | ||
1240 | 47 | settings = new Layout.SettingsGroups(); | 40 | switch_main.notify["active"].connect(() => { |
1241 | 48 | 41 | settings.per_window = switch_main.active; | |
1242 | 49 | // connect switch signals | 42 | }); |
1243 | 50 | switch_main.active = settings.group_per_window; | 43 | settings.per_window_changed.connect (() => { |
1244 | 51 | 44 | switch_main.active = settings.per_window; | |
1245 | 52 | button1.sensitive = button2.sensitive = switch_main.active; | 45 | }); |
1246 | 53 | label_2.sensitive = switch_main.active; | 46 | |
1208 | 54 | |||
1209 | 55 | switch_main.notify["active"].connect( () => { | ||
1210 | 56 | settings.group_per_window = switch_main.active; | ||
1211 | 57 | button1.sensitive = button2.sensitive = switch_main.active; | ||
1212 | 58 | label_2.sensitive = switch_main.active; | ||
1213 | 59 | } ); | ||
1214 | 60 | |||
1215 | 61 | settings.changed["group-per-window"].connect (() => { | ||
1216 | 62 | switch_main.active = settings.group_per_window; | ||
1217 | 63 | button1.sensitive = button2.sensitive = switch_main.active; | ||
1218 | 64 | label_2.sensitive = switch_main.active; | ||
1219 | 65 | } ); | ||
1220 | 66 | |||
1221 | 67 | // connect radio button signals | ||
1222 | 68 | if( settings.default_group >= 0 ) | ||
1223 | 69 | button1.active = true; | ||
1224 | 70 | else | ||
1225 | 71 | button2.active = true; | ||
1226 | 72 | |||
1227 | 73 | button1.toggled.connect (() => { settings.default_group = 0; } ); | ||
1228 | 74 | button2.toggled.connect (() => { settings.default_group = -1; } ); | ||
1229 | 75 | |||
1230 | 76 | settings.changed["default-group"].connect (() => | ||
1231 | 77 | { | ||
1232 | 78 | if( settings.default_group >= 0 ) | ||
1233 | 79 | button1.active = true; | ||
1234 | 80 | else | ||
1235 | 81 | button2.active = true; | ||
1236 | 82 | } ); | ||
1247 | 83 | 47 | ||
1248 | 84 | // tree view to display the current layouts | 48 | // tree view to display the current layouts |
1250 | 85 | display = new Layout.Display (); | 49 | display = new LayoutPage.Display (); |
1251 | 86 | 50 | ||
1252 | 87 | this.attach (display, 0, 0, 4, 4); | 51 | this.attach (display, 0, 0, 4, 4); |
1253 | 88 | 52 | ||
1254 | 89 | 53 | ||
1255 | === modified file 'src/keyboard.vala' | |||
1256 | --- src/keyboard.vala 2014-08-03 01:16:31 +0000 | |||
1257 | +++ src/keyboard.vala 2014-08-11 14:54:46 +0000 | |||
1258 | @@ -17,41 +17,31 @@ | |||
1259 | 17 | var stack_switcher = new Gtk.StackSwitcher (); | 17 | var stack_switcher = new Gtk.StackSwitcher (); |
1260 | 18 | stack_switcher.set_stack (stack); | 18 | stack_switcher.set_stack (stack); |
1261 | 19 | stack_switcher.halign = Gtk.Align.CENTER; | 19 | stack_switcher.halign = Gtk.Align.CENTER; |
1263 | 20 | 20 | ||
1264 | 21 | stack.add_titled (new Keyboard.Shortcuts.Page (), "shortcuts", _("Shortcuts")); | 21 | stack.add_titled (new Keyboard.Shortcuts.Page (), "shortcuts", _("Shortcuts")); |
1265 | 22 | stack.add_titled (new Keyboard.Behaviour.Page (), "behavior", _("Behavior")); | 22 | stack.add_titled (new Keyboard.Behaviour.Page (), "behavior", _("Behavior")); |
1267 | 23 | stack.add_titled (new Keyboard.Layout.Page (), "layout", _("Layout")); | 23 | stack.add_titled (new Keyboard.LayoutPage.Page (), "layout", _("Layout")); |
1268 | 24 | stack.add_titled (new Keyboard.Options.Page (), "options", _("Options")); | 24 | stack.add_titled (new Keyboard.Options.Page (), "options", _("Options")); |
1269 | 25 | 25 | ||
1270 | 26 | // button to reset the current page | ||
1271 | 27 | /*var button = new Gtk.Button.with_label (_("Reset to defaults")); | ||
1272 | 28 | |||
1273 | 29 | button.expand = false; | ||
1274 | 30 | button.halign = Gtk.Align.END; | ||
1275 | 31 | |||
1276 | 32 | button.clicked.connect (() => { | ||
1277 | 33 | pages[notebook.page].reset (); | ||
1278 | 34 | });*/ | ||
1279 | 35 | |||
1280 | 36 | grid.attach (stack_switcher, 0, 0, 1, 1); | 26 | grid.attach (stack_switcher, 0, 0, 1, 1); |
1281 | 37 | grid.attach (stack, 0, 1, 1, 1); | 27 | grid.attach (stack, 0, 1, 1, 1); |
1282 | 38 | } | 28 | } |
1283 | 39 | grid.show_all (); | 29 | grid.show_all (); |
1284 | 40 | return grid; | 30 | return grid; |
1285 | 41 | } | 31 | } |
1287 | 42 | 32 | ||
1288 | 43 | public override void shown () { | 33 | public override void shown () { |
1290 | 44 | 34 | ||
1291 | 45 | } | 35 | } |
1293 | 46 | 36 | ||
1294 | 47 | public override void hidden () { | 37 | public override void hidden () { |
1296 | 48 | 38 | ||
1297 | 49 | } | 39 | } |
1299 | 50 | 40 | ||
1300 | 51 | public override void search_callback (string location) { | 41 | public override void search_callback (string location) { |
1302 | 52 | 42 | ||
1303 | 53 | } | 43 | } |
1305 | 54 | 44 | ||
1306 | 55 | // 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior") | 45 | // 'search' returns results like ("Keyboard → Behavior → Duration", "keyboard<sep>behavior") |
1307 | 56 | public override async Gee.TreeMap<string, string> search (string search) { | 46 | public override async Gee.TreeMap<string, string> search (string search) { |
1308 | 57 | return new Gee.TreeMap<string, string> (null, null); | 47 | return new Gee.TreeMap<string, string> (null, null); |
1309 | @@ -62,4 +52,4 @@ | |||
1310 | 62 | debug ("Activating Keyboard plug"); | 52 | debug ("Activating Keyboard plug"); |
1311 | 63 | var plug = new Pantheon.Keyboard.Plug (); | 53 | var plug = new Pantheon.Keyboard.Plug (); |
1312 | 64 | return plug; | 54 | return plug; |
1314 | 65 | } | 55 | } |
1315 | 66 | \ No newline at end of file | 56 | \ No newline at end of file |
Even if it doesn't respect ANY elementary codestyle rule, I approve the bug fix