Index: ChangeLog
===================================================================
--- ChangeLog	(revision 4593)
+++ ChangeLog	(working copy)
@@ -1,3 +1,20 @@
+2009-01-16  Jens Georg  <vmplanet@ubuntu-vm>
+
+	reviewed by: <delete if not using a buddy>
+
+	* plugins/gbf-am/Makefile.am:
+	* plugins/gbf-am/gbf-am-project.c (uri_is_equal), (uri_is_parent),
+	(uri_normalize), (uri_get_chrooted_path), (xml_new_change_doc),
+	(monitor_cb), (monitor_add), (monitors_setup), (spawn_shutdown),
+	(spawn_write_child), (spawn_kill_child), (spawn_script),
+	(project_reload), (project_update), (gbf_am_project_set_config),
+	(gbf_am_project_set_group_config),
+	(gbf_am_project_set_target_config), (impl_load), (impl_probe),
+	(impl_add_group), (impl_remove_group), (impl_add_target),
+	(impl_remove_target), (impl_add_source), (impl_remove_source):
+	
+	#511589 - port to gio. Removed resolution of "~" in uris
+
 2009-01-16  James Liggett  <jrliggett@cox.net>
 
 	* libanjuta/anjuta-status.c (anjuta_status_progress_pulse):
Index: plugins/gbf-am/Makefile.am
===================================================================
--- plugins/gbf-am/Makefile.am	(revision 4593)
+++ plugins/gbf-am/Makefile.am	(working copy)
@@ -24,6 +24,7 @@
 AM_CPPFLAGS = 					\
 	$(WARN_CFLAGS) \
 	$(DEPRECATED_FLAGS) \
+	$(GIO_CFLAGS) \
 	$(LIBANJUTA_CFLAGS) \
 	-DSCRIPTS_DIR=\"$(scriptsdir)\"
 
@@ -43,6 +44,7 @@
 libgbf_am_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
 libgbf_am_la_LIBADD = \
+	$(GIO_LIBS) \
 	$(LIBANJUTA_LIBS)
 
 # Test program
Index: plugins/gbf-am/gbf-am-project.c
===================================================================
--- plugins/gbf-am/gbf-am-project.c	(revision 4593)
+++ plugins/gbf-am/gbf-am-project.c	(working copy)
@@ -37,10 +37,7 @@
 #include <libgnome/gnome-macros.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
-#include <libgnomevfs/gnome-vfs-monitor.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-xfer.h>
+#include <libanjuta/anjuta-utils.h>
 #include "gbf-am-project.h"
 #include "gbf-am-config.h"
 #include "gbf-am-properties.h"
@@ -51,9 +48,9 @@
 /*#define ENABLE_DEBUG*/
 
 #ifdef ENABLE_DEBUG
-#define DEBUG(x) x
+#define GBF_DEBUG(x) x
 #else
-#define DEBUG(x)
+#define GBF_DEBUG(x)
 #endif
 
 
@@ -193,8 +190,7 @@
 static gboolean        uri_is_parent                (const gchar       *parent_uri,
 						     const gchar       *child_uri);
 static gboolean        uri_is_local_path            (const gchar       *uri);
-static gchar          *uri_to_path                  (const gchar       *uri);
-static gchar          *uri_normalize                (const gchar       *uri,
+static gchar          *uri_normalize                (const gchar       *path_or_uri,
 						     const gchar       *base_uri);
 
 static gboolean        xml_write_add_source         (GbfAmProject      *project,
@@ -292,14 +288,13 @@
 	      const gchar *uri2)
 {
 	gboolean retval = FALSE;
-	GnomeVFSURI *vfs_uri1, *vfs_uri2;
+	GFile *file1, *file2;
 
-	vfs_uri1 = gnome_vfs_uri_new (uri1);
-	vfs_uri2 = gnome_vfs_uri_new (uri2);
-	if (vfs_uri1 != NULL && vfs_uri2 != NULL)
-		retval = gnome_vfs_uri_equal (vfs_uri1, vfs_uri2);
-	gnome_vfs_uri_unref (vfs_uri1);
-	gnome_vfs_uri_unref (vfs_uri2);
+	file1 = g_file_new_for_commandline_arg (uri1);
+	file2 = g_file_new_for_commandline_arg (uri2);
+	retval = g_file_equal (file1, file2);
+	g_object_unref (file1);
+	g_object_unref (file2);
 
 	return retval;
 }
@@ -309,18 +304,21 @@
 	       const gchar *child_uri)
 {
 	gboolean retval = FALSE;
-	GnomeVFSURI *parent, *child;
+	GFile *parent, *child;
 
-	parent = gnome_vfs_uri_new (parent_uri);
-	child = gnome_vfs_uri_new (child_uri);
-	if (parent != NULL && child != NULL)
-		retval = gnome_vfs_uri_is_parent (parent, child, TRUE);
-	gnome_vfs_uri_unref (parent);
-	gnome_vfs_uri_unref (child);
+	parent = g_file_new_for_commandline_arg (parent_uri);
+	child = g_file_new_for_commandline_arg (child_uri);
+	retval = g_file_equal (parent, child);
+	g_object_unref (parent);
+	g_object_unref (child);
 
 	return retval;
 }
 
+/*
+ * This is very similar to the function that decides in 
+ * g_file_new_for_commandline_arg
+ */
 static gboolean
 uri_is_local_path (const gchar *uri)
 {
@@ -337,56 +335,39 @@
 		return TRUE;
 }
 
+/*
+ * This is basically g_file_get_uri (g_file_new_for_commandline_arg (uri)) with
+ * an option to give a basedir while g_file_new_for_commandline_arg always
+ * uses the current dir.
+ */
 static gchar *
-uri_to_path (const gchar *uri)
+uri_normalize (const gchar *path_or_uri, const gchar *base_uri)
 {
-	return gnome_vfs_get_local_path_from_uri (uri);
-}
-
-static gchar *
-uri_normalize (const gchar *uri, const gchar *base_uri)
-{
 	gchar *normalized_uri = NULL;
 
-	if (uri_is_local_path (uri)) {
-		gchar *absolute_path;
-		
-		absolute_path = gnome_vfs_expand_initial_tilde (uri);
-		if (!g_path_is_absolute (uri)) {
-			gchar *tmp = absolute_path;
-			gchar *base_dir;
-			if (base_uri != NULL)
-				base_dir = uri_to_path (base_uri);
-			else
-				base_dir = g_get_current_dir ();
+	if (base_uri != NULL && uri_is_local_path (path_or_uri))
+	{
+		GFile *base;
+		GFile *resolved;
 
-			absolute_path = g_build_filename (base_dir, tmp, NULL);
-			g_free (base_dir);
-			g_free (tmp);
-		}
-		normalized_uri = gnome_vfs_make_uri_canonical (absolute_path);
-		g_free (absolute_path);
-	} else {
-		GnomeVFSURI *vfs_uri;
+		base = g_file_new_for_uri (base_uri);
+		resolved = g_file_resolve_relative_path (base, path_or_uri);
 
-		vfs_uri = gnome_vfs_uri_new (uri);
-		/* FIXME: this should probably check that the method is file: */
-		if (gnome_vfs_uri_is_local (vfs_uri))
-			normalized_uri = gnome_vfs_make_uri_canonical (uri);
-		gnome_vfs_uri_unref (vfs_uri);
+		normalized_uri = g_file_get_uri (resolved);
+		g_object_unref (base);
+		g_object_unref (resolved);
 	}
+	else
+	{
+		GFile *file;
 
-	/* strip trailing slash */
-	if (normalized_uri) {
-		gint length = strlen (normalized_uri);
-		gchar *p;
-		if (length > 0) {
-			p = normalized_uri + length - 1;
-			if (*p == '/')
-				*p = '\0';
-		}
+		file = g_file_new_for_commandline_arg (path_or_uri);
+		normalized_uri = g_file_get_uri (file);
+		g_object_unref (file);
 	}
 
+	GBF_DEBUG (g_debug (G_STRLOC" path_or_uri: %s, base_uri: %s, normalized: %s\n",
+		path_or_uri, base_uri, normalized_uri));
 	return normalized_uri;
 }
 
@@ -403,29 +384,28 @@
 static gchar *
 uri_get_chrooted_path (const gchar *root_uri, const gchar *uri)
 {
-	gchar *root_path, *path;
-	gint root_length;
-	gchar *retval = NULL;
-	
-	path = uri_to_path (uri);
+	GFile *root, *file;
+	gchar *path = NULL;
+
 	if (root_uri == NULL)
-		return path;
-	
-	root_path = uri_to_path (root_uri);
-	
-	root_length = strlen (root_path);
-	if (strncmp (root_path, path, root_length) == 0) {
-		/* check for trailing path separator in root... we need it to
-		 * make the returned path absolute */
-		if (root_path [root_length - 1] == '/')
-			root_length--;
-		retval = g_strdup (path + root_length);
+	{
+		path = anjuta_util_get_local_path_from_uri (uri);
 	}
+	else
+	{
 
-	g_free (root_path);
-	g_free (path);
-	
-	return retval;
+		root = g_file_new_for_uri (root_uri);
+		file = g_file_new_for_uri (uri);
+
+		path = g_file_get_relative_path (root, file);
+
+		g_object_unref (root);
+		g_object_unref (file);
+	}
+
+	GBF_DEBUG (g_debug (G_STRLOC">>>>>>>>>>>>>>>>>> root_uri: %s, uri: %s, path: %s\n",
+		root_uri, uri, path));
+	return path;
 }
 
 /*
@@ -763,7 +743,7 @@
 	doc = xmlNewDoc (BAD_CAST "1.0");
 	if (doc != NULL) {
 		gchar *root_path;
-		root_path = uri_to_path (project->project_root_uri);
+		root_path = anjuta_util_get_local_path_from_uri (project->project_root_uri);
 		doc->children = xmlNewDocNode (doc, NULL, BAD_CAST "project", NULL);
 		xmlSetProp (doc->children, BAD_CAST "root", BAD_CAST root_path);
 		g_free (root_path);
@@ -777,23 +757,22 @@
  * File monitoring support --------------------------------
  * FIXME: review these
  */
-
 static void
-monitor_cb (GnomeVFSMonitorHandle   *handle,
-	    const gchar             *monitor_uri,
-	    const gchar             *info_uri,
-	    GnomeVFSMonitorEventType event_type,
-	    gpointer                 data)
+monitor_cb (GFileMonitor *monitor,
+			GFile *file,
+			GFile *other_file,
+			GFileMonitorEvent event_type,
+			gpointer data)
 {
 	GbfAmProject *project = data;
 
 	g_return_if_fail (project != NULL && GBF_IS_AM_PROJECT (project));
 
 	switch (event_type) {
-		case GNOME_VFS_MONITOR_EVENT_CHANGED:
-		case GNOME_VFS_MONITOR_EVENT_DELETED:
+		case G_FILE_MONITOR_EVENT_CHANGED:
+		case G_FILE_MONITOR_EVENT_DELETED:
 			/* monitor will be removed here... is this safe? */
-			DEBUG (g_message ("File changed"));
+			GBF_DEBUG (g_message ("File changed"));
 			project_reload (project, NULL);
 			g_signal_emit_by_name (G_OBJECT (project), "project-updated");
 			break;
@@ -802,37 +781,41 @@
 	}
 }
 
+
 static void
 monitor_add (GbfAmProject *project, const gchar *uri)
 {
-	GnomeVFSMonitorHandle *handle = NULL;
-	GnomeVFSResult result;
-
+	GFileMonitor *monitor = NULL;
+	
 	g_return_if_fail (project != NULL);
 	g_return_if_fail (project->monitors != NULL);
-
+	
 	if (!uri)
 		return;
 	
-	handle = g_hash_table_lookup (project->monitors, uri);
-	if (!handle) {
-		GnomeVFSURI *vfs_uri;
+	monitor = g_hash_table_lookup (project->monitors, uri);
+	if (!monitor) {
 		gboolean exists;
+		GFile *file;
 		
-		vfs_uri = gnome_vfs_uri_new (uri);
-		exists = gnome_vfs_uri_exists (vfs_uri);
-		gnome_vfs_uri_unref (vfs_uri);
-
+		/* FIXME clarify if uri is uri, path or both */
+		file = g_file_new_for_commandline_arg (uri);
+		exists = g_file_query_exists (file, NULL);
+		
 		if (exists) {
-			result = gnome_vfs_monitor_add (&handle,
-							uri,
-							GNOME_VFS_MONITOR_FILE,
-							monitor_cb,
-							project);
-			if (result == GNOME_VFS_OK) {
+			monitor = g_file_monitor_file (file, 
+						       G_FILE_MONITOR_NONE,
+						       NULL,
+						       NULL);
+			if (monitor != NULL)
+			{
+				g_signal_connect (G_OBJECT (monitor),
+						  "changed",
+						  G_CALLBACK (monitor_cb),
+						  project);
 				g_hash_table_insert (project->monitors,
 						     g_strdup (uri),
-						     handle);
+						     monitor);
 			}
 		}
 	}
@@ -868,7 +851,7 @@
 	
 	/* setup monitors hash */
 	project->monitors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
-						   (GDestroyNotify) gnome_vfs_monitor_cancel);
+						   (GDestroyNotify) g_file_monitor_cancel);
 
 	monitor_add (project, project->project_file);
 	g_hash_table_foreach (project->groups, group_hash_foreach_monitor, project);
@@ -973,7 +956,7 @@
 
 #define PARSER_ASSERT(x)  G_STMT_START {						\
 	if (!(x)) {									\
-		DEBUG (g_warning ("Parser assertion at " G_STRLOC " failed: " #x));	\
+		GBF_DEBUG (g_warning ("Parser assertion at " G_STRLOC " failed: " #x));	\
 		data->state = PARSE_ERROR; return;					\
 	}										\
 											\
@@ -1763,7 +1746,7 @@
 	g_return_if_fail (data != NULL);
 	
 	if (data->child_pid) {
-		DEBUG (g_message ("Killing child"));
+		GBF_DEBUG (g_message ("Killing child"));
 		kill (data->child_pid, SIGKILL);
 		data->child_pid = 0;
 	}
@@ -1843,7 +1826,7 @@
 
 		switch (status) {
 		    case G_IO_STATUS_NORMAL:
-			    DEBUG (g_message ("wrote %" G_GSIZE_FORMAT " bytes", bytes_written));
+			    GBF_DEBUG (g_message ("wrote %" G_GSIZE_FORMAT " bytes", bytes_written));
 			    
 			    if (data->input.length < data->input.size) {
 				    /* don't remove the source */
@@ -1979,7 +1962,7 @@
 spawn_kill_child (GbfAmSpawnData *data)
 {
 	/* we can't wait longer */
-	DEBUG (g_message ("Timeout: sending SIGTERM to child process"));
+	GBF_DEBUG (g_message ("Timeout: sending SIGTERM to child process"));
 	
 	kill (data->child_pid, SIGTERM);
 	
@@ -2040,7 +2023,7 @@
 		data->input.length = 0;  /* for input buffer length acts as an index */
 	}
 
-	DEBUG (g_message ("Spawning script"));
+	GBF_DEBUG (g_message ("Spawning script"));
 	
 	if (!g_spawn_async_with_pipes (NULL,             /* working dir */
 				       argv,
@@ -2142,11 +2125,11 @@
 	gboolean retval;
 	gint i;
 	
-	project_path = uri_to_path (project->project_root_uri);
+	project_path = anjuta_util_get_local_path_from_uri (project->project_root_uri);
 		
 	i = 0;
 	argv [i++] = GBF_AM_PARSE;
-	DEBUG (argv [i++] = "-d");
+	GBF_DEBUG (argv [i++] = "-d");
 	argv [i++] = "--get";
 	argv [i++] = project_path;
 	argv [i++] = NULL;
@@ -2212,7 +2195,7 @@
 
 	i = 0;
 	argv [i++] = GBF_AM_PARSE;
-	DEBUG (argv [i++] = "-d");
+	GBF_DEBUG (argv [i++] = "-d");
 	argv [i++] = "--set";
 	argv [i++] = "-";
 	argv [i++] = NULL;
@@ -2452,7 +2435,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/set-config.xml", doc);
 	});
@@ -2496,7 +2479,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/set-config.xml", doc);
 	});
@@ -2539,7 +2522,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/set-config.xml", doc);
 	});
@@ -2595,7 +2578,7 @@
 	}
 		
 	/* some basic checks */
-	root_path = uri_to_path (project->project_root_uri);
+	root_path = anjuta_util_get_local_path_from_uri (project->project_root_uri);
 	if (root_path == NULL || !g_file_test (root_path, G_FILE_TEST_IS_DIR)) {
 		error_set (error, GBF_PROJECT_ERROR_DOESNT_EXIST,
 			   _("Project doesn't exist or invalid path"));
@@ -2640,7 +2623,7 @@
 
 	normalized_uri = uri_normalize (path, NULL);
 	if (normalized_uri != NULL) {
-		root_path = uri_to_path (normalized_uri);
+		root_path = anjuta_util_get_local_path_from_uri (normalized_uri);
 		if (root_path != NULL && g_file_test (root_path, G_FILE_TEST_IS_DIR)) {
 			retval = (file_exists (root_path, "Makefile.am") &&
 				  (file_exists (root_path, "configure.in") ||
@@ -2855,7 +2838,7 @@
 		return NULL;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/add-group.xml", doc);
 	});
@@ -2871,7 +2854,7 @@
 
 	/* get newly created group id */
 	retval = NULL;
-	DEBUG (change_set_debug_print (change_set));
+	GBF_DEBUG (change_set_debug_print (change_set));
 	change = change_set_find (change_set, GBF_AM_CHANGE_ADDED, GBF_AM_NODE_GROUP);
 	if (change) {
 		retval = g_strdup (change->id);
@@ -2915,7 +2898,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/remove-group.xml", doc);
 	});
@@ -3119,7 +3102,7 @@
 		return NULL;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/add-target.xml", doc);
 	});
@@ -3135,7 +3118,7 @@
 	
 	/* get newly created target id */
 	retval = NULL;
-	DEBUG (change_set_debug_print (change_set));
+	GBF_DEBUG (change_set_debug_print (change_set));
 	change = change_set_find (change_set, GBF_AM_CHANGE_ADDED,
 				  GBF_AM_NODE_TARGET);
 	if (change) {
@@ -3180,7 +3163,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/remove-target.xml", doc);
 	});
@@ -3401,44 +3384,47 @@
 	
 	/* Check that the source uri is inside the project root */
 	if (!uri_is_parent (project->project_root_uri, full_uri)) {
-		/* If not, copy it to target's group directory */
-		GnomeVFSURI *group_vuri, *dest_vuri, *src_vuri;
-		GnomeVFSResult res;
+		GFile *src_file, *group_file, *dst_file;
+		GError *err = NULL;
 		
-		src_vuri = gnome_vfs_uri_new (uri);
-		group_vuri = gnome_vfs_uri_new (group_uri);
-		dest_vuri = gnome_vfs_uri_append_file_name (group_vuri,
-							    filename);
+		src_file = g_file_new_for_commandline_arg (uri);
+		group_file = g_file_new_for_commandline_arg (group_uri);
+		dst_file = g_file_get_child (group_file, filename);
+		g_object_unref (group_file);
 		
-		res = gnome_vfs_xfer_uri (src_vuri, dest_vuri,
-					  GNOME_VFS_XFER_DEFAULT,
-					  GNOME_VFS_XFER_ERROR_MODE_ABORT,
-					  GNOME_VFS_XFER_OVERWRITE_MODE_ABORT,
-					  NULL, NULL);
-		if (res != GNOME_VFS_OK && res != GNOME_VFS_ERROR_FILE_EXISTS) {
-			GbfProjectError gbf_err;
-			gchar *error_str =
-				g_strdup_printf ("Failed to copy source file inside project: %s",
-						 gnome_vfs_result_to_string (res));
-			switch (res) {
-			case GNOME_VFS_ERROR_NOT_FOUND:
-				gbf_err = GBF_PROJECT_ERROR_DOESNT_EXIST;
-				break;
-			default:
-				gbf_err = GBF_PROJECT_ERROR_GENERAL_FAILURE;
-				break;
+		if (!g_file_copy (src_file, dst_file,
+			     G_FILE_COPY_NONE,
+			     NULL, NULL,
+			     NULL, &err))
+		{
+			if (err->code != G_IO_ERROR_EXISTS)
+			{
+				GbfProjectError gbf_err;
+				gchar *error_str = 
+					g_strdup_printf ("Failed to copy source file inside project: %s",
+							 err->message);
+				switch (err->code)
+				{
+				case G_IO_ERROR_NOT_FOUND:
+					gbf_err = GBF_PROJECT_ERROR_DOESNT_EXIST;
+					break;
+				default:
+					gbf_err = GBF_PROJECT_ERROR_GENERAL_FAILURE;
+					break;
+				}
+				error_set (error, gbf_err, error_str);
+				g_free (error_str);
+				g_error_free (err);
+				abort_action = TRUE;
 			}
-			error_set (error, gbf_err, error_str);
-			g_free (error_str);
-			abort_action = TRUE;
-		} else {
-			g_free (full_uri);
-			full_uri = gnome_vfs_uri_to_string (dest_vuri,
-							    GNOME_VFS_URI_HIDE_NONE);
+			else
+			{
+				g_free (full_uri);
+				full_uri = g_file_get_uri (dst_file);
+			}
 		}
-		gnome_vfs_uri_unref (src_vuri);
-		gnome_vfs_uri_unref (group_vuri);
-		gnome_vfs_uri_unref (dest_vuri);
+		g_object_unref (src_file);
+		g_object_unref (dst_file);		
 	}
 	
 	g_free (group_uri);
@@ -3479,7 +3465,7 @@
 		return NULL;
 	}
 	
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/add-source.xml", doc);
 	});
@@ -3495,7 +3481,7 @@
 
 	/* get newly created source id */
 	retval = NULL;
-	DEBUG (change_set_debug_print (change_set));
+	GBF_DEBUG (change_set_debug_print (change_set));
 	change = change_set_find (change_set, GBF_AM_CHANGE_ADDED,
 				  GBF_AM_NODE_SOURCE);
 	if (change) {
@@ -3538,7 +3524,7 @@
 		return;
 	}
 
-	DEBUG ({
+	GBF_DEBUG ({
 		xmlSetDocCompressMode (doc, 0);
 		xmlSaveFile ("/tmp/remove-source.xml", doc);
 	});
