[evolution-patches] Overwriting files warnings in save-attachments and save-calendar plugins



Hi there!

This patch adds three GtkMessageDialogs about overwriting files if they
already exist. Two in the save-calendar and one in the save-attachments
plugin.

For the save-attachments plugin I used the POSIX-call 'access': The
underlying library-function responsible for the 'saving' ain't using
gnome-vfs. For the save-calendar plugin I used gnome-vfs. It ain't yet
checking existence of the file in the save-calendar plugin if the
selected format is 'ical' for I (or somebody else) hasn't yet fixed the
issues with it (the fact that the actual .ical-file being written is
placed in a directory with as only file in it 'calendar.ics' or
'tasks.ics').


Please review


-- 
Philip Van Hoof, Software Developer @ Cronos
home: me at freax dot org
gnome: pvanhoof at gnome dot org
work: philip dot vanhoof at cronos dot be
junk: philip dot vanhoof at gmail dot com
http://www.freax.be, http://www.freax.eu.org
? groupwise-account-setup/Makefile
? groupwise-account-setup/Makefile.in
? groupwise-account-setup/org-gnome-gw-account-setup.eplug
Index: save-attachments/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-attachments/ChangeLog,v
retrieving revision 1.3
diff -u -r1.3 ChangeLog
--- save-attachments/ChangeLog	1 Nov 2004 19:32:04 -0000	1.3
+++ save-attachments/ChangeLog	27 Dec 2004 22:44:30 -0000
@@ -1,3 +1,7 @@
+2004-12-27  Philip Van Hoof  <pvanhoof gnome org>
+
+	* save-attachments.c: Warning when overwriting file
+
 2004-11-01  JP Rosevear  <jpr novell com>
 
 	* Makefile.am: dist xml menu file
Index: save-attachments/save-attachments.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-attachments/save-attachments.c,v
retrieving revision 1.1
diff -u -r1.1 save-attachments.c
--- save-attachments/save-attachments.c	20 Oct 2004 07:40:04 -0000	1.1
+++ save-attachments/save-attachments.c	27 Dec 2004 22:44:30 -0000
@@ -33,6 +33,7 @@
 
 #include <gtk/gtkcheckbutton.h>
 #include <gtk/gtkdialog.h>
+#include <gtk/gtkmessagedialog.h>
 #include <gtk/gtktreestore.h>
 #include <gtk/gtkcellrenderertext.h>
 #include <gtk/gtkcellrenderertoggle.h>
@@ -212,7 +213,33 @@
 	/* FIXME: if part == data->msg then we need to save this
 	 * differently, not using the envelope MimePart */
 
-	em_utils_save_part_to_file(NULL, save, part);
+	/* 
+	 * The underlying em_utils_save_part_to_file ain't using gnome-vfs. Therefor 
+	 * the POSIX access-call should suffice for checking the file existence.
+	 */
+
+	if (access (save, F_OK))
+	{
+		GtkWidget *warning = 
+			gtk_message_dialog_new_with_markup (NULL,
+				GTK_DIALOG_DESTROY_WITH_PARENT,
+				GTK_MESSAGE_WARNING,
+				GTK_BUTTONS_NONE,
+				_("<b>A file %s already exists.</b>\n"
+				  "If you choose to overwrite this file, "
+				  "the contents will be lost."), save);
+
+			gtk_dialog_add_button (GTK_DIALOG (warning), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+			gtk_dialog_add_button (GTK_DIALOG (warning), _("_Overwrite"), GTK_RESPONSE_YES);
+
+			doit = FALSE;
+			if (gtk_dialog_run (GTK_DIALOG (warning)) == GTK_RESPONSE_YES)
+				doit = TRUE;
+			gtk_widget_destroy (warning);
+	}
+
+	if (doit)
+		em_utils_save_part_to_file(NULL, save, part);
 
 	g_free(ext);
 	g_free(filename);
Index: save-calendar/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/ChangeLog,v
retrieving revision 1.8
diff -u -r1.8 ChangeLog
--- save-calendar/ChangeLog	22 Dec 2004 15:45:49 -0000	1.8
+++ save-calendar/ChangeLog	27 Dec 2004 22:44:30 -0000
@@ -1,3 +1,7 @@
+2004-12-27  Philip Van Hoof  <pvanhoof gnome org>
+
+	* csv-format.c, rdf-format.c: Warning when overwriting file
+
 2004-12-22  JP Rosevear  <jpr novell com>
 
 	* Makefile.am: list format-handler.h as a source so it dists
Index: save-calendar/csv-format.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/csv-format.c,v
retrieving revision 1.1
diff -u -r1.1 csv-format.c
--- save-calendar/csv-format.c	20 Dec 2004 12:47:51 -0000	1.1
+++ save-calendar/csv-format.c	27 Dec 2004 22:44:31 -0000
@@ -320,6 +320,7 @@
 	CsvConfig *config = NULL;
 	CsvPluginData *d = handler->data;
 	const gchar *tmp = NULL;
+	gboolean doit = TRUE;
 
 	if (!dest_uri)
 		return;
@@ -346,13 +347,37 @@
 	config->header = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (d->header_check));
 
 	uri = gnome_vfs_uri_new (dest_uri);
-	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
-	if (result != GNOME_VFS_OK) {
-		gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
+
+	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
+	if (result == GNOME_VFS_OK)
+	{
+		GtkWidget *warning = 
+		  gtk_message_dialog_new_with_markup (NULL,
+				GTK_DIALOG_DESTROY_WITH_PARENT,
+				GTK_MESSAGE_WARNING,
+				GTK_BUTTONS_NONE,
+				_("<b>A file %s already exists.</b>\n"
+				  "If you choose to overwrite this file, "
+				  "the contents will be lost."), dest_uri);
+
+		gtk_dialog_add_button (GTK_DIALOG (warning), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+		gtk_dialog_add_button (GTK_DIALOG (warning), _("_Overwrite"), GTK_RESPONSE_YES);
+
+		doit = FALSE;
+		if (gtk_dialog_run (GTK_DIALOG (warning)) == GTK_RESPONSE_YES)
+			doit = TRUE;
+		gtk_widget_destroy (warning);
+	} 
+
+	if (doit) {
 		result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+		if (result != GNOME_VFS_OK) {
+			gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
+			result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+		} 
 	}
 
-	if (result == GNOME_VFS_OK && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
+	if (result == GNOME_VFS_OK && doit && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
 
 		if (config->header) {
 			line = g_string_new ("");
Index: save-calendar/rdf-format.c
===================================================================
RCS file: /cvs/gnome/evolution/plugins/save-calendar/rdf-format.c,v
retrieving revision 1.1
diff -u -r1.1 rdf-format.c
--- save-calendar/rdf-format.c	20 Dec 2004 12:47:51 -0000	1.1
+++ save-calendar/rdf-format.c	27 Dec 2004 22:44:31 -0000
@@ -195,6 +195,7 @@
 	GnomeVFSHandle *handle;
 	GnomeVFSURI *uri;
 	gchar *temp = NULL;
+	gboolean doit = TRUE;
 
 	if (!dest_uri)
 		return;
@@ -211,13 +212,38 @@
 	}
 
 	uri = gnome_vfs_uri_new (dest_uri);
-	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
-	if (result != GNOME_VFS_OK) {
-		gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
+
+	result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_READ);
+	if (result == GNOME_VFS_OK)
+	{
+		GtkWidget *warning = 
+		  gtk_message_dialog_new_with_markup (NULL,
+				GTK_DIALOG_DESTROY_WITH_PARENT,
+				GTK_MESSAGE_WARNING,
+				GTK_BUTTONS_NONE,
+				_("<b>A file %s already exists.</b>\n"
+				  "If you choose to overwrite this file, "
+				  "the contents will be lost."), dest_uri);
+
+		gtk_dialog_add_button (GTK_DIALOG (warning), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+		gtk_dialog_add_button (GTK_DIALOG (warning), _("_Overwrite"), GTK_RESPONSE_YES);
+
+		doit = FALSE;
+		if (gtk_dialog_run (GTK_DIALOG (warning)) == GTK_RESPONSE_YES)
+			doit = TRUE;
+		gtk_widget_destroy (warning);
+	} 
+
+	if (doit) {
 		result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+		if (result != GNOME_VFS_OK) {
+			gnome_vfs_create (&handle, dest_uri, GNOME_VFS_OPEN_WRITE, TRUE, GNOME_VFS_PERM_USER_ALL);
+			result = gnome_vfs_open_uri (&handle, uri, GNOME_VFS_OPEN_WRITE);
+		} 
 	}
 
-	if (result == GNOME_VFS_OK && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
+
+	if (result == GNOME_VFS_OK && doit && e_cal_get_object_list_as_comp (source_client, "#t", &objects, NULL)) {
 		xmlBufferPtr buffer=xmlBufferCreate();
 		xmlDocPtr doc = xmlNewDoc((xmlChar *) "1.0");
 		xmlNodePtr fnode = doc->children;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]