[gnome-control-center] region: Handle the case of an empty input sources list



commit fb6881d53b6487c3503e352b0bf0356faf6b637a
Author: Rui Matos <tiagomatos gmail com>
Date:   Sat Sep 8 18:25:50 2012 +0200

    region: Handle the case of an empty input sources list
    
    We would end up in an endless loop on update.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=683879

 panels/region/gnome-region-panel-input.c |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/panels/region/gnome-region-panel-input.c b/panels/region/gnome-region-panel-input.c
index c54fa07..f2fa585 100644
--- a/panels/region/gnome-region-panel-input.c
+++ b/panels/region/gnome-region-panel-input.c
@@ -585,26 +585,25 @@ update_configuration (GtkTreeModel *model)
   const gchar *old_current_type;
   const gchar *old_current_id;
   guint old_current_index;
+  guint old_n_sources;
   guint index;
 
   old_sources = g_settings_get_value (input_sources_settings, KEY_INPUT_SOURCES);
   old_current_index = g_settings_get_uint (input_sources_settings, KEY_CURRENT_INPUT_SOURCE);
-  g_variant_get_child (old_sources,
-                       old_current_index,
-                       "(&s&s)",
-                       &old_current_type,
-                       &old_current_id);
-  if (g_variant_n_children (old_sources) < 1)
+  old_n_sources = g_variant_n_children (old_sources);
+
+  if (old_n_sources > 0 && old_current_index < old_n_sources)
     {
-      g_warning ("No input source configured, resetting");
-      g_settings_reset (input_sources_settings, KEY_INPUT_SOURCES);
-      goto exit;
+      g_variant_get_child (old_sources,
+                           old_current_index,
+                           "(&s&s)",
+                           &old_current_type,
+                           &old_current_id);
     }
-  if (old_current_index >= g_variant_n_children (old_sources))
+  else
     {
-      g_settings_set_uint (input_sources_settings,
-                           KEY_CURRENT_INPUT_SOURCE,
-                           g_variant_n_children (old_sources) - 1);
+      old_current_type = "";
+      old_current_id = "";
     }
 
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ss)"));
@@ -630,9 +629,8 @@ update_configuration (GtkTreeModel *model)
   while (gtk_tree_model_iter_next (model, &iter));
 
   g_settings_set_value (input_sources_settings, KEY_INPUT_SOURCES, g_variant_builder_end (&builder));
-
- exit:
   g_settings_apply (input_sources_settings);
+
   g_variant_unref (old_sources);
 }
 



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