[gnome-control-center] common: Consolidate CcLanguageChooser functions



commit c7d2b0945dc9532369c319eca797adf0aeb78d0f
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Dec 1 10:33:37 2020 +1300

    common: Consolidate CcLanguageChooser functions

 panels/common/cc-language-chooser.c | 38 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
---
diff --git a/panels/common/cc-language-chooser.c b/panels/common/cc-language-chooser.c
index a48968c1f..08cd71bce 100644
--- a/panels/common/cc-language-chooser.c
+++ b/panels/common/cc-language-chooser.c
@@ -54,42 +54,28 @@ struct _CcLanguageChooser {
 G_DEFINE_TYPE (CcLanguageChooser, cc_language_chooser, GTK_TYPE_DIALOG)
 
 static void
-add_languages (CcLanguageChooser *chooser,
-               gchar            **locale_ids,
-               GHashTable        *initial)
+add_all_languages (CcLanguageChooser *chooser)
 {
-        while (*locale_ids) {
-                gchar *locale_id;
-                gboolean is_initial;
-                CcLanguageRow *row;
+        g_auto(GStrv) locale_ids = NULL;
+        g_autoptr(GHashTable) initial = NULL;
 
-                locale_id = *locale_ids;
-                locale_ids ++;
+        locale_ids = gnome_get_all_locales ();
+        initial = cc_common_language_get_initial_languages ();
+        for (int i = 0; locale_ids[i] != NULL; i++) {
+                CcLanguageRow *row;
+                gboolean is_initial;
 
-                if (!cc_common_language_has_font (locale_id))
+                if (!cc_common_language_has_font (locale_ids[i]))
                         continue;
 
-                is_initial = (g_hash_table_lookup (initial, locale_id) != NULL);
-                row = cc_language_row_new (locale_id);
-                cc_language_row_set_is_extra (row, !is_initial);
+                row = cc_language_row_new (locale_ids[i]);
                 gtk_widget_show (GTK_WIDGET (row));
+                is_initial = (g_hash_table_lookup (initial, locale_ids[i]) != NULL);
+                cc_language_row_set_is_extra (row, !is_initial);
                 gtk_list_box_prepend (chooser->language_listbox, GTK_WIDGET (row));
         }
 }
 
-static void
-add_all_languages (CcLanguageChooser *chooser)
-{
-        gchar **locale_ids;
-        GHashTable *initial;
-
-        locale_ids = gnome_get_all_locales ();
-        initial = cc_common_language_get_initial_languages ();
-        add_languages (chooser, locale_ids, initial);
-        g_hash_table_destroy (initial);
-        g_strfreev (locale_ids);
-}
-
 static gboolean
 match_all (gchar       **words,
            const gchar  *str)


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