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/ChangeLog | 9 ++ addressbook/gui/contact-editor/Makefile.am | 1 + addressbook/gui/contact-editor/e-contact-save-as.c | 54 +++++++++++- addressbook/gui/contact-editor/file-exists.glade | 95 ++++++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 addressbook/gui/contact-editor/file-exists.glade (limited to 'addressbook') diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog index f47fe71a51..7243c469ea 100644 --- a/addressbook/ChangeLog +++ b/addressbook/ChangeLog @@ -1,3 +1,12 @@ +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. + 2001-08-01 Christopher James Lahey * backend/ebook/e-book-view-listener.c diff --git a/addressbook/gui/contact-editor/Makefile.am b/addressbook/gui/contact-editor/Makefile.am index cfdebf408a..19598eeb7b 100644 --- a/addressbook/gui/contact-editor/Makefile.am +++ b/addressbook/gui/contact-editor/Makefile.am @@ -58,6 +58,7 @@ glade_DATA = \ contact-editor.glade \ fulladdr.glade \ fullname.glade \ + file-exists.glade \ e-contact-editor-confirm-delete.glade EXTRA_DIST = $(evolution_DATA) \ 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; +} diff --git a/addressbook/gui/contact-editor/file-exists.glade b/addressbook/gui/contact-editor/file-exists.glade new file mode 100644 index 0000000000..7c457cb892 --- /dev/null +++ b/addressbook/gui/contact-editor/file-exists.glade @@ -0,0 +1,95 @@ + + + + + File_exists.glade + file_exists.glade + + src + pixmaps + C + True + True + + + + GnomeDialog + dialog-exists + False + Confirm Overwrite + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox1 + False + 8 + + 4 + True + True + + + + GtkHButtonBox + GnomeDialog:action_area + dialog-action_area1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button1 + True + True + + + + + GtkButton + button3 + True + True + True + GNOME_STOCK_BUTTON_CANCEL + + + + + GtkLabel + label-exists + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + + -- cgit v1.2.3