[Xfce4-commits] <xfce4-settings:master> Check the return value of gtk_tree_model_get_iter_first.

Jérôme Guelfucci noreply at xfce.org
Thu Sep 23 20:42:01 CEST 2010


Updating branch refs/heads/master
         to 12332425c5fb61abbd52ee3449dde7794ca36367 (commit)
       from fe1b97c07122c76af1788c2595a577bc89ba73cf (commit)

commit 12332425c5fb61abbd52ee3449dde7794ca36367
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Thu Sep 23 20:37:16 2010 +0200

    Check the return value of gtk_tree_model_get_iter_first.

 dialogs/keyboard-settings/xfce-keyboard-settings.c |  131 ++++++++++---------
 1 files changed, 69 insertions(+), 62 deletions(-)

diff --git a/dialogs/keyboard-settings/xfce-keyboard-settings.c b/dialogs/keyboard-settings/xfce-keyboard-settings.c
index 6bbb496..4a5a94f 100644
--- a/dialogs/keyboard-settings/xfce-keyboard-settings.c
+++ b/dialogs/keyboard-settings/xfce-keyboard-settings.c
@@ -1023,7 +1023,8 @@ xfce_keyboard_settings_set_layout (XfceKeyboardSettings *settings)
   view = gtk_builder_get_object (GTK_BUILDER (settings), "xkb_layout_view");
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
-  gtk_tree_model_get_iter_first (model, &iter);
+  if (!gtk_tree_model_get_iter_first (model, &iter))
+    return;
   gtk_tree_model_get (model, &iter,
                       XKB_TREE_LAYOUTS, &val_layout,
                       XKB_TREE_VARIANTS, &val_variant, -1);
@@ -1515,80 +1516,96 @@ xfce_keyboard_settings_layout_selection (XfceKeyboardSettings *settings,
     {
       gboolean found;
 
-      gtk_tree_model_get_iter_first (model, &iter);
-      found = FALSE;
-
-      do
+      if (gtk_tree_model_get_iter_first (model, &iter))
         {
-          gchar *tmp_layout;
+          found = FALSE;
 
-          gtk_tree_model_get (model, &iter, XKB_AVAIL_LAYOUTS_TREE_ID, &tmp_layout, -1);
-          path = gtk_tree_model_get_path (model, &iter);
+          do
+            {
+              gchar *tmp_layout;
 
-          if (found)
-            break;
+              gtk_tree_model_get (model, &iter, XKB_AVAIL_LAYOUTS_TREE_ID, &tmp_layout, -1);
+              path = gtk_tree_model_get_path (model, &iter);
 
-          if (g_strcmp0 (tmp_layout, edit_layout) == 0 )
-            {
-              if (edit_variant && g_strcmp0 (edit_variant, "") && gtk_tree_model_iter_has_child (model, &iter))
+              if (found)
+                break;
+
+              if (g_strcmp0 (tmp_layout, edit_layout) == 0 )
                 {
-                  GtkTreeIter iter2;
-                  gint n, i;
+                  if (edit_variant && g_strcmp0 (edit_variant, "") && gtk_tree_model_iter_has_child (model, &iter))
+                    {
+                      GtkTreeIter iter2;
+                      gint n, i;
 
-                  n = gtk_tree_model_iter_n_children (model, &iter);
+                      n = gtk_tree_model_iter_n_children (model, &iter);
 
-                  for (i = 0; i < n; i ++)
-                    {
-                      if (gtk_tree_model_iter_nth_child (model, &iter2, &iter, i))
+                      for (i = 0; i < n; i ++)
                         {
-                          gchar *tmp_variant;
+                          if (gtk_tree_model_iter_nth_child (model, &iter2, &iter, i))
+                            {
+                              gchar *tmp_variant;
 
-                          gtk_tree_model_get (model, &iter2, XKB_AVAIL_LAYOUTS_TREE_ID, &tmp_variant, -1);
+                              gtk_tree_model_get (model, &iter2, XKB_AVAIL_LAYOUTS_TREE_ID, &tmp_variant, -1);
 
-                          if (g_strcmp0 (tmp_variant, edit_variant) == 0)
-                            {
-                              GtkTreePath *path2;
+                              if (g_strcmp0 (tmp_variant, edit_variant) == 0)
+                                {
+                                  GtkTreePath *path2;
 
-                              path2 = gtk_tree_model_get_path (model, &iter2);
+                                  path2 = gtk_tree_model_get_path (model, &iter2);
 
-                              gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
-                                                                           path2, NULL,
-                                                                           TRUE, 0.5, 0);
-                              gtk_tree_view_expand_row (GTK_TREE_VIEW (layout_selection_view),
-                                                        path,
-                                                        TRUE);
-                              gtk_tree_selection_select_iter (selection, &iter2);
+                                  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
+                                                                               path2, NULL,
+                                                                               TRUE, 0.5, 0);
+                                  gtk_tree_view_expand_row (GTK_TREE_VIEW (layout_selection_view),
+                                                            path,
+                                                            TRUE);
+                                  gtk_tree_selection_select_iter (selection, &iter2);
+
+                                  found = TRUE;
+                                  g_free (tmp_variant);
+                                  gtk_tree_path_free (path2);
+                                  break;
+                                }
 
-                              found = TRUE;
                               g_free (tmp_variant);
-                              gtk_tree_path_free (path2);
-                              break;
                             }
-
-                          g_free (tmp_variant);
                         }
                     }
-                }
-              else
+                else
+                  {
+                    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
+                                                                 path, NULL,
+                                                                 TRUE, 0.5, 0);
+                    gtk_tree_selection_select_iter (selection, &iter);
+                    found = TRUE;
+                    break;
+                  }
+              }
+
+              gtk_tree_path_free (path);
+              g_free (tmp_layout);
+            }
+          while (gtk_tree_model_iter_next (model, &iter));
+
+          if (!found)
+            {
+              /* We did not find the iter to be edited, fallback to the first one */
+              if (gtk_tree_model_get_iter_first (model, &iter))
                 {
-                  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
-                                                               path, NULL,
-                                                               TRUE, 0.5, 0);
+                  path = gtk_tree_model_get_path (model, &iter);
                   gtk_tree_selection_select_iter (selection, &iter);
-                  found = TRUE;
-                  break;
+
+                  gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
+                                                path, NULL,
+                                                TRUE, 0.5, 0);
                 }
             }
-
-          gtk_tree_path_free (path);
-          g_free (tmp_layout);
         }
-      while (gtk_tree_model_iter_next (model, &iter));
-
-      if (!found)
+    }
+  else
+    {
+      if (gtk_tree_model_get_iter_first (model, &iter))
         {
-          /* We did not find the iter to be edited, fallback to the first one */
-          gtk_tree_model_get_iter_first (model, &iter);
           path = gtk_tree_model_get_path (model, &iter);
           gtk_tree_selection_select_iter (selection, &iter);
 
@@ -1597,16 +1614,6 @@ xfce_keyboard_settings_layout_selection (XfceKeyboardSettings *settings,
                                         TRUE, 0.5, 0);
         }
     }
-  else
-    {
-      gtk_tree_model_get_iter_first (model, &iter);
-      path = gtk_tree_model_get_path (model, &iter);
-      gtk_tree_selection_select_iter (selection, &iter);
-
-      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (layout_selection_view),
-                                    path, NULL,
-                                    TRUE, 0.5, 0);
-    }
 
   val_layout = NULL;
   gtk_widget_show (GTK_WIDGET (keyboard_layout_selection_dialog));



More information about the Xfce4-commits mailing list