From 0a4f042f3cbed0359c46c3da702821fd6244be2b Mon Sep 17 00:00:00 2001 From: William Hua Date: Mon, 24 Jun 2013 10:43:05 -0400 Subject: Check if at least one IBus engine. --- lib/main.vala | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index b49d9f3b..c74dfc05 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -410,13 +410,17 @@ public class Indicator.Keyboard.Service : Object { } else if (type == "ibus") { var names = new string[2]; names[0] = name; + var engines = get_ibus ().get_engines_by_names (names); - var engine = engines[0]; - try { - this.icons[index] = Icon.new_for_string (engine.get_icon ()); - } catch { - warn_if_reached (); + if (engines.length > 0) { + var engine = engines[0]; + + try { + this.icons[index] = Icon.new_for_string (engine.get_icon ()); + } catch { + warn_if_reached (); + } } } @@ -555,21 +559,25 @@ public class Indicator.Keyboard.Service : Object { else if (type == "ibus") { var names = new string[2]; names[0] = name; + var engines = get_ibus ().get_engines_by_names (names); - var engine = engines[0]; - string? language = engine.get_language (); - string? display_name = engine.get_longname (); - if (language != null) { - language = Xkl.get_language_name ((!) language); - } + if (engines.length > 0) { + var engine = engines[0]; + string? language = engine.get_language (); + string? display_name = engine.get_longname (); - if (language != null && display_name != null) { - name = @"$((!) language) ($((!) display_name))"; - } else if (language != null) { - name = (!) language; - } else if (display_name != null) { - name = (!) display_name; + if (language != null) { + language = Xkl.get_language_name ((!) language); + } + + if (language != null && display_name != null) { + name = @"$((!) language) ($((!) display_name))"; + } else if (language != null) { + name = (!) language; + } else if (display_name != null) { + name = (!) display_name; + } } } @@ -656,11 +664,15 @@ public class Indicator.Keyboard.Service : Object { } else if (type == "ibus") { var names = new string[2]; names[0] = name; + var engines = get_ibus ().get_engines_by_names (names); - var engine = engines[0]; - layout = engine.get_layout (); - variant = engine.get_layout_variant (); + if (engines.length > 0) { + var engine = engines[0]; + + layout = engine.get_layout (); + variant = engine.get_layout_variant (); + } } } -- cgit v1.2.3