[evolution-patches] patch for save-calendar plugin #71527



-- 
Rodrigo Moya <rodrigo novell com>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/ChangeLog,v
retrieving revision 1.11
diff -u -p -r1.11 ChangeLog
--- ChangeLog	5 Jan 2005 18:03:25 -0000	1.11
+++ ChangeLog	21 Feb 2005 12:20:45 -0000
@@ -1,3 +1,11 @@
+2005-02-21  Rodrigo Moya <rodrigo novell com>
+
+	Fixes #71527
+
+	* ical-format.c (display_error_message): changed to get a simple
+	string instead of a GError.
+	(do_save_calendar_ical): use GNOME-VFS for saving the file.
+
 2005-01-05  JP Rosevear  <jpr novell com>
 
 	* save-calendar.c (ask_destination_and_save): fix build for non
Index: ical-format.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/ical-format.c,v
retrieving revision 1.1
diff -u -p -r1.1 ical-format.c
--- ical-format.c	20 Dec 2004 12:47:51 -0000	1.1
+++ ical-format.c	21 Feb 2005 12:20:45 -0000
@@ -31,12 +31,14 @@
 #else
 #  include <gtk/gtkfilesel.h>
 #endif
+#include <libgnomevfs/gnome-vfs-ops.h>
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtk.h>
 #include <libedataserver/e-source.h>
 #include <libedataserverui/e-source-selector.h>
 #include <libecal/e-cal.h>
+#include <libecal/e-cal-util.h>
 #include <calendar/gui/e-cal-popup.h>
 #include <libgnomevfs/gnome-vfs.h>
 #include <string.h>
@@ -44,12 +46,11 @@
 #include "format-handler.h"
 
 static void
-display_error_message (GtkWidget *parent, GError *error)
+display_error_message (GtkWidget *parent, const char *message)
 {
 	GtkWidget *dialog;
 
-	dialog = gtk_message_dialog_new (GTK_WINDOW (parent), 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-					 error->message);
+	dialog = gtk_message_dialog_new (GTK_WINDOW (parent), 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, message);
 	gtk_dialog_run (GTK_DIALOG (dialog));
 	gtk_widget_destroy (dialog);
 }
@@ -58,8 +59,10 @@ static void
 do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSource *target, ECalSourceType type, char *dest_uri)
 {
 	ESource *primary_source;
-	ECal *source_client, *dest_client;
+	ECal *source_client;
 	GError *error = NULL;
+	GList *objects;
+	icalcomponent *top_level = NULL;
 
 	primary_source = e_source_selector_peek_primary_selection (target->selector);
 
@@ -69,47 +72,60 @@ do_save_calendar_ical (FormatHandler *ha
 	/* open source client */
 	source_client = e_cal_new (primary_source, type);
 	if (!e_cal_open (source_client, TRUE, &error)) {
-		display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
+		display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
 		g_object_unref (source_client);
 		g_error_free (error);
 		return;
 	}
 
-	/* open destination client */
-	error = NULL;
-	dest_client = e_cal_new_from_uri (dest_uri, type);
-	if (e_cal_open (dest_client, FALSE, &error)) {
-		GList *objects;
-
-		if (e_cal_get_object_list (source_client, "#t", &objects, NULL)) {
-			while (objects != NULL) {
-				icalcomponent *icalcomp = objects->data;
+	/* create destination file */
+	top_level = e_cal_util_new_top_level ();
 
-				/* FIXME: deal with additions/modifications */
-
-				/* FIXME: This stores a directory with one file in it, the user expects only a file */
+	error = NULL;
+	if (e_cal_get_object_list (source_client, "#t", &objects, &error)) {
+		GnomeVFSResult result;
+		GnomeVFSHandle *handle;
+
+		while (objects != NULL) {
+			icalcomponent *icalcomp = objects->data;
+			
+			icalcomponent_add_component (top_level, icalcomp);
 
-				/* FIXME: It would be nice if this ical-handler would use gnome-vfs rather than e_cal_* */
+			/* remove item from the list */
+			objects = g_list_remove (objects, icalcomp);
+		}
 
-				error = NULL;
-				if (!e_cal_create_object (dest_client, icalcomp, NULL, &error)) {
-					display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
-					g_error_free (error);
-				}
+		/* save the file */
+		result = gnome_vfs_open (&handle, dest_uri, GNOME_VFS_OPEN_WRITE);
+		if (result != GNOME_VFS_OK) {
+			if ((result = gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE,
+							TRUE, GNOME_VFS_PERM_USER_ALL)) != GNOME_VFS_OK) {
+				display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
+					       gnome_vfs_result_to_string (result));
+			}
+		}
 
-				/* remove item from the list */
-				objects = g_list_remove (objects, icalcomp);
-				icalcomponent_free (icalcomp);
+		if (result == GNOME_VFS_OK) {
+			char *ical_str;
+			GnomeVFSFileSize bytes_written;
+
+			ical_str = icalcomponent_as_ical_string (top_level);
+			if ((result = gnome_vfs_write (handle, (gconstpointer) ical_str, strlen (ical_str), &bytes_written))
+			    != GNOME_VFS_OK) {
+				display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)),
+						       gnome_vfs_result_to_string (result));
 			}
+
+			gnome_vfs_close (handle);
 		}
 	} else {
-		display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error);
+		display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message);
 		g_error_free (error);
 	}
 
 	/* terminate */
 	g_object_unref (source_client);
-	g_object_unref (dest_client);
+	icalcomponent_free (top_level);
 }
 
 FormatHandler *ical_format_handler_new (void)
Index: save-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/save-calendar.c,v
retrieving revision 1.7
diff -u -p -r1.7 save-calendar.c
--- save-calendar.c	5 Jan 2005 18:03:25 -0000	1.7
+++ save-calendar.c	21 Feb 2005 12:20:45 -0000
@@ -128,7 +128,6 @@ ask_destination_and_save (EPlugin *ep, E
 	format_handlers = g_list_append (format_handlers, 
 		rdf_format_handler_new ());
 
-
 	/* The Type GtkComboBox */
 	gtk_box_pack_start (GTK_BOX (extra_widget), GTK_WIDGET (combo), 
 		TRUE, TRUE, 0);


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