From eb66f839dc393431d562d06097707935823f164c Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Fri, 25 Feb 2005 09:55:29 +0000 Subject: Fixes #71527 2005-02-21 Rodrigo Moya 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. svn path=/trunk/; revision=28888 --- plugins/save-calendar/ical-format.c | 68 +++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 26 deletions(-) (limited to 'plugins/save-calendar/ical-format.c') diff --git a/plugins/save-calendar/ical-format.c b/plugins/save-calendar/ical-format.c index 680885161c..b6fe797f1d 100644 --- a/plugins/save-calendar/ical-format.c +++ b/plugins/save-calendar/ical-format.c @@ -31,12 +31,14 @@ #else # include #endif +#include #include #include #include #include #include #include +#include #include #include #include @@ -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 *handler, EPlugin *ep, ECalPopupTargetSourc /* 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; + /* create destination file */ + top_level = e_cal_util_new_top_level (); - if (e_cal_get_object_list (source_client, "#t", &objects, NULL)) { - while (objects != NULL) { - icalcomponent *icalcomp = objects->data; + error = NULL; + if (e_cal_get_object_list (source_client, "#t", &objects, &error)) { + GnomeVFSResult result; + GnomeVFSHandle *handle; - /* FIXME: deal with additions/modifications */ + while (objects != NULL) { + icalcomponent *icalcomp = objects->data; + + icalcomponent_add_component (top_level, icalcomp); - /* FIXME: This stores a directory with one file in it, the user expects only a file */ + /* remove item from the list */ + objects = g_list_remove (objects, icalcomp); + } - /* FIXME: It would be nice if this ical-handler would use gnome-vfs rather than e_cal_* */ + /* 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)); + } + } - 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); - } + if (result == GNOME_VFS_OK) { + char *ical_str; + GnomeVFSFileSize bytes_written; - /* remove item from the list */ - objects = g_list_remove (objects, icalcomp); - icalcomponent_free (icalcomp); + 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) -- cgit v1.2.3