[gedit] utils: remove encoding functions



commit 70bdbd167453840b19a35ddae6ee5f77f6a0c5aa
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Mar 29 13:04:40 2015 +0200

    utils: remove encoding functions
    
    Move them as static functions where they are used (they are used at only
    one place each).
    
    For strv_to_list(), the support for the magic encoding "CURRENT" (for
    the current locale encoding) has been removed, since it's no longer used
    and documented. CURRENT is now only present in GtkSourceEncoding.

 gedit/gedit-encoding-items.c   |    1 -
 gedit/gedit-encodings-dialog.c |   26 ++++++++++++++-
 gedit/gedit-settings.c         |   27 ++++++++++++++--
 gedit/gedit-utils.c            |   67 ----------------------------------------
 gedit/gedit-utils.h            |    5 ---
 5 files changed, 48 insertions(+), 78 deletions(-)
---
diff --git a/gedit/gedit-encoding-items.c b/gedit/gedit-encoding-items.c
index 4954325..ad88a00 100644
--- a/gedit/gedit-encoding-items.c
+++ b/gedit/gedit-encoding-items.c
@@ -23,7 +23,6 @@
 #include <glib/gi18n.h>
 
 #include "gedit-settings.h"
-#include "gedit-utils.h"
 
 struct _GeditEncodingItem
 {
diff --git a/gedit/gedit-encodings-dialog.c b/gedit/gedit-encodings-dialog.c
index 713a378..e121aae 100644
--- a/gedit/gedit-encodings-dialog.c
+++ b/gedit/gedit-encodings-dialog.c
@@ -29,7 +29,6 @@
 #include <glib/gi18n.h>
 #include <gtksourceview/gtksource.h>
 
-#include "gedit-utils.h"
 #include "gedit-settings.h"
 
 struct _GeditEncodingsDialogPrivate
@@ -98,6 +97,29 @@ get_chosen_encodings_list (GeditEncodingsDialog *dialog)
        return g_slist_reverse (ret);
 }
 
+static gchar **
+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 = l->next)
+       {
+               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);
+}
+
 static void
 gedit_encodings_dialog_response (GtkDialog *gtk_dialog,
                                  gint       response_id)
@@ -118,7 +140,7 @@ gedit_encodings_dialog_response (GtkDialog *gtk_dialog,
                gchar **enc_strv;
 
                enc_list = get_chosen_encodings_list (dialog);
-               enc_strv = _gedit_utils_encoding_list_to_strv (enc_list);
+               enc_strv = encoding_list_to_strv (enc_list);
 
                g_settings_set_strv (dialog->priv->enc_settings,
                                     GEDIT_SETTINGS_CANDIDATE_ENCODINGS,
diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c
index acc41ad..3a72eb3 100644
--- a/gedit/gedit-settings.c
+++ b/gedit/gedit-settings.c
@@ -33,7 +33,6 @@
 #include "gedit-app.h"
 #include "gedit-view.h"
 #include "gedit-window.h"
-#include "gedit-utils.h"
 
 #define GEDIT_SETTINGS_LOCKDOWN_COMMAND_LINE "disable-command-line"
 #define GEDIT_SETTINGS_LOCKDOWN_PRINTING "disable-printing"
@@ -510,10 +509,32 @@ strv_is_empty (gchar **strv)
        return FALSE;
 }
 
+static GSList *
+encoding_strv_to_list (const gchar * const *encoding_strv)
+{
+       GSList *list = NULL;
+       gchar **p;
+
+       for (p = (gchar **)encoding_strv; p != NULL && *p != NULL; p++)
+       {
+               const gchar *charset = *p;
+               const GtkSourceEncoding *encoding;
+
+               encoding = gtk_source_encoding_get_from_charset (charset);
+
+               if (encoding != NULL &&
+                   g_slist_find (list, encoding) == NULL)
+               {
+                       list = g_slist_prepend (list, (gpointer)encoding);
+               }
+       }
+
+       return g_slist_reverse (list);
+}
+
 /* Take in priority the candidate encodings from GSettings. If the gsetting is
  * empty, take the default candidates of GtkSourceEncoding.
  * Also, ensure that UTF-8 and the current locale encoding are present.
- * TODO remove duplicates.
  * Returns: a list of GtkSourceEncodings. Free with g_slist_free().
  */
 GSList *
@@ -538,7 +559,7 @@ gedit_settings_get_candidate_encodings (void)
        }
        else
        {
-               candidates = _gedit_utils_encoding_strv_to_list ((const gchar * const *)settings_strv);
+               candidates = encoding_strv_to_list ((const gchar * const *) settings_strv);
 
                /* Ensure that UTF-8 is present. */
                if (utf8_encoding != current_encoding &&
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 0f1dec7..d8e0706 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -1462,71 +1462,4 @@ gedit_utils_newline_type_to_string (GtkSourceNewlineType newline_type)
        return NULL;
 }
 
-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 e1785ea..4c15c27 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -131,11 +131,6 @@ gchar           *gedit_utils_set_direct_save_filename      (GdkDragContext *context);
 
 const gchar     *gedit_utils_newline_type_to_string    (GtkSourceNewlineType newline_type);
 
-/* 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]