AnjutaPluginDescription*
anjuta_plugin_description_copy (AnjutaPluginDescription *df)
{
	return anjuta_plugin_description_new_from_string (anjuta_plugin_description_to_string (df),
	                                                  NULL);
}
Ejemplo n.º 2
0
AnjutaPluginHandle*
anjuta_plugin_handle_new (const gchar *plugin_desc_path)
{
	AnjutaPluginHandle *plugin_handle;
	AnjutaPluginDescription *desc;
	char *str;
	gboolean enable;
	gchar *contents = NULL;
	gboolean success = TRUE;
	
	/* Load file content */
	if (g_file_get_contents (plugin_desc_path, &contents, NULL, NULL)) {
		
		desc = anjuta_plugin_description_new_from_string (contents, NULL);
		g_free (contents);
		if (!desc) {
			g_warning ("Bad plugin file: %s\n", plugin_desc_path);
			return NULL;
		}
	}
	else
	{
		return NULL;
	}
	
	plugin_handle = g_object_new (ANJUTA_TYPE_PLUGIN_HANDLE, NULL);
	
	/* Initialize plugin handle */
	plugin_handle->priv->description = desc;
	plugin_handle->priv->user_activatable = TRUE;
	plugin_handle->priv->resident = TRUE;
	plugin_handle->priv->path = g_path_get_dirname (plugin_desc_path);
	
	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
											  "Location", &str)) {
		plugin_handle->priv->id = str;
	} else {
		g_warning ("Couldn't find 'Location'");
		success = FALSE;
	}
	
	if (anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
													 "Name", &str)) {
		plugin_handle->priv->name = str;
	} else {
		g_warning ("couldn't find 'Name' attribute.");
		success = FALSE;
	}

	if (anjuta_plugin_description_get_locale_string (desc, "Anjuta Plugin",
													 "Description", &str)) {
		plugin_handle->priv->about = str;
	} else {
		g_warning ("Couldn't find 'Description' attribute.");
		success = FALSE;
	}

	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
									   "Icon", &str)) {
		plugin_handle->priv->icon_path = get_icon_path (str);
		g_free (str);
	}

	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
											  "Dependencies",
											  &str)) {
		plugin_handle->priv->dependency_names = property_to_list (str);
		g_free (str);
	}

	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
											  "Interfaces",
											  &str)) {
		plugin_handle->priv->interfaces = property_to_list (str);
		g_free (str);
	}
	
	if (anjuta_plugin_description_get_boolean (desc, "Anjuta Plugin",
											  "UserActivatable", &enable)) {
		plugin_handle->priv->user_activatable = enable;
		/*
		DEBUG_PRINT ("Plugin '%s' is not user activatable",
					 plugin_handle->priv->name?
					 plugin_handle->priv->name : "Unknown");
		*/
	}
	
	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
											  "Resident", &str)) {
		if (str && strcasecmp (str, "no") == 0)
		{
			plugin_handle->priv->resident = FALSE;
		}
		g_free (str);
	}

	if (anjuta_plugin_description_get_string (desc, "Anjuta Plugin",
											  "Language", &str)) {
		plugin_handle->priv->language = str;
	}
	
	if (!success) {
		g_object_unref (plugin_handle);
		plugin_handle = NULL;
	}

	return plugin_handle;
}