[gedit] Remove gedit-convert.[ch].



commit d022c7eb9bc4cf7025f34548c8acd47b07f92735
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Feb 7 16:11:10 2010 +0100

    Remove gedit-convert.[ch].

 gedit/Makefile.am                     |    2 -
 gedit/gedit-convert.c                 |  317 ---------------------------------
 gedit/gedit-convert.h                 |   58 ------
 gedit/gedit-document-loader.c         |    1 -
 gedit/gedit-document-saver.c          |  176 ------------------
 gedit/gedit-document-saver.h          |   13 --
 gedit/gedit-document.c                |    1 -
 gedit/gedit-document.h                |    3 +-
 gedit/gedit-gio-document-loader.c     |    1 -
 gedit/gedit-io-error-message-area.c   |    8 +-
 gedit/gedit-smart-charset-converter.c |    6 +-
 gedit/gedit-tab.c                     |    1 -
 gedit/gedit-utils.c                   |    1 -
 13 files changed, 8 insertions(+), 580 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index fda85ea..e308c48 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -94,7 +94,6 @@ NOINST_H_FILES =			\
 INST_H_FILES =				\
 	gedit-app.h			\
 	gedit-commands.h		\
-	gedit-convert.h			\
 	gedit-debug.h			\
 	gedit-document.h 		\
 	gedit-encodings.h		\
@@ -140,7 +139,6 @@ libgedit_la_SOURCES = 			\
 	gedit-commands-help.c		\
 	gedit-commands-search.c		\
 	gedit-commands-view.c		\
-	gedit-convert.c			\
 	gedit-debug.c			\
 	gedit-dirs.c			\
 	gedit-document.c 		\
diff --git a/gedit/gedit-document-loader.c b/gedit/gedit-document-loader.c
index 54d7bba..05368c8 100644
--- a/gedit/gedit-document-loader.c
+++ b/gedit/gedit-document-loader.c
@@ -39,7 +39,6 @@
 #include "gedit-debug.h"
 #include "gedit-metadata-manager.h"
 #include "gedit-utils.h"
-#include "gedit-convert.h"
 #include "gedit-marshal.h"
 #include "gedit-enum-types.h"
 
diff --git a/gedit/gedit-document-saver.c b/gedit/gedit-document-saver.c
index d7d107f..1a064da 100644
--- a/gedit/gedit-document-saver.c
+++ b/gedit/gedit-document-saver.c
@@ -39,7 +39,6 @@
 
 #include "gedit-document-saver.h"
 #include "gedit-debug.h"
-#include "gedit-convert.h"
 #include "gedit-prefs-manager.h"
 #include "gedit-marshal.h"
 #include "gedit-utils.h"
@@ -266,181 +265,6 @@ gedit_document_saver_new (GeditDocument           *doc,
 	return saver;
 }
 
-gchar *
-gedit_document_saver_get_end_newline (GeditDocumentSaver *saver,
-				      gsize 	         *len)
-{
-	gchar *n_buffer = NULL;
-	gsize n_len = 0;
-
-	if (saver->encoding != gedit_encoding_get_utf8 ())
-	{
-		n_buffer = gedit_convert_from_utf8 ("\n", 
-						    -1, 
-						    saver->encoding, 
-						    &n_len, 
-						    NULL);
-
-		if (n_buffer == NULL)
-		{
-			/* we do not error out for this */
-			g_warning ("Cannot convert '\\n' to the desired encoding.");
-		}
-	}
-	else
-	{
-		n_buffer = g_strdup ("\n");
-		n_len = 1;
-	}
-
-	*len = n_len;
-	return n_buffer;
-}
-
-/* FIXME: we should rework the code to not need to fetch the
-   whole buffer in memory. Also encoding conversion should
-   be done in chunks */
-gchar *
-gedit_document_saver_get_document_contents (GeditDocumentSaver *saver,
-					    gsize 	       *len,
-					    GError 	      **error)
-{
-	GtkTextBuffer *buffer = GTK_TEXT_BUFFER (saver->document);
-	GtkTextIter start_iter;
-	GtkTextIter end_iter;
-	gchar *contents;
-	
-	gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
-	contents = gtk_text_buffer_get_slice (buffer, &start_iter, &end_iter, TRUE);
-
-	*len = strlen (contents);
-
-	if (saver->encoding != gedit_encoding_get_utf8 ())
-	{
-		gchar *converted_contents;
-		gsize new_len;
-
-		converted_contents = gedit_convert_from_utf8 (contents, 
-							      *len, 
-							      saver->encoding,
-							      &new_len,
-							      error);
-		g_free (contents);
-
-		if (*error != NULL)
-		{
-			/* Conversion error */
-			return NULL;
-		}
-		else
-		{
-			contents = converted_contents;
-			*len = new_len;
-		}
-	}
-	
-	return contents;
-}
-
-/*
- * Write the document contents in fd.
- */
-gboolean
-gedit_document_saver_write_document_contents (GeditDocumentSaver  *saver,
-					      gint                 fd,
-					      GError             **error)
-{
-	gsize len;
-	gssize written;
-	gboolean res;
-	gchar *contents;
-
-	gedit_debug (DEBUG_SAVER);
-
-	contents = gedit_document_saver_get_document_contents (saver, &len, error);
-
-	/* make sure we are at the start */
-	res = (lseek (fd, 0, SEEK_SET) != -1);
-
-	/* Truncate the file to 0, in case it was not empty */
-	if (res)
-	{
-		res = (ftruncate (fd, 0) == 0);
-	}
-
-	/* Save the file content */
-	if (len > 0)
-	{
-		if (res)
-		{
-			const gchar *write_buffer = contents;
-			gssize to_write = len;
-
-			do
-			{
-				written = write (fd, write_buffer, to_write);
-				if (written == -1)
-				{
-					if (errno == EINTR)
-						continue;
-
-					res = FALSE;
-
-					break;
-				}
-
-				to_write -= written;
-				write_buffer += written;
-			}
-			while (to_write > 0);
-		}
-
-		/* make sure files are always terminated with \n (see bug #95676). Note
-		   that we strip the trailing \n when loading the file */
-		if (res)
-		{
-			gchar *n_buf;
-			gsize n_len;
-
-			n_buf = gedit_document_saver_get_end_newline (saver, &n_len);
-			if (n_buf != NULL)
-			{
-				written = write (fd, n_buf, n_len);
-				res = (written != -1 && (gsize) written == n_len);
-				g_free (n_buf);
-			}
-			else
-			{
-				g_warning ("Cannot add '\\n' at the end of the file.");
-			}
-		}
-	}
-
-#ifdef HAVE_FSYNC
-	/* Ensure that all the data reaches disk */
-	if (res && fsync (fd) != 0)
-	{
-		g_set_error (error,
-			     G_IO_ERROR,
-			     g_io_error_from_errno (errno),
-			     "%s", g_strerror (errno));
-		res = FALSE;
-	}
-#endif
-
-	if (!res)
-	{
-		g_set_error (error,
-			     G_IO_ERROR,
-			     g_io_error_from_errno (errno),
-			     "%s", g_strerror (errno));
-	}
-
-	g_free (contents);
-
-	return res;
-}
-
 void
 gedit_document_saver_saving (GeditDocumentSaver *saver,
 			     gboolean            completed,
diff --git a/gedit/gedit-document-saver.h b/gedit/gedit-document-saver.h
index b1bd828..ccc0b5c 100644
--- a/gedit/gedit-document-saver.h
+++ b/gedit/gedit-document-saver.h
@@ -102,19 +102,6 @@ GeditDocumentSaver 	*gedit_document_saver_new 		(GeditDocument           *doc,
 								 GeditDocumentNewlineType newline_type,
 								 GeditDocumentSaveFlags   flags);
 
-gchar			*gedit_document_saver_get_document_contents (
-								 GeditDocumentSaver  *saver,
-								 gsize		     *len,
-								 GError             **error);
-
-gchar			*gedit_document_saver_get_end_newline	(GeditDocumentSaver *saver,
-								 gsize              *len);
-
-gboolean		 gedit_document_saver_write_document_contents (
-								 GeditDocumentSaver  *saver,
-								 gint                 fd,
-								 GError             **error);
-
 void			 gedit_document_saver_saving		(GeditDocumentSaver *saver,
 								 gboolean            completed,
 								 GError             *error);
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index b35e952..415944b 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -42,7 +42,6 @@
 
 #include "gedit-prefs-manager-app.h"
 #include "gedit-document.h"
-#include "gedit-convert.h"
 #include "gedit-debug.h"
 #include "gedit-utils.h"
 #include "gedit-language-manager.h"
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index a5d2730..b316393 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -165,8 +165,9 @@ enum
 	GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED,
 	GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
 	GEDIT_DOCUMENT_ERROR_TOO_BIG,
+	GEDIT_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED,
 	GEDIT_DOCUMENT_ERROR_CONVERSION_FALLBACK,
-	GEDIT_DOCUMENT_NUM_ERRORS 
+	GEDIT_DOCUMENT_NUM_ERRORS
 };
 
 GQuark		 gedit_document_error_quark	(void);
diff --git a/gedit/gedit-gio-document-loader.c b/gedit/gedit-gio-document-loader.c
index 63ceae0..ac5b8c4 100644
--- a/gedit/gedit-gio-document-loader.c
+++ b/gedit/gedit-gio-document-loader.c
@@ -40,7 +40,6 @@
 
 #include "gedit-gio-document-loader.h"
 #include "gedit-smart-charset-converter.h"
-#include "gedit-convert.h"
 #include "gedit-prefs-manager.h"
 #include "gedit-debug.h"
 #include "gedit-utils.h"
diff --git a/gedit/gedit-io-error-message-area.c b/gedit/gedit-io-error-message-area.c
index 2204d44..2b79eff 100644
--- a/gedit/gedit-io-error-message-area.c
+++ b/gedit/gedit-io-error-message-area.c
@@ -43,7 +43,6 @@
 #include <gio/gio.h>
 
 #include "gedit-utils.h"
-#include "gedit-convert.h"
 #include "gedit-document.h"
 #include "gedit-io-error-message-area.h"
 #include "gedit-prefs-manager.h"
@@ -612,8 +611,7 @@ gedit_io_loading_error_message_area_new (const gchar         *uri,
 	g_return_val_if_fail (uri != NULL, NULL);
 	g_return_val_if_fail (error != NULL, NULL);
 	g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) ||
-			      (error->domain == GEDIT_CONVERT_ERROR) ||
-			      (error->domain == GEDIT_DOCUMENT_ERROR) || 
+			      (error->domain == GEDIT_DOCUMENT_ERROR) ||
 			      (error->domain == G_IO_ERROR), NULL);
 	
 	full_formatted_uri = gedit_utils_uri_for_display (uri);
@@ -643,8 +641,8 @@ gedit_io_loading_error_message_area_new (const gchar         *uri,
 		message_details = g_strdup (_("You do not have the permissions necessary to open the file."));
 	}
 	else if ((is_gio_error (error, G_IO_ERROR_INVALID_DATA) && encoding == NULL) ||
-	         (error->domain == GEDIT_CONVERT_ERROR &&
-	         error->code == GEDIT_CONVERT_ERROR_AUTO_DETECTION_FAILED))
+	         (error->domain == GEDIT_DOCUMENT_ERROR &&
+	         error->code == GEDIT_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED))
 	{
 		error_message = g_strdup_printf (_("Could not open the file %s."),
 						 uri_for_display);
diff --git a/gedit/gedit-smart-charset-converter.c b/gedit/gedit-smart-charset-converter.c
index 593830c..2f44daf 100644
--- a/gedit/gedit-smart-charset-converter.c
+++ b/gedit/gedit-smart-charset-converter.c
@@ -22,12 +22,11 @@
 
 #include "gedit-smart-charset-converter.h"
 #include "gedit-debug.h"
+#include "gedit-document.h"
 
 #include <gio/gio.h>
 #include <glib/gi18n.h>
 
-#include "gedit-convert.h"
-
 #define GEDIT_SMART_CHARSET_CONVERTER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_SMART_CHARSET_CONVERTER, GeditSmartCharsetConverterPrivate))
 
 struct _GeditSmartCharsetConverterPrivate
@@ -304,7 +303,8 @@ gedit_smart_charset_converter_convert (GConverter *converter,
 		    !smart->priv->is_utf8)
 		{
 			/* FIXME: Add a different domain when we kill gedit_convert */
-			g_set_error_literal (error, GEDIT_CONVERT_ERROR, GEDIT_CONVERT_ERROR_AUTO_DETECTION_FAILED,
+			g_set_error_literal (error, GEDIT_DOCUMENT_ERROR,
+					     GEDIT_DOCUMENT_ERROR_ENCODING_AUTO_DETECTION_FAILED,
 					     _("It is not possible to detect the encoding automatically"));
 			return G_CONVERTER_ERROR;
 		}
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 5789033..87d6c8c 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -43,7 +43,6 @@
 #include "gedit-progress-message-area.h"
 #include "gedit-debug.h"
 #include "gedit-prefs-manager-app.h"
-#include "gedit-convert.h"
 #include "gedit-enum-types.h"
 
 #if !GTK_CHECK_VERSION (2, 17, 1)
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index e522b17..776e1c5 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -50,7 +50,6 @@
 #include "gedit-document.h"
 #include "gedit-prefs-manager.h"
 #include "gedit-debug.h"
-#include "gedit-convert.h"
 
 /* For the workspace/viewport stuff */
 #ifdef GDK_WINDOWING_X11



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