anjuta r4388 - in trunk: . libanjuta plugins/project-manager src



Author: sgranjoux
Date: Tue Nov 11 20:06:46 2008
New Revision: 4388
URL: http://svn.gnome.org/viewvc/anjuta?rev=4388&view=rev

Log:
	* libanjuta/anjuta-profile.c,
	libanjuta/anjuta-profile.h,
	libanjuta/anjuta-profile-manager.c,
	libanjuta/anjuta-plugin-manager.c,
	libanjuta/anjuta-plugin-manager.h,
	src/anjuta.c,
	plugins/project-manager/plugin.c:
	Fix #307886 - Activated plugins not remembered the first time
	Replace gnome-vfs by gio


Modified:
   trunk/ChangeLog
   trunk/libanjuta/anjuta-plugin-manager.c
   trunk/libanjuta/anjuta-plugin-manager.h
   trunk/libanjuta/anjuta-profile-manager.c
   trunk/libanjuta/anjuta-profile.c
   trunk/libanjuta/anjuta-profile.h
   trunk/plugins/project-manager/plugin.c
   trunk/src/anjuta.c

Modified: trunk/libanjuta/anjuta-plugin-manager.c
==============================================================================
--- trunk/libanjuta/anjuta-plugin-manager.c	(original)
+++ trunk/libanjuta/anjuta-plugin-manager.c	Tue Nov 11 20:06:46 2008
@@ -1649,30 +1649,24 @@
 }
 
 GList*
-anjuta_plugin_manager_query (AnjutaPluginManager *plugin_manager,
-							 const gchar *section_name,
-							 const gchar *attribute_name,
-							 const gchar *attribute_value,
-							 ...)
+anjuta_plugin_manager_list_query (AnjutaPluginManager *plugin_manager,
+							 GList *secs,
+							 GList *anames,
+							 GList *avalues)
 {
 	AnjutaPluginManagerPriv *priv;
-	va_list var_args;
-	GList *secs = NULL;
-	GList *anames = NULL;
-	GList *avalues = NULL;
-	const gchar *sec = section_name;
-	const gchar *aname = attribute_name;
-	const gchar *avalue = attribute_value;
 	GList *selected_plugins = NULL;
+	const gchar *sec;
+	const gchar *aname;
+	const gchar *avalue;
 	GList *available;
 	
-	
 	g_return_val_if_fail (ANJUTA_IS_PLUGIN_MANAGER (plugin_manager), NULL);
 	
 	priv = plugin_manager->priv;
 	available = priv->available_plugins;
 	
-	if (section_name == NULL)
+	if (secs == NULL)
 	{
 		/* If no query is given, select all plugins */
 		while (available)
@@ -1686,38 +1680,9 @@
 		return g_list_reverse (selected_plugins);
 	}
 	
-	g_return_val_if_fail (section_name != NULL, NULL);
-	g_return_val_if_fail (attribute_name != NULL, NULL);
-	g_return_val_if_fail (attribute_value != NULL, NULL);
-	
-	secs = g_list_prepend (secs, g_strdup (section_name));
-	anames = g_list_prepend (anames, g_strdup (attribute_name));
-	avalues = g_list_prepend (avalues, g_strdup (attribute_value));
-	
-	va_start (var_args, attribute_value);
-	while (sec)
-	{
-		sec = va_arg (var_args, const gchar *);
-		if (sec)
-		{
-			aname = va_arg (var_args, const gchar *);
-			if (aname)
-			{
-				avalue = va_arg (var_args, const gchar *);
-				if (avalue)
-				{
-					secs = g_list_prepend (secs, g_strdup (sec));
-					anames = g_list_prepend (anames, g_strdup (aname));
-					avalues = g_list_prepend (avalues, g_strdup (avalue));
-				}
-			}
-		}
-	}
-	va_end (var_args);
-	
-	secs = g_list_reverse (secs);
-	anames = g_list_reverse (anames);
-	avalues = g_list_reverse (avalues);
+	g_return_val_if_fail (secs != NULL, NULL);
+	g_return_val_if_fail (anames != NULL, NULL);
+	g_return_val_if_fail (avalues != NULL, NULL);
 	
 	while (available)
 	{
@@ -1807,11 +1772,77 @@
 		}
 		available = g_list_next (available);
 	}
+	
+	return g_list_reverse (selected_plugins);
+}
+
+GList*
+anjuta_plugin_manager_query (AnjutaPluginManager *plugin_manager,
+							 const gchar *section_name,
+							 const gchar *attribute_name,
+							 const gchar *attribute_value,
+							 ...)
+{
+	va_list var_args;
+	GList *secs = NULL;
+	GList *anames = NULL;
+	GList *avalues = NULL;
+	const gchar *sec;
+	const gchar *aname;
+	const gchar *avalue;
+	GList *selected_plugins;
+	
+	
+	if (section_name == NULL)
+	{
+		/* If no query is given, select all plugins */
+		return anjuta_plugin_manager_list_query (plugin_manager, NULL, NULL, NULL);
+	}
+	
+	g_return_val_if_fail (section_name != NULL, NULL);
+	g_return_val_if_fail (attribute_name != NULL, NULL);
+	g_return_val_if_fail (attribute_value != NULL, NULL);
+	
+	secs = g_list_prepend (secs, g_strdup (section_name));
+	anames = g_list_prepend (anames, g_strdup (attribute_name));
+	avalues = g_list_prepend (avalues, g_strdup (attribute_value));
+	
+	va_start (var_args, attribute_value);
+	do
+	{
+		sec = va_arg (var_args, const gchar *);
+		if (sec)
+		{
+			aname = va_arg (var_args, const gchar *);
+			if (aname)
+			{
+				avalue = va_arg (var_args, const gchar *);
+				if (avalue)
+				{
+					secs = g_list_prepend (secs, g_strdup (sec));
+					anames = g_list_prepend (anames, g_strdup (aname));
+					avalues = g_list_prepend (avalues, g_strdup (avalue));
+				}
+			}
+		}
+	}
+	while (sec);
+	va_end (var_args);
+	
+	secs = g_list_reverse (secs);
+	anames = g_list_reverse (anames);
+	avalues = g_list_reverse (avalues);
+	
+	selected_plugins = anjuta_plugin_manager_list_query (plugin_manager,
+														 secs,
+														 anames,
+														 avalues);
+	
 	anjuta_util_glist_strings_free (secs);
 	anjuta_util_glist_strings_free (anames);
 	anjuta_util_glist_strings_free (avalues);
 	
-	return g_list_reverse (selected_plugins);
+	return selected_plugins;
 }
 
 enum {

Modified: trunk/libanjuta/anjuta-plugin-manager.h
==============================================================================
--- trunk/libanjuta/anjuta-plugin-manager.h	(original)
+++ trunk/libanjuta/anjuta-plugin-manager.h	Tue Nov 11 20:06:46 2008
@@ -92,10 +92,14 @@
 /* Plugin queries based on meta-data */
 /* Returns a list of plugin Descriptions */
 GList* anjuta_plugin_manager_query (AnjutaPluginManager *plugin_manager,
-									const gchar *section_name,
-									const gchar *attribute_name,
-									const gchar *attribute_value,
+									const gchar *section_names,
+									const gchar *attribute_names,
+									const gchar *attribute_values,
 									...);
+GList* anjuta_plugin_manager_list_query (AnjutaPluginManager *plugin_manager,
+										 GList *section_names,
+										 GList *attribute_names,
+										 GList *attribute_values);
 
 /* Returns the plugin description that has been selected from the list */
 AnjutaPluginDescription* anjuta_plugin_manager_select (AnjutaPluginManager *plugin_manager,

Modified: trunk/libanjuta/anjuta-profile-manager.c
==============================================================================
--- trunk/libanjuta/anjuta-profile-manager.c	(original)
+++ trunk/libanjuta/anjuta-profile-manager.c	Tue Nov 11 20:06:46 2008
@@ -30,7 +30,6 @@
 #include <string.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
-#include <libgnomevfs/gnome-vfs.h>
 
 #include <libanjuta/anjuta-debug.h>
 #include <libanjuta/anjuta-marshal.h>

Modified: trunk/libanjuta/anjuta-profile.c
==============================================================================
--- trunk/libanjuta/anjuta-profile.c	(original)
+++ trunk/libanjuta/anjuta-profile.c	Tue Nov 11 20:06:46 2008
@@ -32,7 +32,6 @@
 #include <string.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
-#include <libgnomevfs/gnome-vfs.h>
 
 #include "anjuta-profile.h"
 #include "anjuta-marshal.h"
@@ -44,7 +43,7 @@
 	PROP_PLUGIN_MANAGER,
 	PROP_PROFILE_NAME,
 	PROP_PROFILE_PLUGINS,
-	PROP_SYNC_URI,
+	PROP_SYNC_FILE,
 };
 
 enum
@@ -62,7 +61,7 @@
 	GList *plugins;
 	GHashTable *plugins_hash;
 	GHashTable *plugins_to_exclude_from_sync;
-	gchar *sync_uri;
+	GFile *sync_file;
 };
 
 static GObjectClass* parent_class = NULL;
@@ -129,11 +128,10 @@
 		else
 			priv->plugins = NULL;
 		break;
-	case PROP_SYNC_URI:
-		g_free (priv->sync_uri);
-		priv->sync_uri = NULL;
-		if (g_value_get_string (value) != NULL)
-			priv->sync_uri = g_value_dup_string (value);
+	case PROP_SYNC_FILE:
+		if (priv->sync_file)
+				g_object_unref (priv->sync_file);
+		priv->sync_file = g_value_dup_object (value);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -160,8 +158,8 @@
 	case PROP_PROFILE_PLUGINS:
 		g_value_set_pointer (value, priv->plugins);
 		break;
-	case PROP_SYNC_URI:
-		g_value_set_string (value, priv->sync_uri);
+	case PROP_SYNC_FILE:
+		g_value_set_object (value, priv->sync_file);
 		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -235,13 +233,14 @@
 											  G_PARAM_WRITABLE |
 											  G_PARAM_CONSTRUCT));
 	g_object_class_install_property (object_class,
-	                                 PROP_SYNC_URI,
-	                                 g_param_spec_string ("sync-uri",
-											  _("Synchronization URI"),
-											  _("URI to sync the profile xml"),
-											  NULL,
+	                                 PROP_SYNC_FILE,
+	                                 g_param_spec_object ("sync-file",
+											  _("Synchronization file"),
+											  _("File to sync the profile xml"),
+											  G_TYPE_FILE,
 											  G_PARAM_READABLE |
-											  G_PARAM_WRITABLE));
+											  G_PARAM_WRITABLE |
+											  G_PARAM_CONSTRUCT));
 
 	profile_signals[PLUGIN_ADDED] =
 		g_signal_new ("plugin-added",
@@ -372,80 +371,6 @@
 	return priv->plugins;
 }
 
-/* Profile processing */
-/* Returns a list of matching plugins */
-static GList*
-anjuta_profile_query_plugins (AnjutaProfile *profile,
-							  GList *groups, GList *attribs,
-							  GList *values)
-{
-	gchar *sec[5];
-	gchar *att[5];
-	gchar *val[5];
-	GList *sec_node, *att_node, *val_node;
-	gint length, i;
-	AnjutaProfilePriv *priv;
-
-	priv = profile->priv;
-	
-	/* FIXME: How to call a variable arguments function dynamically !! */
-	length = g_list_length (groups);
-	
-	g_return_val_if_fail ((length > 0 && length <= 5), NULL);
-	
-	i = 0;
-	sec_node = groups;
-	att_node = attribs;
-	val_node = values;
-	while (sec_node)
-	{
-		sec[i] = sec_node->data;
-		att[i] = att_node->data;
-		val[i] = val_node->data;
-		
-		sec_node = g_list_next (sec_node);
-		att_node = g_list_next (att_node);
-		val_node = g_list_next (val_node);
-		i++;
-	}
-	
-	switch (length)
-	{
-	case 1:
-		return anjuta_plugin_manager_query (priv->plugin_manager,
-											sec[0], att[0], val[0], NULL);
-	case 2:
-		return anjuta_plugin_manager_query (priv->plugin_manager,
-											sec[0], att[0], val[0],
-											sec[1], att[1], val[1],
-											NULL);
-	case 3:
-		return anjuta_plugin_manager_query (priv->plugin_manager,
-											sec[0], att[0], val[0],
-											sec[1], att[1], val[1],
-											sec[2], att[2], val[2],
-											NULL);
-	case 4:
-		return anjuta_plugin_manager_query (priv->plugin_manager,
-											sec[0], att[0], val[0],
-											sec[1], att[1], val[1],
-											sec[2], att[2], val[2],
-											sec[3], att[3], val[3],
-											NULL);
-	case 5:
-		return anjuta_plugin_manager_query (priv->plugin_manager,
-											sec[0], att[0], val[0],
-											sec[1], att[1], val[1],
-											sec[2], att[2], val[2],
-											sec[3], att[3], val[3],
-											sec[4], att[4], val[4],
-											NULL);
-	default:
-		g_warning ("FIXME: How to call a variable args function dynamically !!");
-	}
-	return NULL;
-}
-
 static GList*
 anjuta_profile_select_plugins (AnjutaProfile *profile,
 							   GList *descs_list)
@@ -478,272 +403,179 @@
 	return g_list_reverse (selected_plugins);
 }
 
-gboolean
-anjuta_profile_add_plugins_from_xml (AnjutaProfile *profile,
-									 const gchar* profile_xml_uri,
-									 gboolean exclude_from_sync,
-									 GError **error)
+static GList *
+anjuta_profile_read_plugins_from_xml (AnjutaProfile *profile,
+									  GFile *file,
+									  GError **error)
 {
-	AnjutaProfilePriv *priv;
+	gchar *read_buf;
+	gsize size;
 	xmlDocPtr xml_doc;
-	xmlNodePtr xml_root, xml_node;
-	GnomeVFSHandle *handle;
-	GnomeVFSFileInfo info;
-	GnomeVFSResult result;
-	int perm, read;
 	GList *descs_list = NULL;
-	GList *selected_plugins = NULL;
 	GList *not_found_names = NULL;
 	GList *not_found_urls = NULL;
-	gboolean err = FALSE;
-	gchar *read_buf = NULL;
-	g_return_val_if_fail (ANJUTA_IS_PROFILE (profile), FALSE);
-	priv = profile->priv;
-	
-	result = gnome_vfs_get_file_info (profile_xml_uri, &info,
-									  GNOME_VFS_FILE_INFO_DEFAULT |
-									  GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS);
+	gboolean parse_error;
 
-	/* If I got the info to check it out */
-	if(result != GNOME_VFS_OK )
-	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': %s"),
-					 profile_xml_uri,
-					 gnome_vfs_result_to_string (result));
-		return FALSE;
-	}
-	
-	/* FIXME: Fix this bit masking */
-	perm = (info.permissions-(int)(info.permissions/65536)*65536);
-	read = (int)(perm/256);
-
-	if(read == 0)
-	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("No read permission for: %s"),
-					 profile_xml_uri);
-		return FALSE;
-	}
-	if((result = gnome_vfs_open (&handle, profile_xml_uri,
-								 GNOME_VFS_OPEN_READ)) != GNOME_VFS_OK)
-	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': %s"),
-					 profile_xml_uri,
-					 gnome_vfs_result_to_string (result));
-		return FALSE;
-	}
-	read_buf = g_new0(char, info.size + 1);
-	
-	result = gnome_vfs_read (handle, read_buf, info.size, NULL);
-	if(!(result == GNOME_VFS_OK || result == GNOME_VFS_ERROR_EOF))
-	{
-		g_free (read_buf);
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': %s"),
-					 profile_xml_uri,
-					 gnome_vfs_result_to_string (result));
-		return FALSE;
-	}
-	gnome_vfs_close (handle);
-	xml_doc = xmlParseMemory (read_buf, info.size);
-	g_free(read_buf);
-	if(xml_doc == NULL)
-	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': XML parse error"),
-					 profile_xml_uri);
-		return FALSE;
-	}
-	
-	xml_root = xmlDocGetRootElement(xml_doc);
-	if(xml_root == NULL)
+	/* Read xml file */
+	if (!g_file_load_contents (file, NULL, &read_buf, &size, NULL, error))
 	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': XML parse error"),
-					 profile_xml_uri);
-		xmlFreeDoc(xml_doc);
-		return FALSE;
+		return NULL;
 	}
 	
-	if(!xml_root->name ||
-	   !xmlStrEqual(xml_root->name, (const xmlChar *)"anjuta"))
+	/* Parse xml file */
+	parse_error = TRUE;
+	xml_doc = xmlParseMemory (read_buf, size);
+	g_free (read_buf);
+	if (xml_doc != NULL)
 	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
-					 _("Failed to read '%s': XML parse error. "
-					   "Invalid or corrupted anjuta plugins profile."),
-					 profile_xml_uri);
-		xmlFreeDoc(xml_doc);
-		return FALSE;
-	}
-	
-	error = FALSE;
-	descs_list = NULL;
-	not_found_names = NULL;
-	not_found_urls = NULL;
-	
-	xml_node = xml_root->xmlChildrenNode;
-	while (xml_node && !error)
-	{
-		GList *groups = NULL;
-		GList *attribs = NULL;
-		GList *values = NULL;
-		GList *plugin_descs;
-		gchar *name, *url, *mandatory_text;
-		xmlNodePtr xml_require_node;
-		gboolean mandatory;
-
-		if (!xml_node->name ||
-			!xmlStrEqual (xml_node->name, (const xmlChar*)"plugin"))
-		{
-			xml_node = xml_node->next;
-			continue;
-		}
+		xmlNodePtr xml_root;
 		
-		name = (gchar*) xmlGetProp (xml_node, (const xmlChar*)"name");
-		url = (gchar*) xmlGetProp (xml_node, (const xmlChar*)"url");
-		
-		/* Ensure that both name is given */
-		if (!name)
+		xml_root = xmlDocGetRootElement(xml_doc);
+		if (xml_root &&
+			(xml_root->name) &&
+			xmlStrEqual(xml_root->name, (const xmlChar *)"anjuta"))
 		{
-			g_warning ("XML error: Plugin name should be present in plugin tag");
-			err = TRUE;
-			break;
-		}
-		if (!url)
-			url = g_strdup ("http://anjuta.org/plugins/";);
-		
-		/* Check if the plugin is mandatory */
-		mandatory_text = (gchar*) xmlGetProp (xml_node,
-											  (const xmlChar*)"mandatory");
-		if (mandatory_text && strcasecmp (mandatory_text, "yes") == 0)
-			mandatory = TRUE;
-		else
-			mandatory = FALSE;
-		xmlFree(mandatory_text);
-		
-		/* For all plugin attribute conditions */
-		xml_require_node = xml_node->xmlChildrenNode;
-		while (xml_require_node && !error)
-		{
-			gchar *group;
-			gchar *attrib;
-			gchar *value;
-			
-			if (!xml_require_node->name ||
-				!xmlStrEqual (xml_require_node->name,
-							  (const xmlChar*)"require"))
+			xmlNodePtr xml_node;
+
+			parse_error = FALSE;
+			for (xml_node = xml_root->xmlChildrenNode; xml_node; xml_node = xml_node->next)
 			{
-				xml_require_node = xml_require_node->next;
-				continue;
-			}
-			group = (gchar*) xmlGetProp (xml_require_node,
-										 (const xmlChar *)"group");
-			attrib = (gchar*) xmlGetProp(xml_require_node,
-										 (const xmlChar *)"attribute");
-			value = (gchar*) xmlGetProp(xml_require_node,
-										(const xmlChar *)"value");
+				GList *groups = NULL;
+				GList *attribs = NULL;
+				GList *values = NULL;
+				xmlChar *name, *url, *mandatory_text;
+				xmlNodePtr xml_require_node;
+				gboolean mandatory;
+
+				if (!xml_node->name ||
+					!xmlStrEqual (xml_node->name, (const xmlChar*)"plugin"))
+				{
+					continue;
+				}
+	
+				name = xmlGetProp (xml_node, (const xmlChar*)"name");
+				url = xmlGetProp (xml_node, (const xmlChar*)"url");
+		
+				/* Ensure that both name is given */
+				if (!name)
+				{
+					g_warning ("XML error: Plugin name should be present in plugin tag");
+					parse_error = TRUE;
+					break;
+				}
+				if (!url)
+					url = xmlCharStrdup ("http://anjuta.org/plugins/";);
+									 
+				/* Check if the plugin is mandatory */
+				mandatory_text = xmlGetProp (xml_node, (const xmlChar*)"mandatory");
+				mandatory = mandatory_text && (xmlStrcasecmp (mandatory_text, (const xmlChar *)"yes") == 0);
+				xmlFree(mandatory_text);
+										 
+				/* For all plugin attribute conditions */
+				for (xml_require_node = xml_node->xmlChildrenNode;
+			 		xml_require_node;
+			 		xml_require_node = xml_require_node->next)
+				{
+					xmlChar *group;
+					xmlChar *attrib;
+					xmlChar *value;
+		
+					if (!xml_require_node->name ||
+						!xmlStrEqual (xml_require_node->name,
+									  (const xmlChar*)"require"))
+					{
+						continue;
+					}
+					group = xmlGetProp (xml_require_node,
+										(const xmlChar *)"group");
+					attrib = xmlGetProp(xml_require_node,
+										(const xmlChar *)"attribute");
+					value = xmlGetProp(xml_require_node,
+									   (const xmlChar *)"value");
 			
-			if (group && attrib && value)
-			{
-				groups = g_list_prepend (groups, group);
-				attribs = g_list_prepend (attribs, attrib);
-				values = g_list_prepend (values, value);
-			}
-			else
-			{
-				if (group) xmlFree (group);
-				if (attrib) xmlFree (attrib);
-				if (value) xmlFree (value);
-				err = TRUE;
-				g_warning ("XML parse error: group, attribute and value should be defined in require");
-				break;
+					if (group && attrib && value)
+					{
+						groups = g_list_prepend (groups, group);
+						attribs = g_list_prepend (attribs, attrib);
+						values = g_list_prepend (values, value);
+					}
+					else
+					{
+						if (group) xmlFree (group);
+						if (attrib) xmlFree (attrib);
+						if (value) xmlFree (value);
+						parse_error = TRUE;
+						g_warning ("XML parse error: group, attribute and value should be defined in require");
+						break;
+					}
+				}
+
+				if (!parse_error)
+				{
+					if (g_list_length (groups) == 0)
+					{
+						parse_error = TRUE;
+						g_warning ("XML Error: No attributes to match given");
+					}
+					else
+					{
+						GList *plugin_descs;
+						
+						plugin_descs =
+							anjuta_plugin_manager_list_query (profile->priv->plugin_manager,
+															  groups,
+															  attribs,
+															  values);
+						if (plugin_descs)
+						{
+							descs_list = g_list_prepend (descs_list, plugin_descs);
+						}
+						else if (mandatory)
+						{
+							not_found_names = g_list_prepend (not_found_names, g_strdup ((const gchar *)name));
+							not_found_urls = g_list_prepend (not_found_urls, g_strdup ((const gchar *)url));
+						}
+					}
+				}
+				g_list_foreach (groups, (GFunc)xmlFree, NULL);
+				g_list_foreach (attribs, (GFunc)xmlFree, NULL);
+				g_list_foreach (values, (GFunc)xmlFree, NULL);
+				g_list_free (groups);
+				g_list_free (attribs);
+				g_list_free (values);
+				xmlFree (name);
+				xmlFree (url);
 			}
-			xml_require_node = xml_require_node->next;
-		}
-		if (error)
-		{
-			g_list_foreach (groups, (GFunc)xmlFree, NULL);
-			g_list_foreach (attribs, (GFunc)xmlFree, NULL);
-			g_list_foreach (values, (GFunc)xmlFree, NULL);
-			g_list_free (groups);
-			g_list_free (attribs);
-			g_list_free (values);
-			xmlFree (name);
-			xmlFree (url);
-			break;
-		}
-		if (g_list_length (groups) == 0)
-		{
-			err = TRUE;
-			g_warning ("XML Error: No attributes to match given");
-			xmlFree (name);
-			xmlFree (url);
-			break;
 		}
-		if (g_list_length (groups) > 5)
-		{
-			err = TRUE;
-			g_warning ("XML Error: Maximum 5 attributes can be given (FIXME)");
-			xmlFree (name);
-			xmlFree (url);
-			break;
-		}
-		plugin_descs = anjuta_profile_query_plugins (profile,
-													 groups, attribs,
-													 values);
-		if (plugin_descs)
-		{
-			descs_list = g_list_prepend (descs_list, plugin_descs);
-			xmlFree (name);
-			xmlFree (url);
-		}
-		else if (mandatory)
-		{
-			not_found_names = g_list_prepend (not_found_names, name);
-			not_found_urls = g_list_prepend (not_found_urls, url);
-		}
-		else
-		{
-			xmlFree (name);
-			xmlFree (url);
-		}
-		xml_node = xml_node->next;
+		xmlFreeDoc(xml_doc);
 	}
-	if (error)
+	
+	if (parse_error)
 	{
-		g_list_foreach (not_found_names, (GFunc)xmlFree, NULL);
-		g_list_foreach (not_found_urls, (GFunc)xmlFree, NULL);
-		g_list_foreach (descs_list, (GFunc)g_list_free, NULL);
-		g_list_free (not_found_names);
-		g_list_free (not_found_urls);
-		g_list_free (descs_list);
-		
+		/* Error during parsing */
+		gchar *uri = g_file_get_uri (file);
+
 		g_set_error (error, ANJUTA_PROFILE_ERROR,
 					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
 					 _("Failed to read '%s': XML parse error. "
 					   "Invalid or corrupted anjuta plugins profile."),
-					 profile_xml_uri);
-		xmlFreeDoc(xml_doc);
-		return FALSE;
+			 		uri);
+		g_free (uri);
+		
+		g_list_foreach (descs_list, (GFunc)g_list_free, NULL);
+		g_list_free (descs_list);
+		descs_list = NULL;
 	}
-	if (not_found_names)
+	else if (not_found_names)
 	{
 		/*
-		 * FIXME: Present a nice dialog box to promt the user to download
-		 * the plugin from corresponding URLs, install them and proceed.
-		 */
+	 	* FIXME: Present a nice dialog box to promt the user to download
+		* the plugin from corresponding URLs, install them and proceed.
+ 		*/	
 		GList *node_name, *node_url;
 		GString *mesg = g_string_new ("");
-		
+		gchar *uri = g_file_get_uri (file);
+			
 		not_found_names = g_list_reverse (not_found_names);
 		not_found_urls = g_list_reverse (not_found_urls);
 		
@@ -761,22 +593,39 @@
 		g_set_error (error, ANJUTA_PROFILE_ERROR,
 					 ANJUTA_PROFILE_ERROR_URI_READ_FAILED,
 					 _("Failed to read '%s': Following mandatory plugins are missing:\n%s"),
-					 profile_xml_uri, mesg->str);
+					 uri, mesg->str);
+		g_free (uri);
 		g_string_free (mesg, TRUE);
 		
-		/* FIXME: It should not return like this ... */
-		g_list_foreach (not_found_names, (GFunc)xmlFree, NULL);
-		g_list_foreach (not_found_urls, (GFunc)xmlFree, NULL);
 		g_list_foreach (descs_list, (GFunc)g_list_free, NULL);
-		g_list_free (not_found_names);
-		g_list_free (not_found_urls);
 		g_list_free (descs_list);
-		
-		xmlFreeDoc(xml_doc);
-		return FALSE;
+		descs_list = NULL;
 	}
+	g_list_foreach (not_found_names, (GFunc)g_free, NULL);
+	g_list_free (not_found_names);
+	g_list_foreach (not_found_urls, (GFunc)g_free, NULL);
+	g_list_free (not_found_urls);
+
+	return descs_list;
+}
+
+gboolean
+anjuta_profile_add_plugins_from_xml (AnjutaProfile *profile,
+									 GFile* profile_xml_file,
+									 gboolean exclude_from_sync,
+									 GError **error)
+{
+	AnjutaProfilePriv *priv;
+	GList *descs_list = NULL;
+	
+	g_return_val_if_fail (ANJUTA_IS_PROFILE (profile), FALSE);
+	
+	priv = profile->priv;
+	descs_list = anjuta_profile_read_plugins_from_xml (profile, profile_xml_file, error);
+	
 	if (descs_list)
 	{
+		GList *selected_plugins = NULL;
 		GList *node;
 		
 		/* Now everything okay. Select the plugins */
@@ -806,8 +655,8 @@
 		}
 		g_list_free (selected_plugins);
 	}
-	xmlFreeDoc(xml_doc);
-	return TRUE;
+	
+	return descs_list != NULL;
 }
 
 gchar*
@@ -884,50 +733,54 @@
 }
 
 void
-anjuta_profile_set_sync_uri (AnjutaProfile *profile, const gchar *sync_uri)
+anjuta_profile_set_sync_file (AnjutaProfile *profile, GFile *sync_file)
 {
 	AnjutaProfilePriv *priv;
 	
 	g_return_if_fail (ANJUTA_IS_PROFILE (profile));
+	
 	priv = profile->priv;
-	g_free (priv->sync_uri);
-	priv->sync_uri = NULL;
-	if (sync_uri)
-		priv->sync_uri = g_strdup (sync_uri);
+	
+	if (priv->sync_file)
+		g_object_unref (priv->sync_file);
+	priv->sync_file = sync_file;
+	if (priv->sync_file);
+		g_object_ref (priv->sync_file);
 }
 
 gboolean
 anjuta_profile_sync (AnjutaProfile *profile, GError **error)
 {
-	GnomeVFSHandle* vfs_write;
-	GnomeVFSResult result;
-	GnomeVFSFileSize nchars;
+	gboolean ok;
 	gchar *xml_buffer;
 	AnjutaProfilePriv *priv;
+	GError* file_error = NULL;
 	
 	g_return_val_if_fail (ANJUTA_IS_PROFILE (profile), FALSE);
 	priv = profile->priv;
 	
-	if (!priv->sync_uri)
+	if (!priv->sync_file)
 		return FALSE;
 	
 	xml_buffer = anjuta_profile_to_xml (profile);
-	result = gnome_vfs_create (&vfs_write, priv->sync_uri,
-							   GNOME_VFS_OPEN_WRITE,
-							   FALSE, 0664);
- 	if (result == GNOME_VFS_OK)
-	{
-		result = gnome_vfs_write (vfs_write, xml_buffer, strlen (xml_buffer),
-								  &nchars);
-		gnome_vfs_close (vfs_write);
-	}
-
-	if (result != GNOME_VFS_OK)
-	{
-		g_set_error (error, ANJUTA_PROFILE_ERROR,
-					 ANJUTA_PROFILE_ERROR_URI_WRITE_FAILED,
-					 "%s", gnome_vfs_result_to_string (result));
+	ok = g_file_replace_contents (priv->sync_file, xml_buffer, strlen(xml_buffer),
+								  NULL, FALSE, G_FILE_CREATE_NONE,
+								  NULL, NULL, &file_error);
+	if (!ok && g_error_matches (file_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+	{
+		/* Try to create parent directory */
+		GFile* parent = g_file_get_parent (priv->sync_file);
+		if (g_file_make_directory (parent, NULL, NULL))
+		{
+			g_clear_error (&file_error);
+			ok = g_file_replace_contents (priv->sync_file, xml_buffer, strlen(xml_buffer),
+										  NULL, FALSE, G_FILE_CREATE_NONE,
+										  NULL, NULL, &file_error);
+		}
+		g_object_unref (parent);
 	}
 	g_free (xml_buffer);
-	return (result == GNOME_VFS_OK);
+	if (file_error != NULL) g_propagate_error (error, file_error);
+	
+	return ok;
 }

Modified: trunk/libanjuta/anjuta-profile.h
==============================================================================
--- trunk/libanjuta/anjuta-profile.h	(original)
+++ trunk/libanjuta/anjuta-profile.h	Tue Nov 11 20:06:46 2008
@@ -22,6 +22,7 @@
 #define _ANJUTA_PROFILE_H_
 
 #include <glib-object.h>
+#include <gio/gio.h>
 #include <libanjuta/anjuta-plugin-description.h>
 #include <libanjuta/anjuta-plugin-manager.h>
 
@@ -74,7 +75,7 @@
 void anjuta_profile_remove_plugin (AnjutaProfile *profile,
 								   AnjutaPluginDescription *plugin);
 gboolean anjuta_profile_add_plugins_from_xml (AnjutaProfile *profile,
-											  const gchar* profile_xml_uri,
+											  GFile* profile_xml_file,
 											  gboolean exclude_from_sync,
 											  GError **error);
 gboolean anjuta_profile_has_plugin (AnjutaProfile *profile,
@@ -82,8 +83,8 @@
 GList* anjuta_profile_get_plugins (AnjutaProfile *profile);
 
 gchar* anjuta_profile_to_xml (AnjutaProfile *profile);
-void anjuta_profile_set_sync_uri (AnjutaProfile *profile,
-								  const gchar *sync_uri);
+void anjuta_profile_set_sync_file (AnjutaProfile *profile,
+								  GFile *sync_file);
 gboolean anjuta_profile_sync (AnjutaProfile *profile, GError **error);
 
 G_END_DECLS

Modified: trunk/plugins/project-manager/plugin.c
==============================================================================
--- trunk/plugins/project-manager/plugin.c	(original)
+++ trunk/plugins/project-manager/plugin.c	Tue Nov 11 20:06:46 2008
@@ -2379,7 +2379,8 @@
 	AnjutaPluginManager *plugin_manager;
 	AnjutaStatus *status;
 	gchar *dirname, *dirname_tmp, *vfs_dir;
-	gchar *session_profile, *profile_name;
+	gchar *session_profile_path, *profile_name;
+	GFile *session_profile;
 	ProjectManagerPlugin *plugin;
 	GError *error = NULL;
 	gchar* uri = g_file_get_uri (file);
@@ -2409,7 +2410,8 @@
 	profile = anjuta_profile_new (PROJECT_PROFILE_NAME, plugin_manager);
 	
 	/* System default profile */
-	anjuta_profile_add_plugins_from_xml (profile, DEFAULT_PROFILE,
+	session_profile = g_file_new_for_uri (DEFAULT_PROFILE);
+	anjuta_profile_add_plugins_from_xml (profile, session_profile,
 										 TRUE, &error);
 	if (error)
 	{
@@ -2418,9 +2420,11 @@
 		g_error_free (error);
 		error = NULL;
 	}
+	g_object_unref (session_profile);
 	
 	/* Project default profile */
-	anjuta_profile_add_plugins_from_xml (profile, uri, TRUE, &error);
+	session_profile = g_file_new_for_uri (uri);
+	anjuta_profile_add_plugins_from_xml (profile, session_profile, TRUE, &error);
 	if (error)
 	{
 		anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (ifile)->shell),
@@ -2428,6 +2432,7 @@
 		g_error_free (error);
 		error = NULL;
 	}
+	g_object_unref (session_profile);
 	
 	/* Project session profile */
 	vfs_uri = gnome_vfs_uri_new (uri);
@@ -2439,11 +2444,11 @@
 	profile_name = g_path_get_basename (DEFAULT_PROFILE);
 	gnome_vfs_uri_unref (vfs_uri);
 	
-	session_profile = g_build_filename (dirname, ".anjuta",
+	session_profile_path = g_build_filename (dirname, ".anjuta",
 										profile_name, NULL);
-	DEBUG_PRINT ("Loading project session profile: %s", session_profile);
-
-	if (g_file_test (session_profile, G_FILE_TEST_EXISTS))
+	DEBUG_PRINT ("Loading project session profile: %s", session_profile_path);
+	session_profile = g_file_new_for_path (session_profile_path);
+	if (g_file_query_exists (session_profile, NULL))
 	{
 		anjuta_profile_add_plugins_from_xml (profile, session_profile,
 											 FALSE, &error);
@@ -2455,8 +2460,9 @@
 			error = NULL;
 		}
 	}
-	anjuta_profile_set_sync_uri (profile, session_profile); 
-	g_free (session_profile);
+	anjuta_profile_set_sync_file (profile, session_profile); 
+	g_object_unref (session_profile);
+	g_free (session_profile_path);
 	g_free (profile_name);
 	
 	/* Set project uri */

Modified: trunk/src/anjuta.c
==============================================================================
--- trunk/src/anjuta.c	(original)
+++ trunk/src/anjuta.c	Tue Nov 11 20:06:46 2008
@@ -286,7 +286,7 @@
 	GnomeClient *client;
 	GnomeClientFlags flags;
 	AnjutaProfile *profile;
-	gchar *session_profile;
+	GFile *session_profile;
 	gchar *remembered_plugins;
 	gchar *project_file = NULL;
 	gchar *profile_name = NULL;
@@ -325,7 +325,8 @@
 	
 	/* Prepare profile */
 	profile = anjuta_profile_new (USER_PROFILE_NAME, plugin_manager);
-	anjuta_profile_add_plugins_from_xml (profile, DEFAULT_PROFILE,
+	session_profile = g_file_new_for_uri (DEFAULT_PROFILE);
+	anjuta_profile_add_plugins_from_xml (profile, session_profile,
 										 TRUE, &error);
 	if (error)
 	{
@@ -333,11 +334,12 @@
 		g_error_free (error);
 		error = NULL;
 	}
+	g_object_unref (session_profile);
 	
 	/* Load user session profile */
 	profile_name = g_path_get_basename (DEFAULT_PROFILE);
-	session_profile = anjuta_util_get_user_cache_file_path (profile_name, NULL);
-	if (g_file_test (session_profile, G_FILE_TEST_EXISTS))
+	session_profile = anjuta_util_get_user_cache_file (profile_name, NULL);
+	if (g_file_query_exists (session_profile, NULL))
 	{
 		anjuta_profile_add_plugins_from_xml (profile, session_profile,
 											 FALSE, &error);
@@ -348,8 +350,8 @@
 			error = NULL;
 		}
 	}
-	anjuta_profile_set_sync_uri (profile, session_profile); 
-	g_free (session_profile);
+	anjuta_profile_set_sync_file (profile, session_profile); 
+	g_object_unref (session_profile);
 	g_free (profile_name);
 	
 	/* Load profile */



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