[gtksourceview/wip/default-encodings: 2/2] encodings: get default candidates



commit 6834a08d6e103d19c5fff5fa5f5b8eda4b9fa14d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Jul 29 14:33:33 2014 +0200

    encodings: get default candidates
    
    Just a prototype.

 gtksourceview/gtksourceencoding.c |   34 ++++++++++++++++++++++++++++++++--
 gtksourceview/gtksourceencoding.h |    6 +++---
 tests/test-widget.c               |    3 +++
 3 files changed, 38 insertions(+), 5 deletions(-)
---
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index 211c28b..a469664 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -487,6 +487,38 @@ gtk_source_encoding_get_name (const GtkSourceEncoding* enc)
        return (enc->name == NULL) ? _("Unknown") : _(enc->name);
 }
 
+GSList *
+gtk_source_encoding_get_default_candidates (void)
+{
+       const gchar *encodings_str;
+       GVariant *encodings_variant;
+       const gchar **encodings_strv;
+       gint i;
+
+       /* Translators: This is the sorted list of encodings used by
+        * GtkSourceView for automatic detection of the file encoding. You may
+        * want to customize it adding encodings that are common in your
+        * country, for instance the GB18030 encoding for the Chinese
+        * translation. You may also want to remove the ISO-8859-15 encoding
+        * (covering English and most Western European languages) if you think
+        * people in your country will rarely use it.  "CURRENT" is a magic
+        * value used by gedit and it represents the encoding for the current
+        * locale, so please don't translate the "CURRENT" term.  Only
+        * recognized encodings are used. See
+        * https://git.gnome.org/browse/gtksourceview/tree/gtksourceview/gtksourceencoding.c#n147
+        * for a list of supported encodings.
+        */
+       encodings_str = _("['UTF-8', 'CURRENT', 'ISO-8859-15', 'UTF-16']");
+
+       encodings_variant = g_variant_new_parsed (encodings_str);
+       g_variant_ref_sink (encodings_variant);
+
+       encodings_strv = g_variant_get_strv (encodings_variant, NULL);
+
+       g_variant_unref (encodings_variant);
+       return _gtk_source_encoding_strv_to_list (encodings_strv);
+}
+
 /**
  * gtk_source_encoding_copy:
  * @enc: a #GtkSourceEncoding.
@@ -518,7 +550,6 @@ gtk_source_encoding_free (GtkSourceEncoding *enc)
        g_return_if_fail (enc != NULL);
 }
 
-#if 0
 /* Will probably be used in the future. */
 static gboolean
 data_exists (GSList         *list,
@@ -586,4 +617,3 @@ _gtk_source_encoding_list_to_strv (const GSList *enc_list)
 
        return (gchar **)g_ptr_array_free (array, FALSE);
 }
-#endif
diff --git a/gtksourceview/gtksourceencoding.h b/gtksourceview/gtksourceencoding.h
index 260dfbb..aa151cc 100644
--- a/gtksourceview/gtksourceencoding.h
+++ b/gtksourceview/gtksourceencoding.h
@@ -60,18 +60,18 @@ const GtkSourceEncoding     *gtk_source_encoding_get_current        (void);
 void                    gtk_source_encoding_foreach            (GtkSourceEncodingForeachFunc func,
                                                                 gpointer                     user_data);
 
+GSList                 *gtk_source_encoding_get_default_candidates
+                                                               (void);
+
 /* These should not be used, they are just to make python bindings happy */
 GtkSourceEncoding      *gtk_source_encoding_copy               (const GtkSourceEncoding *enc);
 void                    gtk_source_encoding_free               (GtkSourceEncoding       *enc);
 
-#if 0
-/* Will probably be used in the future. */
 G_GNUC_INTERNAL
 GSList                 *_gtk_source_encoding_strv_to_list      (const gchar * const     *enc_str);
 
 G_GNUC_INTERNAL
 gchar                 **_gtk_source_encoding_list_to_strv      (const GSList            *enc);
-#endif
 
 G_END_DECLS
 
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 1667e3e..3a6ddc7 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -1004,6 +1004,9 @@ test_widget_init (TestWidget *self)
        }
 
        open_file (self, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
+
+       g_print ("\n\n");
+       gtk_source_encoding_get_default_candidates ();
 }
 
 static TestWidget *


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