changeset 1231:ca8ccf0c3e81

added done callback to utilops used the callback for metadata writting at exit and for renaming new folder
author nadvornik
date Fri, 02 Jan 2009 14:58:21 +0000
parents d13233ab7def
children 98be4a5e36f8
files src/layout.c src/layout_util.c src/main.c src/metadata.c src/metadata.h src/typedefs.h src/utilops.c src/utilops.h src/view_dir.c
diffstat 9 files changed, 64 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/layout.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/layout.c	Fri Jan 02 14:58:21 2009 +0000
@@ -1047,7 +1047,7 @@
 		}
 
 	if (options->metadata.confirm_on_dir_change)
-		metadata_write_queue_confirm();
+		metadata_write_queue_confirm(NULL, NULL);
 
 	return TRUE;
 }
--- a/src/layout_util.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/layout_util.c	Fri Jan 02 14:58:21 2009 +0000
@@ -251,7 +251,7 @@
 {
 	LayoutWindow *lw = data;
 
-	file_util_create_dir(lw->dir_fd, layout_window(lw));
+	file_util_create_dir(lw->dir_fd, layout_window(lw), NULL, NULL);
 }
 
 static void layout_menu_copy_cb(GtkAction *action, gpointer data)
@@ -2040,7 +2040,7 @@
 
 	/* this should be called here to handle the metadata edited in bars */
 	if (options->metadata.confirm_on_image_change)
-		metadata_write_queue_confirm();
+		metadata_write_queue_confirm(NULL, NULL);
 }
 
 void layout_bars_new_selection(LayoutWindow *lw, gint count)
--- a/src/main.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/main.c	Fri Jan 02 14:58:21 2009 +0000
@@ -645,11 +645,16 @@
 	return TRUE;
 }
 
+static void exit_program_write_metadata_cb(gint success, const gchar *dest_path, gpointer data)
+{
+	if (success) exit_program();
+}
+
 void exit_program(void)
 {
 	layout_image_full_screen_stop(NULL);
 
-	if (metadata_write_queue_confirm()) return;
+	if (metadata_write_queue_confirm(exit_program_write_metadata_cb, NULL)) return;
 
 	if (exit_confirm_dlg()) return;
 
--- a/src/metadata.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/metadata.c	Fri Jan 02 14:58:21 2009 +0000
@@ -99,7 +99,7 @@
 }
 
 
-gboolean metadata_write_queue_confirm()
+gboolean metadata_write_queue_confirm(FileUtilDoneFunc done_func, gpointer done_data)
 {
 	GList *work;
 	GList *to_approve = NULL;
@@ -115,7 +115,7 @@
 		to_approve = g_list_prepend(to_approve, file_data_ref(fd));
 		}
 
-	file_util_write_metadata(NULL, to_approve, NULL);
+	file_util_write_metadata(NULL, to_approve, NULL, done_func, done_data);
 	
 	filelist_free(to_approve);
 	
@@ -124,7 +124,7 @@
 
 static gboolean metadata_write_queue_idle_cb(gpointer data)
 {
-	metadata_write_queue_confirm();
+	metadata_write_queue_confirm(NULL, NULL);
 	metadata_write_idle_id = -1;
 	return FALSE;
 }
--- a/src/metadata.h	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/metadata.h	Fri Jan 02 14:58:21 2009 +0000
@@ -17,7 +17,7 @@
 gboolean metadata_write_queue_remove(FileData *fd);
 gboolean metadata_write_queue_remove_list(GList *list);
 gboolean metadata_write_perform(FileData *fd);
-gboolean metadata_write_queue_confirm(void);
+gboolean metadata_write_queue_confirm(FileUtilDoneFunc done_func, gpointer done_data);
 
 
 
--- a/src/typedefs.h	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/typedefs.h	Fri Jan 02 14:58:21 2009 +0000
@@ -212,6 +212,8 @@
 
 typedef void (* ThumbLoaderFunc)(ThumbLoader *tl, gpointer data);
 
+typedef void (* FileUtilDoneFunc)(gboolean success, const gchar *done_path, gpointer data);
+
 struct _ThumbLoader
 {
 	gint standard_loader;
--- a/src/utilops.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/utilops.c	Fri Jan 02 14:58:21 2009 +0000
@@ -314,6 +314,9 @@
 	
 	gint external_command;
 	gpointer resume_data;
+	
+	FileUtilDoneFunc done_func;
+	gpointer done_data;
 };
 
 enum {
@@ -1566,6 +1569,10 @@
 				{
 				metadata_write_queue_remove_list(ud->flist);
 				}
+			
+			if (ud->done_func)
+				ud->done_func((ud->phase == UTILITY_PHASE_DONE), ud->dest_path, ud->done_data);
+				
 			if (ud->with_sidecars)
 				file_data_sc_free_ci_list(ud->flist);
 			else
@@ -1641,7 +1648,7 @@
 	file_util_dialog_run(ud);
 }
 
-static void file_util_write_metadata_full(FileData *source_fd, GList *source_list, GtkWidget *parent, UtilityPhase phase)
+static void file_util_write_metadata_full(FileData *source_fd, GList *source_list, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
 {
 	UtilityData *ud;
 	GList *flist = filelist_copy(source_list);
@@ -1669,6 +1676,9 @@
 	ud->content_list = NULL;
 	ud->parent = parent;
 	
+	ud->done_func = done_func;
+	ud->done_data = done_data;
+	
 	ud->messages.title = _("Write metadata");
 	ud->messages.question = _("Write metadata?");
 	ud->messages.desc_flist = _("This will write the changed metadata into the following files");
@@ -2232,7 +2242,7 @@
 	file_util_dialog_run(ud);
 }
 
-static void file_util_create_dir_full(FileData *fd, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase)
+static void file_util_create_dir_full(FileData *fd, const gchar *dest_path, GtkWidget *parent, UtilityPhase phase, FileUtilDoneFunc done_func, gpointer done_data)
 {
 	UtilityData *ud; 
 
@@ -2258,6 +2268,9 @@
 		}
 	
 	ud->dir_fd = file_data_new_simple(ud->dest_path);
+
+	ud->done_func = done_func;
+	ud->done_data = done_data;
 	
 	ud->messages.title = _("Create Folder");
 	ud->messages.question = _("Create folder?");
@@ -2277,10 +2290,11 @@
 	file_util_delete_full(source_fd, source_list, parent, options->file_ops.confirm_delete ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING);
 }
 
-void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent)
+void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
 {
 	file_util_write_metadata_full(source_fd, source_list, parent, 
-	                              (options->metadata.save_in_image_file && options->metadata.confirm_write) ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING);
+	                              (options->metadata.save_in_image_file && options->metadata.confirm_write) ? UTILITY_PHASE_START : UTILITY_PHASE_ENTERING,
+	                              done_func, done_data);
 }
 
 void file_util_copy(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent)
@@ -2342,9 +2356,9 @@
 	file_util_delete_dir_full(fd, parent, UTILITY_PHASE_START);
 }
 
-void file_util_create_dir(FileData *dir_fd, GtkWidget *parent)
+void file_util_create_dir(FileData *dir_fd, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data)
 {
-	file_util_create_dir_full(dir_fd, NULL, parent, UTILITY_PHASE_ENTERING);
+	file_util_create_dir_full(dir_fd, NULL, parent, UTILITY_PHASE_ENTERING, done_func, done_data);
 }
 
 void file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent)
--- a/src/utilops.h	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/utilops.h	Fri Jan 02 14:58:21 2009 +0000
@@ -17,7 +17,6 @@
 
 #include "ui_utildlg.h"
 
-
 void file_maint_renamed(FileData *fd);
 void file_maint_removed(FileData *fd, GList *ignore_list);
 void file_maint_moved(FileData *fd, GList *ignore_list);
@@ -38,9 +37,10 @@
 void file_util_move(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent);
 void file_util_copy(FileData *source_fd, GList *source_list, const gchar *dest_path, GtkWidget *parent);
 void file_util_rename(FileData *source_fd, GList *source_list, GtkWidget *parent);
-void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent);
+void file_util_write_metadata(FileData *source_fd, GList *source_list, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data);
 
-void file_util_create_dir(FileData *dir_fd, GtkWidget *parent);
+void file_util_create_dir(FileData *dir_fd, GtkWidget *parent, FileUtilDoneFunc done_func, gpointer done_data);
+
 void file_util_rename_dir(FileData *source_fd, const gchar *new_path, GtkWidget *parent);
 
 /* these avoid the location entry dialog, list must be files only and
--- a/src/view_dir.c	Fri Jan 02 09:39:14 2009 +0000
+++ b/src/view_dir.c	Fri Jan 02 14:58:21 2009 +0000
@@ -506,6 +506,31 @@
 	if (vd->layout) layout_refresh(vd->layout);
 }
 
+static void vd_pop_menu_new_rename_cb(gboolean success, const gchar *new_path, gpointer data)
+{
+	ViewDir *vd = data;
+	FileData *fd = NULL;
+	if (!success) return;
+
+	switch(vd->type)
+		{
+		case DIRVIEW_LIST:
+			{
+			vd_refresh(vd);
+			fd = vdlist_row_by_path(vd, new_path, NULL);
+			};
+			break;
+		case DIRVIEW_TREE:
+			{
+			FileData *new_fd = file_data_new_simple(new_path);
+			fd = vdtree_populate_path(vd, new_fd, TRUE, TRUE);
+			file_data_unref(new_fd);
+			}
+			break;
+		}
+	vd_rename_by_data(vd, fd);
+}
+
 static void vd_pop_menu_new_cb(GtkWidget *widget, gpointer data)
 {
 	ViewDir *vd = data;
@@ -527,41 +552,7 @@
 			break;
 		}
 
-	file_util_create_dir(dir_fd, widget);
-
-/* FIXME:*/
-#if 0
-	if (!mkdir_utf8(new_path, 0755))
-		{
-		gchar *text;
-
-		text = g_strdup_printf(_("Unable to create folder:\n%s"), new_path);
-		file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, vd->view);
-		g_free(text);
-		}
-	else
-		{
-		FileData *fd = NULL;
-
-		switch(vd->type)
-			{
-			case DIRVIEW_LIST:
-				{
-				vd_refresh(vd);
-				fd = vdlist_row_by_path(vd, new_path, NULL);
-				};
-				break;
-			case DIRVIEW_TREE:
-				{
-				FileData *new_fd = file_data_new_simple(new_path);
-				fd = vdtree_populate_path(vd, new_fd, TRUE, TRUE);
-				file_data_unref(new_fd);
-				}
-				break;
-			}
-		vd_rename_by_data(vd, fd);
-		}
-#endif
+	file_util_create_dir(dir_fd, widget, vd_pop_menu_new_rename_cb, vd);
 }
 
 static void vd_pop_menu_rename_cb(GtkWidget *widget, gpointer data)