aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-04-02 10:14:06 -0400
committerWilliam Hua <william.hua@canonical.com>2013-04-02 10:14:06 -0400
commit961446aefd28debf647c67aeda152d9b1b65ca92 (patch)
treecb019c9725f839e5a6c980f212670e4d2d083bc8 /lib/main.vala
parent17b5871e6c8d0067543f0eeb82a533e2dab83ff5 (diff)
downloadayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.gz
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.tar.bz2
ayatana-indicator-keyboard-961446aefd28debf647c67aeda152d9b1b65ca92.zip
Guess correct keyboard layout.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala34
1 files changed, 30 insertions, 4 deletions
diff --git a/lib/main.vala b/lib/main.vala
index a0ce4e79..84724b57 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -32,8 +32,23 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void handle_activate_chart (Variant? parameter) {
+ var layout = "us";
+
+ if (this.settings != null) {
+ Variant array;
+ string type;
+ string name;
+
+ var current = this.settings.get_uint ("current");
+ this.settings.get ("sources", "@a(ss)", out array);
+ array.get_child (current, "(ss)", out type, out name);
+
+ if (type == "xkb")
+ layout = name;
+ }
+
try {
- Process.spawn_command_line_async ("gkbd-keyboard-display -l fr");
+ Process.spawn_command_line_async (@"gkbd-keyboard-display -l $layout");
} catch {
warn_if_reached ();
}
@@ -102,12 +117,23 @@ public class Indicator.Keyboard.Service : Object {
VariantIter iter;
string type;
string name;
- uint i;
this.settings.get ("sources", "a(ss)", out iter);
- for (i = 0; iter.next ("(ss)", out type, out name); i++) {
- MenuItem menu_item = new MenuItem (name, "indicator.current");
+ for (var i = 0; iter.next ("(ss)", out type, out name); i++) {
+ if (type == "xkb") {
+ var language = Xkl.get_language_name (name);
+ var country = Xkl.get_country_name (name);
+
+ if (language != null && country != null)
+ name = @"$language ($country)";
+ else if (language != null)
+ name = language;
+ else if (country != null)
+ name = country;
+ }
+
+ var menu_item = new MenuItem (name, "indicator.current");
menu_item.set_attribute (Menu.ATTRIBUTE_TARGET, "u", i);
section.append_item (menu_item);
}