[gnome-control-center] region: Create a source from the X layout in use when setting is empty



commit 1e0192555b686f24d084903d4ce70b5534af6260
Author: Rui Matos <tiagomatos gmail com>
Date:   Thu Sep 13 16:20:29 2012 +0200

    region: Create a source from the X layout in use when setting is empty
    
    We don't want to show an empty input sources list so we create a
    source from the current X layout in case the setting is empty.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683879

 panels/region/gnome-region-panel-input.c |   48 ++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-input.c b/panels/region/gnome-region-panel-input.c
index f2fa585..aec7996 100644
--- a/panels/region/gnome-region-panel-input.c
+++ b/panels/region/gnome-region-panel-input.c
@@ -505,6 +505,49 @@ populate_model (GtkListStore *store,
   g_hash_table_destroy (active_sources_table);
 }
 
+static GVariant *
+create_source_from_current_xkb_config (void)
+{
+  GVariantBuilder builder;
+  XkbRF_VarDefsRec *xkb_var_defs;
+  gchar *tmp;
+  gchar *source_id = NULL;
+  gchar **layouts = NULL;
+  gchar **variants = NULL;
+
+  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
+
+  gnome_xkb_info_get_var_defs (&tmp, &xkb_var_defs);
+  g_free (tmp);
+
+  if (xkb_var_defs->layout)
+    layouts = g_strsplit (xkb_var_defs->layout, ",", 2);
+  if (xkb_var_defs->variant)
+    variants = g_strsplit (xkb_var_defs->variant, ",", 2);
+
+  if (layouts && layouts[0] && layouts[0][0])
+    source_id = g_strdup_printf ("%s", layouts[0]);
+  else
+    goto out;
+
+  if (variants && variants[0] && variants[0][0])
+    {
+      tmp = source_id;
+      source_id = g_strdup_printf ("%s+%s", tmp, variants[0]);
+      g_free (tmp);
+    }
+
+  g_variant_builder_add (&builder, "(ss)", INPUT_SOURCE_TYPE_XKB, source_id);
+
+ out:
+  g_free (source_id);
+  g_strfreev (layouts);
+  g_strfreev (variants);
+  gnome_xkb_info_free_var_defs (xkb_var_defs);
+
+  return g_variant_builder_end (&builder);
+}
+
 static void
 populate_with_active_sources (GtkListStore *store)
 {
@@ -518,6 +561,11 @@ populate_with_active_sources (GtkListStore *store)
   GtkTreeIter tree_iter;
 
   sources = g_settings_get_value (input_sources_settings, KEY_INPUT_SOURCES);
+  if (g_variant_n_children (sources) < 1)
+    {
+      g_variant_unref (sources);
+      sources = create_source_from_current_xkb_config ();
+    }
 
   g_variant_iter_init (&iter, sources);
   while (g_variant_iter_next (&iter, "(&s&s)", &type, &id))



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