[gedit] Small refactoring about getting the encoding from metadata
- From: Paolo Borelli <pborelli src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gedit] Small refactoring about getting the encoding from metadata
- Date: Thu, 26 Nov 2009 20:36:36 +0000 (UTC)
commit c7426294df11ca7425dde38c69ecf4d446e8e77d
Author: Paolo Borelli <pborelli gnome org>
Date: Thu Nov 26 21:31:05 2009 +0100
Small refactoring about getting the encoding from metadata
gedit/gedit-document-loader.c | 53 +++++++++++++++++++++--------------------
gedit/gedit-document-loader.h | 1 -
2 files changed, 27 insertions(+), 27 deletions(-)
---
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index 661e639..84cbdc4 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -228,6 +228,23 @@ insert_text_in_document (GeditDocumentLoader *loader,
gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (doc));
}
+static const GeditEncoding *
+get_metadata_encoding (const gchar *uri)
+{
+ gchar *charset;
+
+ charset = gedit_metadata_manager_get (uri, "encoding");
+
+ if (charset == NULL)
+ return NULL;
+
+ enc = gedit_encoding_get_from_charset (charset);
+
+ g_free (charset);
+
+ return enc;
+}
+
/* This function is only meant to be called by child classes */
gboolean
gedit_document_loader_update_document_contents (GeditDocumentLoader *loader,
@@ -273,22 +290,27 @@ gedit_document_loader_update_document_contents (GeditDocumentLoader *loader,
gchar *converted_text = NULL;
gsize new_len = file_size;
+ /* Autodetecting the encoding */
if (loader->encoding == NULL)
{
- /* Autodetecting the encoding: first try with the encoding
- stored in the metadata, if any */
+ const gchar *uri;
+ const GeditEncoding *metadata_encoding;
+
+ /* first try with the encoding stored in the metadata, if any */
+ uri = gedit_document_loader_get_uri (loader);
+ metadata_encoding = get_metadata_encoding (uri);
- if (loader->metadata_encoding != NULL)
+ if (metadata_encoding != NULL)
{
converted_text = gedit_convert_to_utf8 (
file_contents,
file_size,
- &loader->metadata_encoding,
+ &metadata_encoding,
&new_len,
NULL);
if (converted_text != NULL)
- loader->auto_detected_encoding = loader->metadata_encoding;
+ loader->auto_detected_encoding = metadata_encoding;
}
}
@@ -353,24 +375,6 @@ gedit_document_loader_loading (GeditDocumentLoader *loader,
}
}
-static const GeditEncoding *
-get_metadata_encoding (const gchar *uri)
-{
- const GeditEncoding *enc;
- gchar *charset;
-
- charset = gedit_metadata_manager_get (uri, "encoding");
-
- if (charset == NULL)
- return NULL;
-
- enc = gedit_encoding_get_from_charset (charset);
-
- g_free (charset);
-
- return enc;
-}
-
/* This is a factory method that returns an appopriate loader
* for the given uri.
*/
@@ -410,9 +414,6 @@ gedit_document_loader_load (GeditDocumentLoader *loader)
g_return_if_fail (loader->used == FALSE);
loader->used = TRUE;
- if (loader->encoding == NULL)
- loader->metadata_encoding = get_metadata_encoding (loader->uri);
-
GEDIT_DOCUMENT_LOADER_GET_CLASS (loader)->load (loader);
}
diff --git a/gedit/gedit-document-loader.h b/gedit/gedit-document-loader.h
index ed8fa13..45805d7 100644
--- a/gedit/gedit-document-loader.h
+++ b/gedit/gedit-document-loader.h
@@ -65,7 +65,6 @@ struct _GeditDocumentLoader
GFileInfo *info;
gchar *uri;
const GeditEncoding *encoding;
- const GeditEncoding *metadata_encoding;
const GeditEncoding *auto_detected_encoding;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]