[gedit/wip/loader-saver: 23/34] Use GtkSourceEncoding in GeditEncoding
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/loader-saver: 23/34] Use GtkSourceEncoding in GeditEncoding
- Date: Wed, 18 Jun 2014 16:30:58 +0000 (UTC)
commit 165b8d4aa9b3f7622514ae08b46106ec59ea25b5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Dec 30 15:42:05 2013 +0100
Use GtkSourceEncoding in GeditEncoding
gedit/gedit-encodings.c | 390 +++--------------------------------------------
gedit/gedit-encodings.h | 9 +-
2 files changed, 30 insertions(+), 369 deletions(-)
---
diff --git a/gedit/gedit-encodings.c b/gedit/gedit-encodings.c
index a165340..20b44e0 100644
--- a/gedit/gedit-encodings.c
+++ b/gedit/gedit-encodings.c
@@ -3,6 +3,7 @@
* This file is part of gedit
*
* Copyright (C) 2002-2005 Paolo Maggi
+ * Copyright (C) 2014 Sébastien Wilmet
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,6 +19,14 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * SECTION:gedit-encodings
+ * @short_description: character encodings (deprecated)
+ *
+ * Character encodings. The functions are deprecated and should not be used in
+ * newly written code. Use #GtkSourceEncoding instead.
+ */
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -28,419 +37,68 @@
#include "gedit-encodings.h"
-
-struct _GeditEncoding
-{
- gint index;
- const gchar *charset;
- const gchar *name;
-};
-
G_DEFINE_BOXED_TYPE (GeditEncoding, gedit_encoding,
gedit_encoding_copy,
gedit_encoding_free)
-/*
- * The original versions of the following tables are taken from profterm
- *
- * Copyright (C) 2002 Red Hat, Inc.
- */
-
-typedef enum
-{
-
- GEDIT_ENCODING_ISO_8859_1,
- GEDIT_ENCODING_ISO_8859_2,
- GEDIT_ENCODING_ISO_8859_3,
- GEDIT_ENCODING_ISO_8859_4,
- GEDIT_ENCODING_ISO_8859_5,
- GEDIT_ENCODING_ISO_8859_6,
- GEDIT_ENCODING_ISO_8859_7,
- GEDIT_ENCODING_ISO_8859_8,
- GEDIT_ENCODING_ISO_8859_9,
- GEDIT_ENCODING_ISO_8859_10,
- GEDIT_ENCODING_ISO_8859_13,
- GEDIT_ENCODING_ISO_8859_14,
- GEDIT_ENCODING_ISO_8859_15,
- GEDIT_ENCODING_ISO_8859_16,
-
- GEDIT_ENCODING_UTF_7,
- GEDIT_ENCODING_UTF_16,
- GEDIT_ENCODING_UTF_16_BE,
- GEDIT_ENCODING_UTF_16_LE,
- GEDIT_ENCODING_UTF_32,
- GEDIT_ENCODING_UCS_2,
- GEDIT_ENCODING_UCS_4,
-
- GEDIT_ENCODING_ARMSCII_8,
- GEDIT_ENCODING_BIG5,
- GEDIT_ENCODING_BIG5_HKSCS,
- GEDIT_ENCODING_CP_866,
-
- GEDIT_ENCODING_EUC_JP,
- GEDIT_ENCODING_EUC_JP_MS,
- GEDIT_ENCODING_CP932,
- GEDIT_ENCODING_EUC_KR,
- GEDIT_ENCODING_EUC_TW,
-
- GEDIT_ENCODING_GB18030,
- GEDIT_ENCODING_GB2312,
- GEDIT_ENCODING_GBK,
- GEDIT_ENCODING_GEOSTD8,
-
- GEDIT_ENCODING_IBM_850,
- GEDIT_ENCODING_IBM_852,
- GEDIT_ENCODING_IBM_855,
- GEDIT_ENCODING_IBM_857,
- GEDIT_ENCODING_IBM_862,
- GEDIT_ENCODING_IBM_864,
-
- GEDIT_ENCODING_ISO_2022_JP,
- GEDIT_ENCODING_ISO_2022_KR,
- GEDIT_ENCODING_ISO_IR_111,
- GEDIT_ENCODING_JOHAB,
- GEDIT_ENCODING_KOI8_R,
- GEDIT_ENCODING_KOI8__R,
- GEDIT_ENCODING_KOI8_U,
-
- GEDIT_ENCODING_SHIFT_JIS,
- GEDIT_ENCODING_TCVN,
- GEDIT_ENCODING_TIS_620,
- GEDIT_ENCODING_UHC,
- GEDIT_ENCODING_VISCII,
-
- GEDIT_ENCODING_WINDOWS_1250,
- GEDIT_ENCODING_WINDOWS_1251,
- GEDIT_ENCODING_WINDOWS_1252,
- GEDIT_ENCODING_WINDOWS_1253,
- GEDIT_ENCODING_WINDOWS_1254,
- GEDIT_ENCODING_WINDOWS_1255,
- GEDIT_ENCODING_WINDOWS_1256,
- GEDIT_ENCODING_WINDOWS_1257,
- GEDIT_ENCODING_WINDOWS_1258,
-
- GEDIT_ENCODING_LAST,
-
- GEDIT_ENCODING_UTF_8,
- GEDIT_ENCODING_UNKNOWN
-
-} GeditEncodingIndex;
-
-static const GeditEncoding utf8_encoding = {
- GEDIT_ENCODING_UTF_8,
- "UTF-8",
- N_("Unicode")
-};
-
-/* initialized in gedit_encoding_lazy_init() */
-static GeditEncoding unknown_encoding = {
- GEDIT_ENCODING_UNKNOWN,
- NULL,
- NULL
-};
-
-static const GeditEncoding encodings [] = {
-
- { GEDIT_ENCODING_ISO_8859_1,
- "ISO-8859-1", N_("Western") },
- { GEDIT_ENCODING_ISO_8859_2,
- "ISO-8859-2", N_("Central European") },
- { GEDIT_ENCODING_ISO_8859_3,
- "ISO-8859-3", N_("South European") },
- { GEDIT_ENCODING_ISO_8859_4,
- "ISO-8859-4", N_("Baltic") },
- { GEDIT_ENCODING_ISO_8859_5,
- "ISO-8859-5", N_("Cyrillic") },
- { GEDIT_ENCODING_ISO_8859_6,
- "ISO-8859-6", N_("Arabic") },
- { GEDIT_ENCODING_ISO_8859_7,
- "ISO-8859-7", N_("Greek") },
- { GEDIT_ENCODING_ISO_8859_8,
- "ISO-8859-8", N_("Hebrew Visual") },
- { GEDIT_ENCODING_ISO_8859_9,
- "ISO-8859-9", N_("Turkish") },
- { GEDIT_ENCODING_ISO_8859_10,
- "ISO-8859-10", N_("Nordic") },
- { GEDIT_ENCODING_ISO_8859_13,
- "ISO-8859-13", N_("Baltic") },
- { GEDIT_ENCODING_ISO_8859_14,
- "ISO-8859-14", N_("Celtic") },
- { GEDIT_ENCODING_ISO_8859_15,
- "ISO-8859-15", N_("Western") },
- { GEDIT_ENCODING_ISO_8859_16,
- "ISO-8859-16", N_("Romanian") },
-
- { GEDIT_ENCODING_UTF_7,
- "UTF-7", N_("Unicode") },
- { GEDIT_ENCODING_UTF_16,
- "UTF-16", N_("Unicode") },
- { GEDIT_ENCODING_UTF_16_BE,
- "UTF-16BE", N_("Unicode") },
- { GEDIT_ENCODING_UTF_16_LE,
- "UTF-16LE", N_("Unicode") },
- { GEDIT_ENCODING_UTF_32,
- "UTF-32", N_("Unicode") },
- { GEDIT_ENCODING_UCS_2,
- "UCS-2", N_("Unicode") },
- { GEDIT_ENCODING_UCS_4,
- "UCS-4", N_("Unicode") },
-
- { GEDIT_ENCODING_ARMSCII_8,
- "ARMSCII-8", N_("Armenian") },
- { GEDIT_ENCODING_BIG5,
- "BIG5", N_("Chinese Traditional") },
- { GEDIT_ENCODING_BIG5_HKSCS,
- "BIG5-HKSCS", N_("Chinese Traditional") },
- { GEDIT_ENCODING_CP_866,
- "CP866", N_("Cyrillic/Russian") },
-
- { GEDIT_ENCODING_EUC_JP,
- "EUC-JP", N_("Japanese") },
- { GEDIT_ENCODING_EUC_JP_MS,
- "EUC-JP-MS", N_("Japanese") },
- { GEDIT_ENCODING_CP932,
- "CP932", N_("Japanese") },
-
- { GEDIT_ENCODING_EUC_KR,
- "EUC-KR", N_("Korean") },
- { GEDIT_ENCODING_EUC_TW,
- "EUC-TW", N_("Chinese Traditional") },
-
- { GEDIT_ENCODING_GB18030,
- "GB18030", N_("Chinese Simplified") },
- { GEDIT_ENCODING_GB2312,
- "GB2312", N_("Chinese Simplified") },
- { GEDIT_ENCODING_GBK,
- "GBK", N_("Chinese Simplified") },
- { GEDIT_ENCODING_GEOSTD8,
- "GEORGIAN-ACADEMY", N_("Georgian") }, /* FIXME GEOSTD8 ? */
-
- { GEDIT_ENCODING_IBM_850,
- "IBM850", N_("Western") },
- { GEDIT_ENCODING_IBM_852,
- "IBM852", N_("Central European") },
- { GEDIT_ENCODING_IBM_855,
- "IBM855", N_("Cyrillic") },
- { GEDIT_ENCODING_IBM_857,
- "IBM857", N_("Turkish") },
- { GEDIT_ENCODING_IBM_862,
- "IBM862", N_("Hebrew") },
- { GEDIT_ENCODING_IBM_864,
- "IBM864", N_("Arabic") },
-
- { GEDIT_ENCODING_ISO_2022_JP,
- "ISO-2022-JP", N_("Japanese") },
- { GEDIT_ENCODING_ISO_2022_KR,
- "ISO-2022-KR", N_("Korean") },
- { GEDIT_ENCODING_ISO_IR_111,
- "ISO-IR-111", N_("Cyrillic") },
- { GEDIT_ENCODING_JOHAB,
- "JOHAB", N_("Korean") },
- { GEDIT_ENCODING_KOI8_R,
- "KOI8R", N_("Cyrillic") },
- { GEDIT_ENCODING_KOI8__R,
- "KOI8-R", N_("Cyrillic") },
- { GEDIT_ENCODING_KOI8_U,
- "KOI8U", N_("Cyrillic/Ukrainian") },
-
- { GEDIT_ENCODING_SHIFT_JIS,
- "SHIFT_JIS", N_("Japanese") },
- { GEDIT_ENCODING_TCVN,
- "TCVN", N_("Vietnamese") },
- { GEDIT_ENCODING_TIS_620,
- "TIS-620", N_("Thai") },
- { GEDIT_ENCODING_UHC,
- "UHC", N_("Korean") },
- { GEDIT_ENCODING_VISCII,
- "VISCII", N_("Vietnamese") },
-
- { GEDIT_ENCODING_WINDOWS_1250,
- "WINDOWS-1250", N_("Central European") },
- { GEDIT_ENCODING_WINDOWS_1251,
- "WINDOWS-1251", N_("Cyrillic") },
- { GEDIT_ENCODING_WINDOWS_1252,
- "WINDOWS-1252", N_("Western") },
- { GEDIT_ENCODING_WINDOWS_1253,
- "WINDOWS-1253", N_("Greek") },
- { GEDIT_ENCODING_WINDOWS_1254,
- "WINDOWS-1254", N_("Turkish") },
- { GEDIT_ENCODING_WINDOWS_1255,
- "WINDOWS-1255", N_("Hebrew") },
- { GEDIT_ENCODING_WINDOWS_1256,
- "WINDOWS-1256", N_("Arabic") },
- { GEDIT_ENCODING_WINDOWS_1257,
- "WINDOWS-1257", N_("Baltic") },
- { GEDIT_ENCODING_WINDOWS_1258,
- "WINDOWS-1258", N_("Vietnamese") }
-};
-
-static void
-gedit_encoding_lazy_init (void)
-{
- static gboolean initialized = FALSE;
- const gchar *locale_charset;
-
- if (initialized)
- return;
-
- if (g_get_charset (&locale_charset) == FALSE)
- {
- unknown_encoding.charset = g_strdup (locale_charset);
- }
-
- initialized = TRUE;
-}
-
const GeditEncoding *
gedit_encoding_get_from_charset (const gchar *charset)
{
- gint i;
-
- g_return_val_if_fail (charset != NULL, NULL);
-
- gedit_encoding_lazy_init ();
-
- if (charset == NULL)
- return NULL;
-
- if (g_ascii_strcasecmp (charset, "UTF-8") == 0)
- return gedit_encoding_get_utf8 ();
-
- i = 0;
- while (i < GEDIT_ENCODING_LAST)
- {
- if (g_ascii_strcasecmp (charset, encodings[i].charset) == 0)
- return &encodings[i];
-
- ++i;
- }
-
- if (unknown_encoding.charset != NULL)
- {
- if (g_ascii_strcasecmp (charset, unknown_encoding.charset) == 0)
- return &unknown_encoding;
- }
-
- return NULL;
+ return (const GeditEncoding *) gtk_source_encoding_get_from_charset (charset);
}
const GeditEncoding *
gedit_encoding_get_from_index (gint idx)
{
- g_return_val_if_fail (idx >= 0, NULL);
-
- if (idx >= GEDIT_ENCODING_LAST)
- return NULL;
-
- gedit_encoding_lazy_init ();
-
- return &encodings[idx];
+ return (const GeditEncoding *) gtk_source_encoding_get_from_index (idx);
}
const GeditEncoding *
gedit_encoding_get_utf8 (void)
{
- gedit_encoding_lazy_init ();
-
- return &utf8_encoding;
+ return (const GeditEncoding *) gtk_source_encoding_get_utf8 ();
}
const GeditEncoding *
gedit_encoding_get_current (void)
{
- static gboolean initialized = FALSE;
- static const GeditEncoding *locale_encoding = NULL;
-
- const gchar *locale_charset;
-
- gedit_encoding_lazy_init ();
-
- if (initialized != FALSE)
- return locale_encoding;
-
- if (g_get_charset (&locale_charset) == FALSE)
- {
- g_return_val_if_fail (locale_charset != NULL, &utf8_encoding);
-
- locale_encoding = gedit_encoding_get_from_charset (locale_charset);
- }
- else
- {
- locale_encoding = &utf8_encoding;
- }
-
- if (locale_encoding == NULL)
- {
- locale_encoding = &unknown_encoding;
- }
-
- g_return_val_if_fail (locale_encoding != NULL, NULL);
-
- initialized = TRUE;
-
- return locale_encoding;
+ return (const GeditEncoding *) gtk_source_encoding_get_current ();
}
gchar *
gedit_encoding_to_string (const GeditEncoding* enc)
{
- g_return_val_if_fail (enc != NULL, NULL);
-
- gedit_encoding_lazy_init ();
-
- g_return_val_if_fail (enc->charset != NULL, NULL);
-
- if (enc->name != NULL)
- {
- return g_strdup_printf ("%s (%s)", _(enc->name), enc->charset);
- }
- else
- {
- if (g_ascii_strcasecmp (enc->charset, "ANSI_X3.4-1968") == 0)
- return g_strdup_printf ("US-ASCII (%s)", enc->charset);
- else
- return g_strdup (enc->charset);
- }
+ return gtk_source_encoding_to_string ((const GtkSourceEncoding *) enc);
}
const gchar *
gedit_encoding_get_charset (const GeditEncoding* enc)
{
- g_return_val_if_fail (enc != NULL, NULL);
-
- gedit_encoding_lazy_init ();
-
- g_return_val_if_fail (enc->charset != NULL, NULL);
-
- return enc->charset;
+ return gtk_source_encoding_get_charset ((const GtkSourceEncoding *) enc);
}
const gchar *
gedit_encoding_get_name (const GeditEncoding* enc)
{
- g_return_val_if_fail (enc != NULL, NULL);
-
- gedit_encoding_lazy_init ();
-
- return (enc->name == NULL) ? _("Unknown") : _(enc->name);
+ return gtk_source_encoding_get_name ((const GtkSourceEncoding *) enc);
}
-/* These are to make language bindings happy. Since Encodings are
- * const, copy() just returns the same pointer and fres() doesn't
- * do nothing */
-
+/**
+ * gedit_encoding_copy:
+ * @enc: a #GeditEncoding.
+ *
+ * Returns: (transfer none): the copy of @enc.
+ */
GeditEncoding *
gedit_encoding_copy (const GeditEncoding *enc)
{
- g_return_val_if_fail (enc != NULL, NULL);
-
- return (GeditEncoding *) enc;
+ return (GeditEncoding *) gtk_source_encoding_copy ((const GtkSourceEncoding *) enc);
}
void
gedit_encoding_free (GeditEncoding *enc)
{
- g_return_if_fail (enc != NULL);
+ gtk_source_encoding_free ((GtkSourceEncoding *) enc);
}
static gboolean
diff --git a/gedit/gedit-encodings.h b/gedit/gedit-encodings.h
index e2fc7c4..25eb8cd 100644
--- a/gedit/gedit-encodings.h
+++ b/gedit/gedit-encodings.h
@@ -21,30 +21,33 @@
#ifndef __GEDIT_ENCODINGS_H__
#define __GEDIT_ENCODINGS_H__
-#include <glib.h>
-#include <glib-object.h>
+#include <gtksourceview/gtksource.h>
G_BEGIN_DECLS
-typedef struct _GeditEncoding GeditEncoding;
+typedef GtkSourceEncoding GeditEncoding;
#define GEDIT_TYPE_ENCODING (gedit_encoding_get_type ())
GType gedit_encoding_get_type (void) G_GNUC_CONST;
const GeditEncoding *gedit_encoding_get_from_charset (const gchar *charset);
+
const GeditEncoding *gedit_encoding_get_from_index (gint index);
gchar *gedit_encoding_to_string (const GeditEncoding *enc);
const gchar *gedit_encoding_get_name (const GeditEncoding *enc);
+
const gchar *gedit_encoding_get_charset (const GeditEncoding *enc);
const GeditEncoding *gedit_encoding_get_utf8 (void);
+
const GeditEncoding *gedit_encoding_get_current (void);
/* These should not be used, they are just to make python bindings happy */
GeditEncoding *gedit_encoding_copy (const GeditEncoding *enc);
+
void gedit_encoding_free (GeditEncoding *enc);
GSList *_gedit_encoding_strv_to_list (const gchar * const *enc_str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]