[gnome-settings-daemon] keyboard: Add likely IBus engine for some locales if empty setting



commit 2c1f88690f0ba54bfc45c425ef1f857d1202578c
Author: Rui Matos <tiagomatos gmail com>
Date:   Wed Oct 3 22:41:19 2012 +0200

    keyboard: Add likely IBus engine for some locales if empty setting
    
    If there are no input sources configured and we're running under one
    of some specific locales where it's highly likely that the user will
    need/want a specific IBus source to type we just add it to the list.
    
    LC_CTYPE is used to determine the locale for this purpose since many
    users in these locales set LC_MESSAGES to English.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=685457

 plugins/keyboard/gsd-keyboard-manager.c |   65 ++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 1 deletions(-)
---
diff --git a/plugins/keyboard/gsd-keyboard-manager.c b/plugins/keyboard/gsd-keyboard-manager.c
index 3bf1db5..6ad0e79 100644
--- a/plugins/keyboard/gsd-keyboard-manager.c
+++ b/plugins/keyboard/gsd-keyboard-manager.c
@@ -509,6 +509,65 @@ out:
         g_ptr_array_add (opt_array, NULL);
         return (gchar **) g_ptr_array_free (opt_array, FALSE);
 }
+
+static const gchar *
+engine_from_locale (void)
+{
+        const gchar *locale;
+        const gchar *locale_engine[][2] = {
+                { "ja_JP", "anthy" },
+                { "ko_KR", "hangul" },
+                { "zh_CN", "pinyin" },
+                { "zh_HK", "cangjie3" },
+                { "zh_TW", "chewing" },
+        };
+        gint i;
+
+        locale = setlocale (LC_CTYPE, NULL);
+        if (!locale)
+                return NULL;
+
+        for (i = 0; i < G_N_ELEMENTS (locale_engine); ++i)
+                if (g_str_has_prefix (locale, locale_engine[i][0]))
+                        return locale_engine[i][1];
+
+        return NULL;
+}
+
+static void
+init_builder_with_sources (GVariantBuilder *builder,
+                           GSettings       *settings)
+{
+        const gchar *type;
+        const gchar *id;
+        GVariantIter iter;
+        GVariant *sources;
+
+        sources = g_settings_get_value (settings, KEY_INPUT_SOURCES);
+
+        g_variant_builder_init (builder, G_VARIANT_TYPE ("a(ss)"));
+
+        g_variant_iter_init (&iter, sources);
+        while (g_variant_iter_next (&iter, "(&s&s)", &type, &id))
+                g_variant_builder_add (builder, "(ss)", type, id);
+
+        g_variant_unref (sources);
+}
+
+static void
+add_ibus_sources_from_locale (GSettings *settings)
+{
+        const gchar *locale_engine;
+        GVariantBuilder builder;
+
+        locale_engine = engine_from_locale ();
+        if (!locale_engine)
+                return;
+
+        init_builder_with_sources (&builder, settings);
+        g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_IBUS, locale_engine);
+        g_settings_set_value (settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder));
+}
 #endif  /* HAVE_IBUS */
 
 static gboolean
@@ -1318,8 +1377,12 @@ maybe_create_input_sources (GsdKeyboardManager *manager)
         }
 
         sources = g_settings_get_value (settings, KEY_INPUT_SOURCES);
-        if (g_variant_n_children (sources) < 1)
+        if (g_variant_n_children (sources) < 1) {
                 create_sources_from_current_xkb_config (settings);
+#ifdef HAVE_IBUS
+                add_ibus_sources_from_locale (settings);
+#endif
+        }
         g_variant_unref (sources);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]