[gedit/wip/loader-saver: 3/19] Move encoding utils functions to gedit-utils



commit 8f11873f32d8f76aa389f9503ba8cb29251a0621
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jun 11 23:41:10 2014 +0200

    Move encoding utils functions to gedit-utils
    
    gedit-encodings will be removed, but the utils functions will still be
    needed in gedit.

 gedit/gedit-document-loader.c     |    2 +-
 gedit/gedit-encodings-combo-box.c |    2 +-
 gedit/gedit-encodings-dialog.c    |    4 +-
 gedit/gedit-encodings.c           |   69 -------------------------------------
 gedit/gedit-encodings.h           |    3 --
 gedit/gedit-utils.c               |   67 +++++++++++++++++++++++++++++++++++
 gedit/gedit-utils.h               |    6 +++-
 7 files changed, 76 insertions(+), 77 deletions(-)
---
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index b70bf30..8b1c9eb 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -626,7 +626,7 @@ get_candidate_encodings (GeditDocumentLoader *loader)
        enc_strv = g_settings_get_strv (loader->priv->enc_settings,
                                        GEDIT_SETTINGS_ENCODING_AUTO_DETECTED);
 
-       encodings = _gedit_encoding_strv_to_list ((const gchar * const *)enc_strv);
+       encodings = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_strv);
        g_strfreev (enc_strv);
 
        metadata = get_metadata_encoding (loader);
diff --git a/gedit/gedit-encodings-combo-box.c b/gedit/gedit-encodings-combo-box.c
index fa1f05b..a4263e2 100644
--- a/gedit/gedit-encodings-combo-box.c
+++ b/gedit/gedit-encodings-combo-box.c
@@ -331,7 +331,7 @@ update_menu (GeditEncodingsComboBox *menu)
        enc_strv = g_settings_get_strv (menu->priv->enc_settings,
                                        GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU);
 
-       encodings = _gedit_encoding_strv_to_list ((const gchar * const *)enc_strv);
+       encodings = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_strv);
        g_strfreev (enc_strv);
 
        for (l = encodings; l != NULL; l = g_slist_next (l))
diff --git a/gedit/gedit-encodings-dialog.c b/gedit/gedit-encodings-dialog.c
index 45807e8..362796f 100644
--- a/gedit/gedit-encodings-dialog.c
+++ b/gedit/gedit-encodings-dialog.c
@@ -92,7 +92,7 @@ gedit_encodings_dialog_response (GtkDialog *dialog,
                {
                        gchar **encs;
 
-                       encs = _gedit_encoding_list_to_strv (priv->show_in_menu_list);
+                       encs = _gedit_utils_encoding_list_to_strv (priv->show_in_menu_list);
                        g_settings_set_strv (priv->enc_settings,
                                             GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU,
                                             (const gchar * const *)encs);
@@ -292,7 +292,7 @@ init_shown_in_menu_tree_model (GeditEncodingsDialog *dialog)
        enc_strv = g_settings_get_strv (dialog->priv->enc_settings,
                                        GEDIT_SETTINGS_ENCODING_SHOWN_IN_MENU);
 
-       list = _gedit_encoding_strv_to_list ((const gchar * const *)enc_strv);
+       list = _gedit_utils_encoding_strv_to_list ((const gchar * const *)enc_strv);
 
        for (tmp = list; tmp != NULL; tmp = g_slist_next (tmp))
        {
diff --git a/gedit/gedit-encodings.c b/gedit/gedit-encodings.c
index 20b44e0..b70e044 100644
--- a/gedit/gedit-encodings.c
+++ b/gedit/gedit-encodings.c
@@ -101,73 +101,4 @@ gedit_encoding_free (GeditEncoding *enc)
        gtk_source_encoding_free ((GtkSourceEncoding *) enc);
 }
 
-static gboolean
-data_exists (GSList         *list,
-            const gpointer  data)
-{
-       while (list != NULL)
-       {
-               if (list->data == data)
-                       return TRUE;
-
-               list = g_slist_next (list);
-       }
-
-       return FALSE;
-}
-
-GSList *
-_gedit_encoding_strv_to_list (const gchar * const *enc_str)
-{
-       GSList *res = NULL;
-       gchar **p;
-       const GeditEncoding *enc;
-
-       for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++)
-       {
-               const gchar *charset = *p;
-
-               if (strcmp (charset, "CURRENT") == 0)
-                       g_get_charset (&charset);
-
-               g_return_val_if_fail (charset != NULL, NULL);
-               enc = gedit_encoding_get_from_charset (charset);
-
-               if (enc != NULL)
-               {
-                       if (!data_exists (res, (gpointer)enc))
-                               res = g_slist_prepend (res, (gpointer)enc);
-
-               }
-       }
-
-       return g_slist_reverse (res);
-}
-
-gchar **
-_gedit_encoding_list_to_strv (const GSList *enc_list)
-{
-       GSList *l;
-       GPtrArray *array;
-
-       array = g_ptr_array_sized_new (g_slist_length ((GSList *)enc_list) + 1);
-
-       for (l = (GSList *)enc_list; l != NULL; l = g_slist_next (l))
-       {
-               const GeditEncoding *enc;
-               const gchar *charset;
-
-               enc = (const GeditEncoding *)l->data;
-
-               charset = gedit_encoding_get_charset (enc);
-               g_return_val_if_fail (charset != NULL, NULL);
-
-               g_ptr_array_add (array, g_strdup (charset));
-       }
-
-       g_ptr_array_add (array, NULL);
-
-       return (gchar **)g_ptr_array_free (array, FALSE);
-}
-
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-encodings.h b/gedit/gedit-encodings.h
index 25eb8cd..96a54c3 100644
--- a/gedit/gedit-encodings.h
+++ b/gedit/gedit-encodings.h
@@ -50,9 +50,6 @@ GeditEncoding         *gedit_encoding_copy             (const GeditEncoding *enc);
 
 void                    gedit_encoding_free             (GeditEncoding       *enc);
 
-GSList                 *_gedit_encoding_strv_to_list    (const gchar * const *enc_str);
-gchar                 **_gedit_encoding_list_to_strv    (const GSList        *enc);
-
 G_END_DECLS
 
 #endif  /* __GEDIT_ENCODINGS_H__ */
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 107b226..5d87008 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -1442,4 +1442,71 @@ gedit_utils_set_direct_save_filename (GdkDragContext *context)
        return uri;
 }
 
+static gboolean
+data_exists (GSList         *list,
+            const gpointer  data)
+{
+       for (; list != NULL; list = g_slist_next (list))
+       {
+               if (list->data == data)
+               {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+GSList *
+_gedit_utils_encoding_strv_to_list (const gchar * const *enc_str)
+{
+       GSList *res = NULL;
+       gchar **p;
+
+       for (p = (gchar **)enc_str; p != NULL && *p != NULL; p++)
+       {
+               const gchar *charset = *p;
+               const GtkSourceEncoding *enc;
+
+               if (g_str_equal (charset, "CURRENT"))
+               {
+                       g_get_charset (&charset);
+               }
+
+               g_return_val_if_fail (charset != NULL, NULL);
+               enc = gtk_source_encoding_get_from_charset (charset);
+
+               if (enc != NULL &&
+                   !data_exists (res, (gpointer)enc))
+               {
+                       res = g_slist_prepend (res, (gpointer)enc);
+               }
+       }
+
+       return g_slist_reverse (res);
+}
+
+gchar **
+_gedit_utils_encoding_list_to_strv (const GSList *enc_list)
+{
+       GSList *l;
+       GPtrArray *array;
+
+       array = g_ptr_array_sized_new (g_slist_length ((GSList *)enc_list) + 1);
+
+       for (l = (GSList *)enc_list; l != NULL; l = g_slist_next (l))
+       {
+               const GtkSourceEncoding *enc = l->data;
+               const gchar *charset = gtk_source_encoding_get_charset (enc);
+
+               g_return_val_if_fail (charset != NULL, NULL);
+
+               g_ptr_array_add (array, g_strdup (charset));
+       }
+
+       g_ptr_array_add (array, NULL);
+
+       return (gchar **)g_ptr_array_free (array, FALSE);
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index 424220a..478e034 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -26,7 +26,6 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <atk/atk.h>
-#include <gedit/gedit-encodings.h>
 #include <gedit/gedit-document.h>
 #include <gtksourceview/gtksource.h>
 
@@ -130,6 +129,11 @@ GeditDocumentCompressionType
 
 gchar           *gedit_utils_set_direct_save_filename  (GdkDragContext *context);
 
+/* Private */
+GSList         *_gedit_utils_encoding_strv_to_list     (const gchar * const *enc_str);
+
+gchar         **_gedit_utils_encoding_list_to_strv     (const GSList *enc_list);
+
 G_END_DECLS
 
 #endif /* __GEDIT_UTILS_H__ */


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