[gedit/wip/encoding-get-all] Use gtk_source_encoding_get_all() instead of foreach()



commit 321f9a0973a0c284e3ac6e1e399ace44771f5d54
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Aug 15 17:42:25 2014 +0200

    Use gtk_source_encoding_get_all() instead of foreach()
    
    gtk_source_encoding_foreach() has been removed.

 gedit/gedit-app.c              |   18 ++++++++++++++----
 gedit/gedit-encodings-dialog.c |   39 ++++++++++++++++++++++++---------------
 2 files changed, 38 insertions(+), 19 deletions(-)
---
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index 42b0365..df2b100 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -951,10 +951,20 @@ gedit_app_command_line (GApplication            *application,
 }
 
 static void
-encoding_foreach_cb (const GtkSourceEncoding *encoding,
-                    gpointer                 user_data)
+print_all_encodings (void)
 {
-       g_print ("%s\n", gtk_source_encoding_get_charset (encoding));
+       GSList *all_encodings;
+       GSList *l;
+
+       all_encodings = gtk_source_encoding_get_all ();
+
+       for (l = all_encodings; l != NULL; l = l->next)
+       {
+               const GtkSourceEncoding *encoding = l->data;
+               g_print ("%s\n", gtk_source_encoding_get_charset (encoding));
+       }
+
+       g_slist_free (all_encodings);
 }
 
 static gint
@@ -969,7 +979,7 @@ gedit_app_handle_local_options (GApplication *application,
 
        if (g_variant_dict_contains (options, "list-encodings"))
        {
-               gtk_source_encoding_foreach (encoding_foreach_cb, NULL);
+               print_all_encodings ();
                return 0;
        }
 
diff --git a/gedit/gedit-encodings-dialog.c b/gedit/gedit-encodings-dialog.c
index c5c141a..284a200 100644
--- a/gedit/gedit-encodings-dialog.c
+++ b/gedit/gedit-encodings-dialog.c
@@ -291,24 +291,34 @@ init_shown_in_menu_tree_model (GeditEncodingsDialog *dialog)
 }
 
 static void
-insert_encoding_foreach_cb (const GtkSourceEncoding *encoding,
-                           GeditEncodingsDialog    *dlg)
+init_liststore_available (GeditEncodingsDialog *dialog)
 {
-       GtkTreeIter iter;
+       GSList *all_encodings;
+       GSList *l;
 
-       if (encoding == gtk_source_encoding_get_utf8 ())
+       all_encodings = gtk_source_encoding_get_all ();
+
+       for (l = all_encodings; l != NULL; l = l->next)
        {
-               /* The UTF-8 encoding is always added to the combobox. */
-               return;
-       }
+               const GtkSourceEncoding *encoding = l->data;
+               GtkTreeIter iter;
 
-       gtk_list_store_append (dlg->priv->liststore_available, &iter);
+               if (encoding == gtk_source_encoding_get_utf8 ())
+               {
+                       /* The UTF-8 encoding is always added to the combobox. */
+                       continue;
+               }
 
-       gtk_list_store_set (dlg->priv->liststore_available,
-                           &iter,
-                           COLUMN_CHARSET, gtk_source_encoding_get_charset (encoding),
-                           COLUMN_NAME, gtk_source_encoding_get_name (encoding),
-                           -1);
+               gtk_list_store_append (dialog->priv->liststore_available, &iter);
+
+               gtk_list_store_set (dialog->priv->liststore_available,
+                                   &iter,
+                                   COLUMN_CHARSET, gtk_source_encoding_get_charset (encoding),
+                                   COLUMN_NAME, gtk_source_encoding_get_name (encoding),
+                                   -1);
+       }
+
+       g_slist_free (all_encodings);
 }
 
 static void
@@ -337,8 +347,7 @@ gedit_encodings_dialog_init (GeditEncodingsDialog *dlg)
        /* Tree view of available encodings */
 
        /* Add the data */
-       gtk_source_encoding_foreach ((GtkSourceEncodingForeachFunc) insert_encoding_foreach_cb,
-                                    dlg);
+       init_liststore_available (dlg);
 
        /* Sort model */
        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dlg->priv->sort_available),


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