From 0d176ec109e4ac4cf62cb4e9c4553157e4e0d766 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Wed, 1 Aug 2001 07:16:40 +0000 Subject: Added file-exists.glade. 2001-08-01 Christopher James Lahey * gui/contact-editor/Makefile.am: Added file-exists.glade. * gui/contact-editor/e-contact-save-as.c (file_exists), gui/contact-editor/file-exists.glade: Added a dialog to ask the user whether to replace an already existing file. Mostly from a patch by Jos Dehaes. Fixes Ximian bug #2231. svn path=/trunk/; revision=11540 --- addressbook/gui/contact-editor/e-contact-save-as.c | 54 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'addressbook/gui/contact-editor/e-contact-save-as.c') diff --git a/addressbook/gui/contact-editor/e-contact-save-as.c b/addressbook/gui/contact-editor/e-contact-save-as.c index 0d2b81f2bd..35247edbfc 100644 --- a/addressbook/gui/contact-editor/e-contact-save-as.c +++ b/addressbook/gui/contact-editor/e-contact-save-as.c @@ -24,8 +24,14 @@ #include #include #include +#include +#include #include +#include #include "e-contact-save-as.h" +#include + +static int file_exists(GtkFileSelection *filesel, const char *filename); typedef struct { GtkFileSelection *filesel; @@ -35,10 +41,24 @@ typedef struct { static void save_it(GtkWidget *widget, SaveAsInfo *info) { + gint error = 0; + gint response = 0; + const char *filename = gtk_file_selection_get_filename (info->filesel); - e_write_file (filename, info->vcard, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC); + error = e_write_file (filename, info->vcard, O_WRONLY | O_CREAT | O_EXCL | O_TRUNC); + if (error == EEXIST) { + response = file_exists(info->filesel, filename); + switch (response) { + case 0 : /* Overwrite */ + e_write_file(filename, info->vcard, O_WRONLY | O_CREAT | O_TRUNC); + break; + case 1 : /* cancel */ + break; + } + } + g_free (info->vcard); gtk_widget_destroy(GTK_WIDGET(info->filesel)); g_free(info); @@ -98,3 +118,35 @@ e_contact_list_save_as(char *title, GList *list) delete_it, info); gtk_widget_show(GTK_WIDGET(filesel)); } + +static int +file_exists(GtkFileSelection *filesel, const char *filename) +{ + GnomeDialog *dialog = NULL; + GtkWidget *label; + GladeXML *gui = NULL; + int result = 0; + char *string; + + gui = glade_xml_new (EVOLUTION_GLADEDIR "/file-exists.glade", NULL); + dialog = GNOME_DIALOG(glade_xml_get_widget(gui, "dialog-exists")); + gtk_widget_ref(GTK_WIDGET(dialog)); + + label = glade_xml_get_widget (gui, "label-exists"); + if (GTK_IS_LABEL (label)) { + string = g_strdup_printf (_("%s already exists\nDo you want to overwrite it?"), filename); + gtk_label_set_text (GTK_LABEL (label), string); + g_free (string); + } + + gnome_dialog_set_parent(dialog, GTK_WINDOW(filesel)); + + gtk_widget_show (GTK_WIDGET (dialog)); + result = gnome_dialog_run_and_close(dialog); + + gtk_widget_unref(GTK_WIDGET(dialog)); + gtk_widget_destroy(GTK_WIDGET(dialog)); + g_free(gui); + + return result; +} -- cgit v1.2.3