gedit r6351 - in trunk: . gedit



Author: jessevdk
Date: Wed Aug  6 17:45:35 2008
New Revision: 6351
URL: http://svn.gnome.org/viewvc/gedit?rev=6351&view=rev

Log:
	* gedit/gedit-tab.c:
	* gedit/gedit-gnomevfs-document-saver.c:
	* gedit/gedit-document-loader.c:
	* gedit/gedit-local-document-saver.c:
	* gedit/gedit-document-loader.h:
	* gedit/gedit-utils.c:
	* gedit/gedit-utils.h:
	* gedit/gedit-file-chooser-dialog.c:
	* gedit/gedit-io-error-message-area.c:
	* gedit/gedit-window.c:
	* gedit/gedit-mmap-document-loader.c:
	* gedit/gedit-document.c:
	* gedit/gedit-document.h:
	* gedit/gedit-gnomevfs-document-loader.c:
	* gedit/gedit-commands-file.c:
	* gedit/gedit-language-manager.c:
	* gedit/gedit-document-saver.c:
	* gedit/gedit-document-saver.h:
	* configure.ac:
	
	Implemented phase 1 of porting gedit to gio. This first phase includes
	small pieces of gnome-vfs and libgnomeui to be ported to gio. This
	includes mime type information, looking up icons, handling uri's
	and replacing gnome-vfs types like GnomeVFSFileSize.


Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/gedit/gedit-commands-file.c
   trunk/gedit/gedit-document-loader.c
   trunk/gedit/gedit-document-loader.h
   trunk/gedit/gedit-document-saver.c
   trunk/gedit/gedit-document-saver.h
   trunk/gedit/gedit-document.c
   trunk/gedit/gedit-document.h
   trunk/gedit/gedit-file-chooser-dialog.c
   trunk/gedit/gedit-gnomevfs-document-loader.c
   trunk/gedit/gedit-gnomevfs-document-saver.c
   trunk/gedit/gedit-io-error-message-area.c
   trunk/gedit/gedit-language-manager.c
   trunk/gedit/gedit-local-document-saver.c
   trunk/gedit/gedit-mmap-document-loader.c
   trunk/gedit/gedit-tab.c
   trunk/gedit/gedit-utils.c
   trunk/gedit/gedit-utils.h
   trunk/gedit/gedit-window.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Wed Aug  6 17:45:35 2008
@@ -163,8 +163,8 @@
 dnl ================================================================
 
 PKG_CHECK_MODULES(GEDIT, [
-	glib-2.0 >= 2.14.0
-	gtk+-2.0 >= 2.12.0
+	glib-2.0 >= 2.13.0
+	gtk+-2.0 >= 2.13.0
 	gtksourceview-2.0 >= 2.2.0
 	libgnomeui-2.0 >= 2.16.0
 	libglade-2.0 >= 2.5.1

Modified: trunk/gedit/gedit-commands-file.c
==============================================================================
--- trunk/gedit/gedit-commands-file.c	(original)
+++ trunk/gedit/gedit-commands-file.c	Wed Aug  6 17:45:35 2008
@@ -704,7 +704,7 @@
 		doc = gedit_tab_get_document (tab);
 		g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
 
-		uri_for_display = gedit_utils_format_uri_for_display (uri);
+		uri_for_display = gedit_utils_uri_for_display (uri);
 
 		gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
 					        window->priv->generic_message_cid,

Modified: trunk/gedit/gedit-document-loader.c
==============================================================================
--- trunk/gedit/gedit-document-loader.c	(original)
+++ trunk/gedit/gedit-document-loader.c	Wed Aug  6 17:45:35 2008
@@ -433,7 +433,7 @@
 }
 
 /* Returns 0 if file size is unknown */
-GnomeVFSFileSize
+goffset
 gedit_document_loader_get_file_size (GeditDocumentLoader *loader)
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), 0);
@@ -441,7 +441,7 @@
 	return GEDIT_DOCUMENT_LOADER_GET_CLASS (loader)->get_file_size (loader);
 }
 
-GnomeVFSFileSize
+goffset
 gedit_document_loader_get_bytes_read (GeditDocumentLoader *loader)
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), 0);

Modified: trunk/gedit/gedit-document-loader.h
==============================================================================
--- trunk/gedit/gedit-document-loader.h	(original)
+++ trunk/gedit/gedit-document-loader.h	Wed Aug  6 17:45:35 2008
@@ -88,8 +88,8 @@
 	gboolean		(* cancel)		(GeditDocumentLoader *loader);
 	const gchar *		(* get_mime_type)	(GeditDocumentLoader *loader);
 	time_t			(* get_mtime)		(GeditDocumentLoader *loader);
-	GnomeVFSFileSize	(* get_file_size)	(GeditDocumentLoader *loader);
-	GnomeVFSFileSize	(* get_bytes_read)	(GeditDocumentLoader *loader);
+	goffset			(* get_file_size)	(GeditDocumentLoader *loader);
+	goffset			(* get_bytes_read)	(GeditDocumentLoader *loader);
 	gboolean		(* get_readonly)	(GeditDocumentLoader *loader);
 };
 
@@ -134,10 +134,10 @@
 const GeditEncoding	*gedit_document_loader_get_encoding	(GeditDocumentLoader *loader);
 
 /* Returns 0 if file size is unknown */
-/* FIXME: change GnomeVFSFileSize to what glib provides. */
-GnomeVFSFileSize	 gedit_document_loader_get_file_size	(GeditDocumentLoader *loader);
+/* FIXME: change goffset to what glib provides. */
+goffset	 gedit_document_loader_get_file_size	(GeditDocumentLoader *loader);
 
-GnomeVFSFileSize	 gedit_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
+goffset	 gedit_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
 
 
 G_END_DECLS

Modified: trunk/gedit/gedit-document-saver.c
==============================================================================
--- trunk/gedit/gedit-document-saver.c	(original)
+++ trunk/gedit/gedit-document-saver.c	Wed Aug  6 17:45:35 2008
@@ -446,7 +446,7 @@
 }
 
 /* Returns 0 if file size is unknown */
-GnomeVFSFileSize
+goffset
 gedit_document_saver_get_file_size (GeditDocumentSaver *saver)
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver), 0);
@@ -454,7 +454,7 @@
 	return GEDIT_DOCUMENT_SAVER_GET_CLASS (saver)->get_file_size (saver);
 }
 
-GnomeVFSFileSize
+goffset
 gedit_document_saver_get_bytes_written (GeditDocumentSaver *saver)
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver), 0);

Modified: trunk/gedit/gedit-document-saver.h
==============================================================================
--- trunk/gedit/gedit-document-saver.h	(original)
+++ trunk/gedit/gedit-document-saver.h	Wed Aug  6 17:45:35 2008
@@ -89,8 +89,8 @@
 							 time_t              old_mtime);
 	const gchar *		(* get_mime_type)	(GeditDocumentSaver *saver);
 	time_t			(* get_mtime)		(GeditDocumentSaver *saver);
-	GnomeVFSFileSize	(* get_file_size)	(GeditDocumentSaver *saver);
-	GnomeVFSFileSize	(* get_bytes_written)	(GeditDocumentSaver *saver);
+	goffset			(* get_file_size)	(GeditDocumentSaver *saver);
+	goffset			(* get_bytes_written)	(GeditDocumentSaver *saver);
 };
 
 /*
@@ -131,9 +131,9 @@
 time_t			 gedit_document_saver_get_mtime		(GeditDocumentSaver  *saver);
 
 /* Returns 0 if file size is unknown */
-GnomeVFSFileSize	 gedit_document_saver_get_file_size	(GeditDocumentSaver  *saver);
+goffset	 gedit_document_saver_get_file_size	(GeditDocumentSaver  *saver);
 
-GnomeVFSFileSize	 gedit_document_saver_get_bytes_written	(GeditDocumentSaver  *saver);
+goffset	 gedit_document_saver_get_bytes_written	(GeditDocumentSaver  *saver);
 
 
 G_END_DECLS

Modified: trunk/gedit/gedit-document.c
==============================================================================
--- trunk/gedit/gedit-document.c	(original)
+++ trunk/gedit/gedit-document.c	Wed Aug  6 17:45:35 2008
@@ -38,7 +38,6 @@
 #include <stdlib.h>
 
 #include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs.h>
 #include <gtksourceview/gtksourceiter.h>
 
 #include "gedit-prefs-manager-app.h"
@@ -108,8 +107,6 @@
 	gchar	    *uri;
 	gint 	     untitled_number;
 
-	GnomeVFSURI *vfs_uri;
-
 	const GeditEncoding *encoding;
 
 	gchar	    *mime_type;
@@ -277,9 +274,6 @@
 	}
 
 	g_free (doc->priv->uri);
-	if (doc->priv->vfs_uri != NULL)
-		gnome_vfs_uri_unref (doc->priv->vfs_uri);
-
 	g_free (doc->priv->mime_type);
 	g_free (doc->priv->search_text);
 
@@ -688,7 +682,6 @@
 	doc->priv = GEDIT_DOCUMENT_GET_PRIVATE (doc);
 
 	doc->priv->uri = NULL;
-	doc->priv->vfs_uri = NULL;
 	doc->priv->untitled_number = get_untitled_number ();
 
 	doc->priv->mime_type = g_strdup ("text/plain");
@@ -760,13 +753,6 @@
 		g_free (doc->priv->uri);
 		doc->priv->uri = g_strdup (uri);
 
-		if (doc->priv->vfs_uri != NULL)
-			gnome_vfs_uri_unref (doc->priv->vfs_uri);
-
-		/* Note: vfs_uri may be NULL for some valid but
-		 * unsupported uris */
-		doc->priv->vfs_uri = gnome_vfs_uri_new (uri);
-
 		if (doc->priv->untitled_number > 0)
 		{
 			release_untitled_number (doc->priv->untitled_number);
@@ -781,23 +767,16 @@
 	}
 	else
 	{
-		gchar *base_name = NULL;
-
-		/* Guess the mime type from file extension or fallback to "text/plain" */
-		if (doc->priv->vfs_uri != NULL)
-			base_name = gnome_vfs_uri_extract_short_path_name (doc->priv->vfs_uri);
-		if (base_name != NULL)
+		if (doc->priv->uri != NULL)
 		{
 			const gchar *detected_mime;
 
-			detected_mime = gnome_vfs_get_mime_type_for_name (base_name);
-			if (detected_mime == NULL ||
-			    strcmp (GNOME_VFS_MIME_TYPE_UNKNOWN, detected_mime) == 0)
+			detected_mime = g_content_type_guess (doc->priv->uri, NULL, 0, NULL);
+
+			if (detected_mime == NULL || g_content_type_is_unknown (detected_mime))
 				detected_mime = "text/plain";
 
 			doc->priv->mime_type = g_strdup (detected_mime);
-
-			g_free (base_name);
 		}
 		else
 		{
@@ -879,89 +858,8 @@
 	if (doc->priv->uri == NULL)
 		return g_strdup_printf (_("Unsaved Document %d"),
 					doc->priv->untitled_number);
-	else if (doc->priv->vfs_uri == NULL)
-		return gnome_vfs_format_uri_for_display (doc->priv->uri);
 	else
-	{	
-		gchar *name;
-		gchar *uri_for_display;
-		
-		name = gnome_vfs_uri_to_string (doc->priv->vfs_uri, GNOME_VFS_URI_HIDE_PASSWORD);
-		g_return_val_if_fail (name != NULL, gnome_vfs_format_uri_for_display (doc->priv->uri));
-		
-		uri_for_display = gnome_vfs_format_uri_for_display (name);
-		g_free (name);
-		
-		return uri_for_display;
-	}
-}
-
-/* move to gedit-utils? */
-static gchar *
-get_uri_shortname_for_display (GnomeVFSURI *uri)
-{
-	gchar *name;	
-	gboolean  validated;
-
-	validated = FALSE;
-
-	name = gnome_vfs_uri_extract_short_name (uri);
-	
-	if (name == NULL)
-	{
-		name = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
-	}
-	else if (g_ascii_strcasecmp (uri->method_string, "file") == 0)
-	{
-		gchar *text_uri;
-		gchar *local_file;
-		text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
-		local_file = gnome_vfs_get_local_path_from_uri (text_uri);
-
-		if (local_file != NULL)
-		{
-			g_free (name);
-			name = g_filename_display_basename (local_file);
-			validated = TRUE;
-		}
-
-		g_free (local_file);
-		g_free (text_uri);
-	} 
-	else if (!gnome_vfs_uri_has_parent (uri)) 
-	{
-		const gchar *method;
-
-		method = uri->method_string;
-
-		if (name == NULL ||
-		    strcmp (name, GNOME_VFS_URI_PATH_STR) == 0) 
-		{
-			g_free (name);
-			name = g_strdup (method);
-		} 
-		/*
-		else 
-		{
-			gchar *tmp;
-
-			tmp = name;
-			name = g_strdup_printf ("%s: %s", method, name);
-			g_free (tmp);
-		}
-		*/
-	}
-
-	if (!validated && !g_utf8_validate (name, -1, NULL)) 
-	{
-		gchar *utf8_name;
-
-		utf8_name = gedit_utils_make_valid_utf8 (name);
-		g_free (name);
-		name = utf8_name;
-	}
-
-	return name;
+		return gedit_utils_uri_for_display (doc->priv->uri);
 }
 
 /* Never returns NULL */
@@ -973,10 +871,8 @@
 	if (doc->priv->uri == NULL)
 		return g_strdup_printf (_("Unsaved Document %d"),
 					doc->priv->untitled_number);	      
-	else if (doc->priv->vfs_uri == NULL)
-		return g_strdup (doc->priv->uri);
 	else
-		return get_uri_shortname_for_display (doc->priv->vfs_uri);
+		return gedit_utils_basename_for_display (doc->priv->uri);
 }
 
 /* Never returns NULL */
@@ -1028,9 +924,8 @@
 gboolean
 _gedit_document_check_externally_modified (GeditDocument *doc)
 {
-	GnomeVFSFileInfo *info;
-	GnomeVFSResult result;
-	gboolean res = FALSE;
+	GFile *gfile;
+	GFileInfo *info;
 
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
 
@@ -1039,27 +934,20 @@
 		return FALSE;
 	}
 
-	info = gnome_vfs_file_info_new ();
-
-	result = gnome_vfs_get_file_info_uri (doc->priv->vfs_uri,
-					      info,
-					      GNOME_VFS_FILE_INFO_DEFAULT|
-					      GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
-	if (result != GNOME_VFS_OK)
+	gfile = g_file_new_for_uri (doc->priv->uri);
+	info = g_file_query_info (gfile, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+	g_object_unref (gfile);
+	
+	if (info == NULL)
 	{
-		gnome_vfs_file_info_unref (info);
-
 		return FALSE;
 	}
 
-	if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MTIME)
-	{
-		res = info->mtime > doc->priv->mtime;
-	}
-
-	gnome_vfs_file_info_unref (info);
-
-	return res;
+	GTimeVal timeval;
+	g_file_info_get_modification_time (info, &timeval);
+	g_object_unref (info);
+	
+	return timeval.tv_sec > doc->priv->mtime;
 }
 
 static void
@@ -1178,8 +1066,8 @@
 	}
 	else
 	{
-		GnomeVFSFileSize size;
-		GnomeVFSFileSize read;
+		goffset size;
+		goffset read;
 
 		size = gedit_document_loader_get_file_size (loader);
 		read = gedit_document_loader_get_bytes_read (loader);
@@ -1299,8 +1187,8 @@
 	}
 	else
 	{
-		GnomeVFSFileSize size = 0;
-		GnomeVFSFileSize written = 0;
+		goffset size = 0;
+		goffset written = 0;
 
 		size = gedit_document_saver_get_file_size (saver);
 		written = gedit_document_saver_get_bytes_written (saver);
@@ -1441,10 +1329,7 @@
 {
 	g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
 
-	if (doc->priv->uri == NULL || doc->priv->vfs_uri == NULL)
-		return FALSE;
-		
-	return !gnome_vfs_uri_exists (doc->priv->vfs_uri);
+	return doc->priv->uri && !gedit_utils_uri_exists (doc->priv->uri);
 }
 
 /*

Modified: trunk/gedit/gedit-document.h
==============================================================================
--- trunk/gedit/gedit-document.h	(original)
+++ trunk/gedit/gedit-document.h	Wed Aug  6 17:45:35 2008
@@ -110,8 +110,8 @@
 					 gboolean             create);
 
 	void (* loading)		(GeditDocument    *document,
-					 GnomeVFSFileSize  size,
-					 GnomeVFSFileSize  total_size);
+					 goffset	   size,
+					 goffset	   total_size);
 
 	void (* loaded)			(GeditDocument    *document,
 					 const GError     *error);
@@ -123,8 +123,8 @@
 					 GeditDocumentSaveFlags  flags);
 
 	void (* saving)			(GeditDocument    *document,
-					 GnomeVFSFileSize  size,
-					 GnomeVFSFileSize  total_size);
+					 goffset	   size,
+					 goffset	   total_size);
 
 	void (* saved)  		(GeditDocument    *document,
 					 const GError     *error);

Modified: trunk/gedit/gedit-file-chooser-dialog.c
==============================================================================
--- trunk/gedit/gedit-file-chooser-dialog.c	(original)
+++ trunk/gedit/gedit-file-chooser-dialog.c	Wed Aug  6 17:45:35 2008
@@ -39,7 +39,6 @@
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
 
 #include "gedit-file-chooser-dialog.h"
 #include "gedit-encodings-option-menu.h"
@@ -184,12 +183,7 @@
 
 			for (i = 0; mime_types[i] != NULL; i++)
 			{
-				GnomeVFSMimeEquivalence res;
-
-				res = gnome_vfs_mime_type_get_equivalence (mime_types[i],
-									   "text/plain");
-
-				if (res == GNOME_VFS_MIME_UNRELATED)
+				if (!g_content_type_is_a (mime_types[i], "text/plain"))
 				{
 					gedit_debug_message (DEBUG_COMMANDS,
 							     "Mime-type %s is not related to text/plain",
@@ -226,11 +220,7 @@
 	mime_types = known_mime_types;
 	while (mime_types != NULL)
 	{
-		GnomeVFSMimeEquivalence res;
-		res = gnome_vfs_mime_type_get_equivalence (filter_info->mime_type,
-							   (const gchar*)mime_types->data);
-
-		if (res != GNOME_VFS_MIME_UNRELATED)
+		if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data))
 			return TRUE;
 
 		mime_types = g_slist_next (mime_types);

Modified: trunk/gedit/gedit-gnomevfs-document-loader.c
==============================================================================
--- trunk/gedit/gedit-gnomevfs-document-loader.c	(original)
+++ trunk/gedit/gedit-gnomevfs-document-loader.c	Wed Aug  6 17:45:35 2008
@@ -53,8 +53,8 @@
 static gboolean		 gedit_gnomevfs_document_loader_cancel		(GeditDocumentLoader *loader);
 static const gchar	*gedit_gnomevfs_document_loader_get_mime_type	(GeditDocumentLoader *loader);
 static time_t		 gedit_gnomevfs_document_loader_get_mtime	(GeditDocumentLoader *loader);
-static GnomeVFSFileSize	 gedit_gnomevfs_document_loader_get_file_size	(GeditDocumentLoader *loader);
-static GnomeVFSFileSize	 gedit_gnomevfs_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
+static goffset		 gedit_gnomevfs_document_loader_get_file_size	(GeditDocumentLoader *loader);
+static goffset		 gedit_gnomevfs_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
 static gboolean		 gedit_gnomevfs_document_loader_get_readonly	(GeditDocumentLoader *loader);
 
 
@@ -178,8 +178,8 @@
 async_read_cb (GnomeVFSAsyncHandle         *handle,
 	       GnomeVFSResult               result,
 	       gpointer                     buffer,
-	       GnomeVFSFileSize             bytes_requested,
-	       GnomeVFSFileSize             bytes_read,
+	       GnomeVFSFileSize	            bytes_requested,
+	       GnomeVFSFileSize	            bytes_read,
 	       GeditGnomeVFSDocumentLoader *gvloader)
 {
 	gedit_debug (DEBUG_LOADER);
@@ -436,18 +436,18 @@
 }
 
 /* Returns 0 if file size is unknown */
-static GnomeVFSFileSize
+static goffset
 gedit_gnomevfs_document_loader_get_file_size (GeditDocumentLoader *loader)
 {
 	GeditGnomeVFSDocumentLoader *gvloader = GEDIT_GNOMEVFS_DOCUMENT_LOADER (loader);
 
 	if (gvloader->priv->info == NULL)
-		return (GnomeVFSFileSize) 0;
+		return (goffset) 0;
 
-	return (GnomeVFSFileSize) gvloader->priv->info->size;
+	return (goffset) gvloader->priv->info->size;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_gnomevfs_document_loader_get_bytes_read (GeditDocumentLoader *loader)
 {
 	return GEDIT_GNOMEVFS_DOCUMENT_LOADER (loader)->priv->bytes_read;

Modified: trunk/gedit/gedit-gnomevfs-document-saver.c
==============================================================================
--- trunk/gedit/gedit-gnomevfs-document-saver.c	(original)
+++ trunk/gedit/gedit-gnomevfs-document-saver.c	Wed Aug  6 17:45:35 2008
@@ -46,8 +46,8 @@
 										 time_t              old_mtime);
 static const gchar 	*gedit_gnomevfs_document_saver_get_mime_type		(GeditDocumentSaver *saver);
 static time_t		 gedit_gnomevfs_document_saver_get_mtime		(GeditDocumentSaver *saver);
-static GnomeVFSFileSize	 gedit_gnomevfs_document_saver_get_file_size		(GeditDocumentSaver *saver);
-static GnomeVFSFileSize	 gedit_gnomevfs_document_saver_get_bytes_written	(GeditDocumentSaver *saver);
+static goffset		 gedit_gnomevfs_document_saver_get_file_size		(GeditDocumentSaver *saver);
+static goffset		 gedit_gnomevfs_document_saver_get_bytes_written	(GeditDocumentSaver *saver);
 
 struct _GeditGnomeVFSDocumentSaverPrivate
 {
@@ -526,13 +526,13 @@
 	return GEDIT_GNOMEVFS_DOCUMENT_SAVER (saver)->priv->doc_mtime;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_gnomevfs_document_saver_get_file_size (GeditDocumentSaver *saver)
 {
 	return GEDIT_GNOMEVFS_DOCUMENT_SAVER (saver)->priv->size;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_gnomevfs_document_saver_get_bytes_written (GeditDocumentSaver *saver)
 {
 	return GEDIT_GNOMEVFS_DOCUMENT_SAVER (saver)->priv->bytes_written;

Modified: trunk/gedit/gedit-io-error-message-area.c
==============================================================================
--- trunk/gedit/gedit-io-error-message-area.c	(original)
+++ trunk/gedit/gedit-io-error-message-area.c	Wed Aug  6 17:45:35 2008
@@ -166,7 +166,7 @@
 	g_return_val_if_fail (error != NULL, NULL);
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -417,7 +417,7 @@
 	g_return_val_if_fail (error != NULL, NULL);
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -751,7 +751,7 @@
 	g_return_val_if_fail ((error->domain == G_CONVERT_ERROR) ||
 			      (error->domain == GEDIT_CONVERT_ERROR), NULL);
 	
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -819,7 +819,7 @@
 	g_return_val_if_fail (error->domain == G_CONVERT_ERROR, NULL);
 	g_return_val_if_fail (encoding != NULL, NULL);
 	
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -885,7 +885,7 @@
        	gchar *uri_for_display;
        	gchar *temp_uri_for_display;
 	
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -976,7 +976,7 @@
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
 	g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -1071,7 +1071,7 @@
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
 	g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -1166,7 +1166,7 @@
 	g_return_val_if_fail (error != NULL, NULL);
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain
@@ -1409,7 +1409,7 @@
 
 	g_return_val_if_fail (uri != NULL, NULL);
 
-	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
+	full_formatted_uri = gedit_utils_uri_for_display (uri);
 
 	/* Truncate the URI so it doesn't get insanely wide. Note that even
 	 * though the dialog uses wrapped text, if the URI doesn't contain

Modified: trunk/gedit/gedit-language-manager.c
==============================================================================
--- trunk/gedit/gedit-language-manager.c	(original)
+++ trunk/gedit/gedit-language-manager.c	Wed Aug  6 17:45:35 2008
@@ -177,15 +177,7 @@
 
 		for (i = 0; mime_types[i] != NULL; ++i)
 		{
-			GnomeVFSMimeEquivalence res;
-
-			/* Use gnome_vfs_mime_type_get_equivalence instead of
-			 * strcmp, to take care of mime-types inheritance
-			 * (see bug #324191) */
-			res = gnome_vfs_mime_type_get_equivalence (mime_type, 
-								   mime_types[i]);
-
-			if (res == GNOME_VFS_MIME_IDENTICAL)
+			if (g_content_type_equals(mime_type, mime_types[i]))
 			{
 				/* If the mime-type of lang is identical to "mime-type" then
 				   return lang */
@@ -197,7 +189,7 @@
 
 				break;
 			}
-			else if ((res == GNOME_VFS_MIME_PARENT) && (parent == NULL))
+			else if (parent == NULL && g_content_type_is_a (mime_type, mime_types[i]))
 			{
 				/* If the mime-type of lang is a parent of "mime-type" then
 				   remember it. We will return it if we don't find

Modified: trunk/gedit/gedit-local-document-saver.c
==============================================================================
--- trunk/gedit/gedit-local-document-saver.c	(original)
+++ trunk/gedit/gedit-local-document-saver.c	Wed Aug  6 17:45:35 2008
@@ -61,22 +61,22 @@
 									 time_t              old_mtime);
 static const gchar 	*gedit_local_document_saver_get_mime_type	(GeditDocumentSaver *saver);
 static time_t		 gedit_local_document_saver_get_mtime		(GeditDocumentSaver *saver);
-static GnomeVFSFileSize	 gedit_local_document_saver_get_file_size	(GeditDocumentSaver *saver);
-static GnomeVFSFileSize	 gedit_local_document_saver_get_bytes_written	(GeditDocumentSaver *saver);
+static goffset		 gedit_local_document_saver_get_file_size	(GeditDocumentSaver *saver);
+static goffset		 gedit_local_document_saver_get_bytes_written	(GeditDocumentSaver *saver);
 
 
 struct _GeditLocalDocumentSaverPrivate
 {
-	GnomeVFSFileSize	  size;
-	GnomeVFSFileSize	  bytes_written;
+	goffset	  size;
+	goffset	  bytes_written;
 
 	/* temp data for local files */
-	gint			  fd;
-	gchar			 *local_path;
-	gchar                    *mime_type; //CHECK use FileInfo instead?
-	time_t                    doc_mtime;
+	gint	  fd;
+	gchar	 *local_path;
+	gchar    *mime_type; //CHECK use FileInfo instead?
+	time_t    doc_mtime;
 
-	GError                   *error;
+	GError   *error;
 };
 
 G_DEFINE_TYPE(GeditLocalDocumentSaver, gedit_local_document_saver, GEDIT_TYPE_DOCUMENT_SAVER)
@@ -873,13 +873,13 @@
 	return GEDIT_LOCAL_DOCUMENT_SAVER (saver)->priv->doc_mtime;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_local_document_saver_get_file_size (GeditDocumentSaver *saver)
 {
 	return GEDIT_LOCAL_DOCUMENT_SAVER (saver)->priv->size;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_local_document_saver_get_bytes_written (GeditDocumentSaver *saver)
 {
 	return GEDIT_LOCAL_DOCUMENT_SAVER (saver)->priv->bytes_written;

Modified: trunk/gedit/gedit-mmap-document-loader.c
==============================================================================
--- trunk/gedit/gedit-mmap-document-loader.c	(original)
+++ trunk/gedit/gedit-mmap-document-loader.c	Wed Aug  6 17:45:35 2008
@@ -64,24 +64,24 @@
 static gboolean		 gedit_mmap_document_loader_cancel		(GeditDocumentLoader *loader);
 static const gchar	*gedit_mmap_document_loader_get_mime_type	(GeditDocumentLoader *loader);
 static time_t		 gedit_mmap_document_loader_get_mtime		(GeditDocumentLoader *loader);
-static GnomeVFSFileSize	 gedit_mmap_document_loader_get_file_size	(GeditDocumentLoader *loader);
-static GnomeVFSFileSize	 gedit_mmap_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
+static goffset		 gedit_mmap_document_loader_get_file_size	(GeditDocumentLoader *loader);
+static goffset		 gedit_mmap_document_loader_get_bytes_read	(GeditDocumentLoader *loader);
 static gboolean		 gedit_mmap_document_loader_get_readonly	(GeditDocumentLoader *loader);
 
 struct _GeditMmapDocumentLoaderPrivate
 {
-	struct stat       statbuf;
-	gchar            *mime_type;
-	guint             statbuf_filled : 1;
+	struct stat statbuf;
+	gchar      *mime_type;
+	guint       statbuf_filled : 1;
 
-	GnomeVFSFileSize  bytes_read;
+	goffset     bytes_read;
 
-	gint              fd;
-	gchar            *local_file_name;
+	gint        fd;
+	gchar      *local_file_name;
 
-	gchar            *buffer;
+	gchar      *buffer;
 
-	GError           *error;
+	GError     *error;
 };
 
 G_DEFINE_TYPE(GeditMmapDocumentLoader, gedit_mmap_document_loader, GEDIT_TYPE_DOCUMENT_LOADER)
@@ -398,17 +398,17 @@
 	return mloader->priv->statbuf.st_mtime;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_mmap_document_loader_get_file_size (GeditDocumentLoader *loader)
 {
 	GeditMmapDocumentLoader *mloader = GEDIT_MMAP_DOCUMENT_LOADER (loader);
 
 	if (!mloader->priv->statbuf_filled)
-		return (GnomeVFSFileSize) 0;
-	return (GnomeVFSFileSize) mloader->priv->statbuf.st_size;
+		return (goffset) 0;
+	return (goffset) mloader->priv->statbuf.st_size;
 }
 
-static GnomeVFSFileSize
+static goffset
 gedit_mmap_document_loader_get_bytes_read (GeditDocumentLoader *loader)
 {
 	return GEDIT_MMAP_DOCUMENT_LOADER (loader)->priv->bytes_read;

Modified: trunk/gedit/gedit-tab.c
==============================================================================
--- trunk/gedit/gedit-tab.c	(original)
+++ trunk/gedit/gedit-tab.c	Wed Aug  6 17:45:35 2008
@@ -31,10 +31,7 @@
 #endif
 
 #include <glib/gi18n.h>
-
-#include <libgnomeui/libgnomeui.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <gio/gio.h>
 
 #include "gedit-app.h"
 #include "gedit-notebook.h"
@@ -753,7 +750,7 @@
 
 		from = short_name;
 
-		to = gedit_utils_format_uri_for_display (tab->priv->tmp_save_uri);
+		to = gedit_utils_uri_for_display (tab->priv->tmp_save_uri);
 
 		str = gedit_utils_str_middle_truncate (to, 
 						       MAX (20, MAX_MSG_LENGTH - len));
@@ -795,9 +792,9 @@
 }
 
 static void
-message_area_set_progress (GeditTab	    *tab,
-			   GnomeVFSFileSize  size,
-			   GnomeVFSFileSize  total_size)
+message_area_set_progress (GeditTab *tab,
+			   goffset   size,
+			   goffset   total_size)
 {
 	if (tab->priv->message_area == NULL)
 		return;
@@ -829,10 +826,10 @@
 }
 
 static void
-document_loading (GeditDocument    *document,
-		  GnomeVFSFileSize  size,
-		  GnomeVFSFileSize  total_size,
-		  GeditTab         *tab)
+document_loading (GeditDocument *document,
+		  goffset        size,
+		  goffset        total_size,
+		  GeditTab      *tab)
 {
 	double et;
 
@@ -899,6 +896,7 @@
 {
 	GtkWidget *emsg;
 	gchar *uri;
+	GFile *location;
 	const GeditEncoding *encoding;
 
 	g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_LOADING) ||
@@ -915,6 +913,7 @@
 	set_message_area (tab, NULL);
 
 	uri = gedit_document_get_uri (document);
+	location = gedit_document_get_location (document);
 
 	if (error != NULL)
 	{
@@ -1016,12 +1015,12 @@
 			
 			if (d != document)
 			{
-				gchar *u;
+				GFile *loc;
 
-				u = gedit_document_get_uri (d);
+				loc = gedit_document_get_location (d);
 
-				if ((u != NULL) &&
-			    	    gnome_vfs_uris_match (uri, u))
+				if ((loc != NULL) &&
+			    	    g_file_equal (location, loc))
 			    	{
 			    		GtkWidget *w;
 			    		GeditView *view;
@@ -1044,12 +1043,11 @@
 							  G_CALLBACK (file_already_open_warning_message_area_response),
 							  tab);
 
-					g_free (u);
-
+			    		g_object_unref (loc);
 			    		break;
 			    	}
 
-				g_free (u);
+				g_object_unref (loc);
 			}
 		}
 
@@ -1071,8 +1069,8 @@
 
 static void
 document_saving (GeditDocument    *document,
-		 GnomeVFSFileSize  size,
-		 GnomeVFSFileSize  total_size,
+		 goffset  size,
+		 goffset  total_size,
 		 GeditTab         *tab)
 {
 	double et;
@@ -1700,7 +1698,7 @@
 			break;			
 		default:
 			mime_type = gedit_document_get_mime_type (doc);
-			mime_description = gnome_vfs_mime_get_description (mime_type);
+			mime_description = g_content_type_get_description (mime_type);
 
 			if (mime_description == NULL)
 				mime_full_description = g_strdup (mime_type);
@@ -1773,22 +1771,13 @@
 }
 
 static GdkPixbuf *
-get_icon (GtkIconTheme *theme, 
-	  const gchar  *uri,
-	  const gchar  *mime_type, 
-	  gint          size)
+get_stock_icon (GtkIconTheme *theme, 
+		const gchar  *stock,
+		gint          size)
 {
-	gchar *icon;
 	GdkPixbuf *pixbuf;
 	
-	icon = gnome_icon_lookup (theme, NULL, uri, NULL, NULL,
-				  mime_type, 0, NULL);
-	
-
-	g_return_val_if_fail (icon != NULL, NULL);
-
-	pixbuf = gtk_icon_theme_load_icon (theme, icon, size, 0, NULL);
-	g_free (icon);
+	pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL);
 	if (pixbuf == NULL)
 		return NULL;
 		
@@ -1796,15 +1785,45 @@
 }
 
 static GdkPixbuf *
-get_stock_icon (GtkIconTheme *theme, 
-		const gchar  *stock,
-		gint          size)
+get_icon (GtkIconTheme *theme, 
+	  GFile        *location,
+	  gint          size)
 {
 	GdkPixbuf *pixbuf;
+	GtkIconInfo *icon_info;
+	GFileInfo *info;
+	GIcon *gicon;
 	
-	pixbuf = gtk_icon_theme_load_icon (theme, stock, size, 0, NULL);
-	if (pixbuf == NULL)
-		return NULL;
+	if (!location)
+		return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+	/* FIXME: Doing a sync stat is bad, this should be fixed */
+	info = g_file_query_info (location, 
+	                          G_FILE_ATTRIBUTE_STANDARD_ICON, 
+	                          G_FILE_QUERY_INFO_NONE, 
+	                          NULL, 
+	                          NULL);
+	
+	if (!info)
+		return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+	gicon = g_file_info_get_icon (info);
+	g_object_unref (info);
+	
+	if (!gicon)
+		return get_stock_icon (theme, GTK_STOCK_FILE, size);
+
+	icon_info = gtk_icon_theme_lookup_by_gicon (theme, gicon, size, 0);
+	g_object_unref (gicon);
+	
+	if (!icon_info)
+		return get_stock_icon (theme, GTK_STOCK_FILE, size);
+	
+	pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+	gtk_icon_info_free (icon_info);
+	
+	if (!pixbuf)
+		return get_stock_icon (theme, GTK_STOCK_FILE, size);
 		
 	return resize_icon (pixbuf, size);
 }
@@ -1881,19 +1900,13 @@
 
 		default:
 		{
-			gchar *raw_uri;
-			gchar *mime_type;
+			GFile *location;
 			GeditDocument *doc;
 
 			doc = gedit_tab_get_document (tab);
 
-			raw_uri = gedit_document_get_uri (doc);
-			mime_type = gedit_document_get_mime_type (doc);
-
-			pixbuf = get_icon (theme, raw_uri, mime_type, icon_size);
-
-			g_free (raw_uri);
-			g_free (mime_type);
+			location = gedit_document_get_location (doc);
+			pixbuf = get_icon (theme, location, icon_size);
 		}
 	}
 

Modified: trunk/gedit/gedit-utils.c
==============================================================================
--- trunk/gedit/gedit-utils.c	(original)
+++ trunk/gedit/gedit-utils.c	Wed Aug  6 17:45:35 2008
@@ -44,7 +44,7 @@
 #include <glib/gunicode.h>
 #include <glib/gi18n.h>
 #include <glade/glade-xml.h>
-#include <libgnomevfs/gnome-vfs.h>
+#include <gio/gio.h>
 
 #include "gedit-utils.h"
 
@@ -67,19 +67,13 @@
 gboolean
 gedit_utils_uri_has_file_scheme (const gchar *uri)
 {
-	gchar *canonical_uri;
-	gchar *tmp;
+	GFile *gfile;
 	gboolean res;
 
-	canonical_uri = gnome_vfs_make_uri_canonical (uri);
-	g_return_val_if_fail (canonical_uri != NULL, FALSE);
-
-	tmp = gnome_vfs_get_local_path_from_uri (canonical_uri);
-	res = (tmp != NULL);
+	gfile = g_file_new_for_uri (uri);
+	res = g_file_has_uri_scheme (gfile, "file");
 	
-	g_free (canonical_uri);
-	g_free (tmp);
-
+	g_object_unref (gfile);
 	return res;
 }
 
@@ -87,18 +81,17 @@
 gboolean
 gedit_utils_uri_has_writable_scheme (const gchar *uri)
 {
-	gchar *canonical_uri;
+	GFile *gfile;
 	gchar *scheme;
 	GSList *writable_schemes;
 	gboolean res;
 
-	canonical_uri = gnome_vfs_make_uri_canonical (uri);
-	g_return_val_if_fail (canonical_uri != NULL, FALSE);
+	gfile = g_file_new_for_uri (uri);
+	scheme = g_file_get_uri_scheme (gfile);
 
-	scheme = gnome_vfs_get_uri_scheme (canonical_uri);
 	g_return_val_if_fail (scheme != NULL, FALSE);
 
-	g_free (canonical_uri);
+	g_object_unref (gfile);
 
 	writable_schemes = gedit_prefs_manager_get_writable_vfs_schemes ();
 
@@ -343,19 +336,17 @@
 gboolean
 gedit_utils_uri_exists (const gchar* text_uri)
 {
-	GnomeVFSURI *uri;
+	GFile *gfile;
 	gboolean res;
 		
 	g_return_val_if_fail (text_uri != NULL, FALSE);
 	
 	gedit_debug_message (DEBUG_UTILS, "text_uri: %s", text_uri);
 
-	uri = gnome_vfs_uri_new (text_uri);
-	g_return_val_if_fail (uri != NULL, FALSE);
+	gfile = g_file_new_for_uri (text_uri);
+	res = g_file_query_exists (gfile, NULL);
 
-	res = gnome_vfs_uri_exists (uri);
-
-	gnome_vfs_uri_unref (uri);
+	g_object_unref (gfile);
 
 	gedit_debug_message (DEBUG_UTILS, res ? "TRUE" : "FALSE");
 
@@ -500,7 +491,6 @@
 	GString * file_contents;
 	gchar *tmp_buf = NULL;
 	guint buffer_length;
-	GnomeVFSResult	res;
 	fd_set rfds;
 	struct timeval tv;
 	
@@ -527,8 +517,6 @@
 
 		if (ferror (stdin) != 0)
 		{
-			res = gnome_vfs_result_from_errno (); 
-		
 			g_free (tmp_buf);
 			g_string_free (file_contents, TRUE);
 			return NULL;
@@ -944,7 +932,7 @@
 			  const gchar    *url,
 			  gpointer        data)
 {
-	gnome_vfs_url_show (url);
+	gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (about)), url, GDK_CURRENT_TIME, NULL);
 }
 
 static gboolean
@@ -1115,13 +1103,14 @@
 gchar *
 gedit_utils_make_canonical_uri_from_shell_arg (const gchar *str)
 {	
+	GFile *gfile;
 	gchar *uri;
-	gchar *canonical_uri;
 
 	g_return_val_if_fail (str != NULL, NULL);
 	g_return_val_if_fail (*str != '\0', NULL);
 	
 	/* Note for the future: 
+	 * FIXME: is still still relevant?
 	 *
 	 * <federico> paolo: and flame whoever tells 
 	 * you that file:///gnome/test_files/hÃllà 
@@ -1136,21 +1125,110 @@
 	 * <paolo>: I will use gedit_utils_is_valid_uri ()
 	 *
 	 */
-	 
-	uri = gnome_vfs_make_uri_from_shell_arg (str);
-	canonical_uri = gnome_vfs_make_uri_canonical (uri);
+
+	gfile = g_file_new_for_commandline_arg (str);
+	uri = g_file_get_uri (gfile);
+	g_object_unref (gfile);
+
+	if (gedit_utils_is_valid_uri (uri))
+		return uri;
+	
 	g_free (uri);
+	return NULL;
+}
+
+/**
+ * gedit_utils_file_has_parent:
+ * @gfile: the GFile to check the parent for
+ *
+ * Return TRUE if the specified gfile has a parent (is not the root), FALSE
+ * otherwise
+ */
+gboolean
+gedit_utils_file_has_parent (GFile *gfile)
+{
+	GFile *parent;
+	gboolean ret;
 	
-	/* g_print ("URI: %s\n", canonical_uri); */
+	parent = g_file_get_parent (gfile);
+	ret = parent != NULL;
 	
-	if (gedit_utils_is_valid_uri (canonical_uri))
-		return canonical_uri;
+	if (parent)
+		g_object_unref (parent);
 	
-	return NULL;
+	return ret;
 }
 
 /**
- * gedit_utils_format_uri_for_display:
+ * gedit_utils_basename_for_display:
+ * @uri: uri for which the basename should be displayed
+ *
+ * Return the basename of a file suitable for display to users.
+ */
+gchar *
+gedit_utils_basename_for_display (gchar const *uri)
+{
+	gchar *name;
+	GFile *gfile;
+	GFileInfo *info;
+	gchar *hn;
+	
+	g_return_val_if_fail (uri != NULL, NULL);
+	
+	gfile = g_file_new_for_uri (uri);
+	
+	/* First, try to query the display name */
+	info = g_file_query_info (gfile,
+				  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 
+				  G_FILE_QUERY_INFO_NONE, 
+				  NULL, 
+				  NULL);
+
+	if (info)
+	{
+		/* Simply get the display name to use as the basename */
+		name = g_strdup (g_file_info_get_display_name (info));
+		g_object_unref (info);
+	}
+	else if (g_file_has_uri_scheme (gfile, "file"))
+	{
+		/* This is a local file, and therefore we will use
+		 * g_filename_display_basename on the local path */
+		gchar *local_path;
+		
+		local_path = g_file_get_path (gfile);
+		name = g_filename_display_basename (local_path);
+		g_free (local_path);
+	}
+	else if (gedit_utils_file_has_parent (gfile) || !gedit_utils_decode_uri (uri, NULL, NULL, &hn, NULL, NULL))
+	{
+		/* For remote files with a parent (so not just http://foo.com)
+		   or remote file for which the decoding of the host name fails,
+		   use the _parse_name and take basename of that */
+		 gchar *parse_name;
+
+		 parse_name = g_file_get_parse_name (gfile);
+		 name = g_path_get_basename (parse_name);
+		 g_free (parse_name);
+	}
+	else
+	{
+		/* display '/ on <host>' using the decoded host */
+		gchar *hn_utf8;
+		hn_utf8 = gedit_utils_make_valid_utf8 (hn);
+		
+		/* Translators: '/ on <remote-share>' */
+		name = g_strdup_printf (_("/ on %s"), hn_utf8);
+		
+		g_free (hn_utf8);
+		g_free (hn);
+	}
+	
+	return name;
+}
+
+/**
+ * gedit_utils_uri_for_display:
  * @uri: uri to be displayed.
  *
  * Filter, modify, unescape and change @uri to make it appropriate
@@ -1163,43 +1241,23 @@
  * <li>All other uri appear as expected.</li>
  * </ul>
  *
- * This function is very similar to gnome_vfs_format_uri_for_display but remove
- * the password from the resulting string
+ * This function is a convenient wrapper for g_file_get_parse_name
  *
  * Return value: a string which represents @uri and can be displayed.
  */
 gchar *
-gedit_utils_format_uri_for_display (const gchar *uri)
+gedit_utils_uri_for_display (const gchar *uri)
 {
-	GnomeVFSURI *vfs_uri;
+	GFile *gfile;
+	gchar *ret;
 	
-	g_return_val_if_fail (uri != NULL, NULL);
-
-	/* Note: vfs_uri may be NULL for some valid but
-	 * unsupported uris */
-	vfs_uri = gnome_vfs_uri_new (uri);
-	
-	if (vfs_uri == NULL)
-	{
-		/* We may disclose the password here, but there is nothing we
-		 * can do since we cannot get a valid vfs_uri */
-		return gnome_vfs_format_uri_for_display (uri);
-	}
-	else
-	{	
-		gchar *name;
-		gchar *uri_for_display;
-		
-		name = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_PASSWORD);
-		g_return_val_if_fail (name != NULL, gnome_vfs_format_uri_for_display (uri));
-		
-		uri_for_display = gnome_vfs_format_uri_for_display (name);
-		g_free (name);
-		
-		gnome_vfs_uri_unref (vfs_uri);
-		
-		return uri_for_display;
-	}
+	gfile = g_file_new_for_uri (uri);
+	
+	/* CHECK: does this actually do what we want? */
+	ret = g_file_get_parse_name (gfile);
+	
+	g_object_unref (gfile);
+	return ret;
 }
 
 /**
@@ -1243,3 +1301,154 @@
 
 	return uri_list;
 }
+
+static void
+null_ptr (gchar **ptr)
+{
+	if (ptr)
+		*ptr = NULL;
+}
+
+/**
+ * gedit_utils_decode_uri:
+ * @uri: the uri to decode
+ * @scheme: return value pointer for the uri's scheme (e.g. http, sftp, ...)
+ * @user: return value pointer for the uri user info
+ * @port: return value pointer for the uri port
+ * @host: return value pointer for the uri host
+ * @path: return value pointer for the uri path
+ *
+ * Parse and break an uri apart in its individual components like the uri
+ * scheme, user info, port, host and path. The return value pointer can be
+ * NULL to ignore certain parts of the uri. If the function returns TRUE, then
+ * all return value pointers should be freed using g_free
+ * 
+ * Return value: TRUE if the uri could be properly decoded, FALSE otherwise.
+ */
+gboolean
+gedit_utils_decode_uri (const gchar *uri,
+			gchar **scheme,
+			gchar **user,
+			gchar **host,
+			gchar **port,
+			gchar **path
+)
+{
+	/* Largely copied from glib/gio/gdummyfile.c:_g_decode_uri. This 
+	 * functionality should be in glib/gio, but for now we implement it
+	 * ourselves (see bug #546182) */
+
+	const char *p, *in, *hier_part_start, *hier_part_end;
+	char *out;
+	char c;
+
+	/* From RFC 3986 Decodes:
+	 * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
+	 */ 
+
+	p = uri;
+	
+	null_ptr (scheme);
+	null_ptr (user);
+	null_ptr (port);
+	null_ptr (host);
+	null_ptr (path);
+
+	/* Decode scheme:
+	 * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
+	 */
+
+	if (!g_ascii_isalpha (*p))
+		return FALSE;
+
+	while (1)
+	{
+		c = *p++;
+
+		if (c == ':')
+			break;
+
+		if (!(g_ascii_isalnum(c) ||
+		      c == '+' ||
+		      c == '-' ||
+		      c == '.'))
+			return FALSE;
+	}
+	
+	if (scheme)
+	{
+		*scheme = g_malloc (p - uri);
+		out = *scheme;
+	
+		for (in = uri; in < p - 1; in++)
+			*out++ = g_ascii_tolower (*in);
+			
+		*out = '\0';
+	}
+	
+	hier_part_start = p;
+	hier_part_end = p + strlen (p);
+	
+	if (hier_part_start[0] == '/' && hier_part_start[1] == '/')
+	{
+		const char *authority_start, *authority_end;
+		const char *userinfo_start, *userinfo_end;
+		const char *host_start, *host_end;
+		const char *port_start;
+		
+		authority_start = hier_part_start + 2;
+		/* authority is always followed by / or nothing */
+		authority_end = memchr (authority_start, '/', hier_part_end - authority_start);
+		
+		if (authority_end == NULL)
+			authority_end = hier_part_end;
+
+		/* 3.2:
+		 * authority = [ userinfo "@" ] host [ ":" port ]
+		 */
+
+		userinfo_end = memchr (authority_start, '@', authority_end - authority_start);
+		
+		if (userinfo_end)
+		{
+			userinfo_start = authority_start;
+			
+			if (user)
+				*user = g_uri_unescape_segment (userinfo_start, userinfo_end, NULL);
+			
+			if (user && *user == NULL)
+			{
+				if (scheme)
+					g_free (*scheme);
+
+				return FALSE;
+			}
+	
+			host_start = userinfo_end + 1;
+		}
+		else
+			host_start = authority_start;
+
+		port_start = memchr (host_start, ':', authority_end - host_start);
+
+		if (port_start)
+		{
+			host_end = port_start++;
+
+			if (port)
+				*port = g_strndup (port_start, authority_end - port_start);
+		}
+		else
+			host_end = authority_end;
+
+		if (host)
+			*host = g_strndup (host_start, host_end - host_start);
+
+		hier_part_start = authority_end;
+	}
+
+	if (path)
+		*path = g_uri_unescape_segment (hier_part_start, hier_part_end, "/");
+	
+	return TRUE;
+}

Modified: trunk/gedit/gedit-utils.h
==============================================================================
--- trunk/gedit/gedit-utils.h	(original)
+++ trunk/gedit/gedit-utils.h	Wed Aug  6 17:45:35 2008
@@ -139,13 +139,21 @@
 							 const gchar  *widget_name,
 							 ...) G_GNUC_NULL_TERMINATED;
 
+gboolean         gedit_utils_file_has_parent            (GFile *gfile);
+
 /* Return NULL if str is not a valid URI and/or filename */
 gchar		*gedit_utils_make_canonical_uri_from_shell_arg
 							(const gchar *str);
 		
-/* Like gnome_vfs_format_uri_for_display but removes the password from the 
- * resulting string */
-gchar		*gedit_utils_format_uri_for_display 	(const gchar *uri);
+gchar		*gedit_utils_uri_for_display 	        (const gchar *uri);
+gchar           *gedit_utils_basename_for_display	(const gchar *uri);
+gboolean	 gedit_utils_decode_uri 		(const gchar *uri,
+							 gchar **scheme,
+							 gchar **user,
+							 gchar **port,
+							 gchar **host,
+							 gchar **path);
+
 
 /* Turns data from a drop into a list of well formatted uris */
 gchar 	       **gedit_utils_drop_get_uris		(GtkSelectionData *selection_data);

Modified: trunk/gedit/gedit-window.c
==============================================================================
--- trunk/gedit/gedit-window.c	(original)
+++ trunk/gedit/gedit-window.c	Wed Aug  6 17:45:35 2008
@@ -1232,7 +1232,7 @@
 
 		/* gtk_recent_info_get_uri_display (info) is buggy and
 		 * works only for local files */
-		uri = gedit_utils_format_uri_for_display (gtk_recent_info_get_uri (info));
+		uri = gedit_utils_uri_for_display (gtk_recent_info_get_uri (info));
 		ruri = gedit_utils_replace_home_dir_with_tilde (uri);
 		g_free (uri);
 



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