changeset 928:6a42ab7051f2

improved error reporting
author nadvornik
date Fri, 25 Jul 2008 22:04:55 +0000
parents d27b4184ceb8
children ca07ab364c60
files src/filedata.c src/filedata.h src/utilops.c
diffstat 3 files changed, 104 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.c	Fri Jul 25 06:35:35 2008 +0000
+++ b/src/filedata.c	Fri Jul 25 22:04:55 2008 +0000
@@ -1569,7 +1569,7 @@
  * FIXME: add more tests
  */
 
-gint file_data_check_ci_dest(FileData *fd)
+gint file_data_verify_ci(FileData *fd)
 {
 	gint ret = CHANGE_OK;
 	
@@ -1596,26 +1596,113 @@
 }
 
  
-gint file_data_sc_check_ci_dest(FileData *fd)
+gint file_data_sc_verify_ci(FileData *fd)
 {
 	GList *work;
-	int ret;
+	gint ret;
 
-	ret = file_data_check_ci_dest(fd);
+	ret = file_data_verify_ci(fd);
 
 	work = fd->sidecar_files;
 	while (work)
 		{
 		FileData *sfd = work->data;
 
-		ret |= file_data_check_ci_dest(sfd);
+		ret |= file_data_verify_ci(sfd);
 		work = work->next;
 		}
 
 	return ret;
 }
 
+gchar *file_data_get_error_string(gint error)
+{
+	GString *result = g_string_new("");
 
+	if (error & CHANGE_NO_PERM)
+		{
+		if (result->len > 0) g_string_append(result, ", ");
+		g_string_append(result, _("no read permission"));
+		}
+
+	if (error & CHANGE_DEST_EXISTS)
+		{
+		if (result->len > 0) g_string_append(result, ", ");
+		g_string_append(result, _("destination file already exists and will be overwritten"));
+		}
+
+	return g_string_free(result, FALSE);
+}
+
+gint file_data_sc_verify_ci_list(GList *list, gchar **desc)
+{
+	gint all_errors = 0;
+	gint common_errors = ~0; 
+	gint num;
+	gint *errors;
+	gint i;
+	
+	if (!list) return 0;
+	
+	num = g_list_length(list);
+	errors = g_new(int, num);
+	GList *work = list;
+	i = 0;
+	while (work)
+		{
+		FileData *fd;
+		gint error;
+
+		fd = work->data;
+		work = work->next;
+			
+		error = file_data_sc_verify_ci(fd);
+		all_errors |= error;
+		common_errors &= error;
+		
+		errors[i] = error;
+		
+		i++;
+		}
+	
+	if (desc && all_errors)
+		{
+		GString *result = g_string_new("");
+		
+		if (common_errors)
+			{
+			gchar *str = file_data_get_error_string(common_errors);
+			g_string_append(result, str);
+			g_string_append(result, "\n");
+			g_free(str);
+			}
+		
+		GList *work = list;
+		i = 0;
+		while (work)
+			{
+			FileData *fd;
+			gint error;
+
+			fd = work->data;
+			work = work->next;
+			
+			error = errors[i] & ~common_errors;
+			
+			if (error)
+				{
+				gchar *str = file_data_get_error_string(error);
+				g_string_append_printf(result, "%s: %s\n", fd->name, str);
+				g_free(str);
+				}
+			i++;
+			}
+		*desc = g_string_free(result, FALSE);
+		}
+
+	g_free(errors);
+	return all_errors;
+}
 
 
 /*
--- a/src/filedata.h	Fri Jul 25 06:35:35 2008 +0000
+++ b/src/filedata.h	Fri Jul 25 22:04:55 2008 +0000
@@ -91,7 +91,10 @@
 gint file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path);
 gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path);
 gint file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path);
-gint file_data_sc_check_ci_dest(FileData *fd);
+gint file_data_sc_verify_ci(FileData *fd);
+gchar *file_data_get_error_string(gint error);
+gint file_data_sc_verify_ci_list(GList *list, gchar **desc);
+
 gboolean file_data_sc_perform_ci(FileData *fd);
 gint file_data_sc_apply_ci(FileData *fd);
 void file_data_sc_free_ci(FileData *fd);
--- a/src/utilops.c	Fri Jul 25 06:35:35 2008 +0000
+++ b/src/utilops.c	Fri Jul 25 22:04:55 2008 +0000
@@ -833,7 +833,7 @@
 		pb_error = gtk_widget_render_icon(widget, GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU, NULL); 
 		}
 	
-	error = file_data_sc_check_ci_dest(fd);
+	error = file_data_sc_verify_ci(fd);
 	
 	if (!error) return NULL;
 
@@ -864,23 +864,16 @@
 void file_util_check_ci(UtilityData *ud)
 {
 	gint error = CHANGE_OK;
+	gchar *desc = NULL;
 	
 	if (ud->dir_fd)
 		{
-		error = file_data_sc_check_ci_dest(ud->dir_fd);
+		error = file_data_sc_verify_ci(ud->dir_fd);
+		if (error) desc = file_data_get_error_string(error);
 		}
 	else
 		{
-		GList *work = ud->flist;
-		while (work)
-			{
-			FileData *fd;
-
-			fd = work->data;
-			work = work->next;
-			
-			error |= file_data_sc_check_ci_dest(fd);
-			}
+		error = file_data_sc_verify_ci_list(ud->flist, &desc);
 		}
 
 	if (!error)
@@ -900,12 +893,11 @@
 					ud->parent, TRUE,
 					file_util_check_abort_cb, ud);
 
-		generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, NULL, "Really continue?");
+		generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, _("Really continue?"), desc);
 
 		generic_dialog_add_button(d, GTK_STOCK_GO_FORWARD, _("Co_ntinue"),
 					  file_util_check_resume_cb, TRUE);
 		gtk_widget_show(d->dialog);
-		return;
 		}
 	else
 		{
@@ -915,12 +907,11 @@
 		d = file_util_gen_dlg("This operation can't continue", GQ_WMCLASS, "dlg_confirm",
 					ud->parent, TRUE,
 					file_util_check_abort_cb, ud);
-		generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, NULL, "This operation can't continue");
+		generic_dialog_add_message(d, GTK_STOCK_DIALOG_WARNING, "This operation can't continue", desc);
 
 		gtk_widget_show(d->dialog);
-		return;
 		}
-
+	g_free(desc);
 }