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 | |
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')
-rw-r--r-- | addressbook/gui/contact-editor/Makefile.am | 1 | ||||
-rw-r--r-- | addressbook/gui/contact-editor/e-contact-save-as.c | 54 | ||||
-rw-r--r-- | addressbook/gui/contact-editor/file-exists.glade | 95 |
3 files changed, 149 insertions, 1 deletions
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 <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; +} 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 @@ +<?xml version="1.0"?> +<GTK-Interface> + +<project> + <name>File_exists.glade</name> + <program_name>file_exists.glade</program_name> + <directory></directory> + <source_directory>src</source_directory> + <pixmaps_directory>pixmaps</pixmaps_directory> + <language>C</language> + <gnome_support>True</gnome_support> + <gettext_support>True</gettext_support> +</project> + +<widget> + <class>GnomeDialog</class> + <name>dialog-exists</name> + <visible>False</visible> + <title>Confirm Overwrite</title> + <type>GTK_WINDOW_TOPLEVEL</type> + <position>GTK_WIN_POS_NONE</position> + <modal>False</modal> + <allow_shrink>False</allow_shrink> + <allow_grow>False</allow_grow> + <auto_shrink>False</auto_shrink> + <auto_close>False</auto_close> + <hide_on_close>False</hide_on_close> + + <widget> + <class>GtkVBox</class> + <child_name>GnomeDialog:vbox</child_name> + <name>dialog-vbox1</name> + <homogeneous>False</homogeneous> + <spacing>8</spacing> + <child> + <padding>4</padding> + <expand>True</expand> + <fill>True</fill> + </child> + + <widget> + <class>GtkHButtonBox</class> + <child_name>GnomeDialog:action_area</child_name> + <name>dialog-action_area1</name> + <layout_style>GTK_BUTTONBOX_END</layout_style> + <spacing>8</spacing> + <child_min_width>85</child_min_width> + <child_min_height>27</child_min_height> + <child_ipad_x>7</child_ipad_x> + <child_ipad_y>0</child_ipad_y> + <child> + <padding>0</padding> + <expand>False</expand> + <fill>True</fill> + <pack>GTK_PACK_END</pack> + </child> + + <widget> + <class>GtkButton</class> + <name>button1</name> + <can_default>True</can_default> + <can_focus>True</can_focus> + <label>Overwrite</label> + </widget> + + <widget> + <class>GtkButton</class> + <name>button3</name> + <can_default>True</can_default> + <has_default>True</has_default> + <can_focus>True</can_focus> + <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> + </widget> + </widget> + + <widget> + <class>GtkLabel</class> + <name>label-exists</name> + <label>Don't bother translating this string. It's not used.</label> + <justify>GTK_JUSTIFY_CENTER</justify> + <wrap>False</wrap> + <xalign>0.5</xalign> + <yalign>0.5</yalign> + <xpad>0</xpad> + <ypad>0</ypad> + <child> + <padding>0</padding> + <expand>False</expand> + <fill>False</fill> + </child> + </widget> + </widget> +</widget> + +</GTK-Interface> |