diff options
author | Christopher James Lahey <clahey@ximian.com> | 2001-08-01 15:16:40 +0800 |
---|---|---|
committer | Chris Lahey <clahey@src.gnome.org> | 2001-08-01 15:16:40 +0800 |
commit | 0d176ec109e4ac4cf62cb4e9c4553157e4e0d766 (patch) | |
tree | 7be09c51f9ba4e1bd64980da4a31f325ce7c287a /addressbook/gui/contact-editor/e-contact-save-as.c | |
parent | e567bc692a7d6da7cb793fcb1cbd47ef64ae3455 (diff) | |
download | gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar.gz gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar.bz2 gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar.lz gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar.xz gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.tar.zst gsoc2013-evolution-0d176ec109e4ac4cf62cb4e9c4553157e4e0d766.zip |
Added file-exists.glade.
2001-08-01 Christopher James Lahey <clahey@ximian.com>
* 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
Diffstat (limited to 'addressbook/gui/contact-editor/e-contact-save-as.c')
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-save-as.c | 54 |
1 files changed, 53 insertions, 1 deletions
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 <fcntl.h> #include <gtk/gtkfilesel.h> #include <gtk/gtksignal.h> +#include <gtk/gtk.h> +#include <libgnomeui/gnome-dialog.h> #include <gal/util/e-util.h> +#include <libgnome/gnome-i18n.h> #include "e-contact-save-as.h" +#include <errno.h> + +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; +} |