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



commit f1c4f942d6ca00a1856d193cd1ced1f9dde1a1f1
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 |   40 +++++++++++++++++++++++++++++++++++++
 gtksourceview/gtksourceencoding.h |    3 ++
 tests/test-widget.c               |    3 ++
 3 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index 211c28b..c001708 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -487,6 +487,46 @@ 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.
+        * TODO update the URL.
+        * See http://git.gnome.org/browse/gedit/tree/gedit/gedit-encodings.c#n152 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_print ("Encodings:\n");
+       for (i = 0; encodings_strv != NULL && encodings_strv[i] != NULL; i++)
+       {
+               g_print ("%s\n", encodings_strv[i]);
+       }
+       g_print ("\n");
+
+       g_variant_unref (encodings_variant);
+       return NULL;
+}
+
 /**
  * gtk_source_encoding_copy:
  * @enc: a #GtkSourceEncoding.
diff --git a/gtksourceview/gtksourceencoding.h b/gtksourceview/gtksourceencoding.h
index 260dfbb..8f76d04 100644
--- a/gtksourceview/gtksourceencoding.h
+++ b/gtksourceview/gtksourceencoding.h
@@ -60,6 +60,9 @@ 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);
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]