From 6d472a771799cc453ad065b78f4635a7919f4769 Mon Sep 17 00:00:00 2001 From: Srinivasa Ragavan Date: Fri, 21 Apr 2006 19:23:18 +0000 Subject: Added code to see if the file already exist. svn path=/trunk/; revision=31856 --- plugins/save-calendar/ChangeLog | 7 ++++++ plugins/save-calendar/ical-format.c | 50 +++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/plugins/save-calendar/ChangeLog b/plugins/save-calendar/ChangeLog index 6ca73daddb..8f47a22bbc 100644 --- a/plugins/save-calendar/ChangeLog +++ b/plugins/save-calendar/ChangeLog @@ -1,3 +1,10 @@ +2006-04-22 Srinivasa Ragavan + + * ical-format.c (do_save_calendar_ical): Ask for overwrite, if the + file already exists. + + ** Fixes bug #329345 + 2006-02-13 Karsten Bräckelmann * org-gnome-save-calendar.eplug.xml: diff --git a/plugins/save-calendar/ical-format.c b/plugins/save-calendar/ical-format.c index 459bd4c254..f4620b89a2 100644 --- a/plugins/save-calendar/ical-format.c +++ b/plugins/save-calendar/ical-format.c @@ -45,6 +45,7 @@ #include #include "format-handler.h" +#include "e-util/e-error.h" static void display_error_message (GtkWidget *parent, const char *message) @@ -64,6 +65,8 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc GError *error = NULL; GList *objects; icalcomponent *top_level = NULL; + GnomeVFSURI *uri; + gboolean doit = TRUE; primary_source = e_source_selector_peek_primary_selection (target->selector); @@ -97,27 +100,36 @@ do_save_calendar_ical (FormatHandler *handler, EPlugin *ep, ECalPopupTargetSourc } /* 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)); - } - } - - 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)), + uri = gnome_vfs_uri_new (dest_uri); + + result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ); + if (result == GNOME_VFS_OK) + doit = e_error_run(GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET (target->selector))), + E_ERROR_ASK_FILE_EXISTS_OVERWRITE, dest_uri, NULL) == GTK_RESPONSE_OK; + + if (doit) { + 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)); + } + } + + 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); } - - gnome_vfs_close (handle); } } else { display_error_message (gtk_widget_get_toplevel (GTK_WIDGET (target->selector)), error->message); -- cgit v1.2.3