aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook/gui/contact-editor/e-contact-save-as.c
diff options
context:
space:
mode:
Diffstat (limited to 'addressbook/gui/contact-editor/e-contact-save-as.c')
-rw-r--r--addressbook/gui/contact-editor/e-contact-save-as.c54
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;
+}