[gthumb] pressing the delete key in a catalog removes the file from the catalog instead of deleting the file



commit 8743701164ee234544572359716dbd468a69317a
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 22 14:38:24 2011 +0200

    pressing the delete key in a catalog removes the file from the catalog instead of deleting the file from disk
    
    [bug #623620]

 extensions/catalogs/actions.c                  |  124 ++------------------
 extensions/catalogs/gth-file-source-catalogs.c |  149 +++++++++++++++++++++++-
 extensions/catalogs/gth-file-source-catalogs.h |    5 +-
 extensions/file_manager/callbacks.c            |    1 +
 gthumb/gth-file-source-vfs.c                   |    1 +
 gthumb/gth-file-source.c                       |   17 ++-
 gthumb/gth-file-source.h                       |    2 +
 7 files changed, 172 insertions(+), 127 deletions(-)
---
diff --git a/extensions/catalogs/actions.c b/extensions/catalogs/actions.c
index 6e4a16e..daa720c 100644
--- a/extensions/catalogs/actions.c
+++ b/extensions/catalogs/actions.c
@@ -25,6 +25,7 @@
 #include <gth-catalog.h>
 #include "dlg-add-to-catalog.h"
 #include "dlg-catalog-properties.h"
+#include "gth-file-source-catalogs.h"
 
 
 void
@@ -46,128 +47,21 @@ gth_browser_activate_action_edit_add_to_catalog (GtkAction  *action,
 }
 
 
-typedef struct {
-	GthBrowser *browser;
-	GList      *file_data_list;
-	GFile      *gio_file;
-	GthCatalog *catalog;
-} RemoveFromCatalogData;
-
-
-static void
-remove_from_catalog_end (GError                *error,
-			 RemoveFromCatalogData *data)
-{
-	if (error != NULL)
-		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->browser), _("Could not remove the files from the catalog"), &error);
-
-	g_object_unref (data->catalog);
-	g_object_unref (data->gio_file);
-	_g_object_list_unref (data->file_data_list);
-	g_free (data);
-}
-
-
-static void
-catalog_save_done_cb (void     **buffer,
-		      gsize      count,
-		      GError    *error,
-		      gpointer   user_data)
-{
-	RemoveFromCatalogData *data = user_data;
-
-	if (error == NULL) {
-		GFile *catalog_file;
-		GList *files = NULL;
-		GList *scan;
-
-		catalog_file = gth_catalog_file_from_gio_file (data->gio_file, NULL);
-		for (scan = data->file_data_list; scan; scan = scan->next)
-			files = g_list_prepend (files, ((GthFileData*) scan->data)->file);
-		files = g_list_reverse (files);
-
-		gth_monitor_folder_changed (gth_main_get_default_monitor (),
-					    catalog_file,
-					    files,
-					    GTH_MONITOR_EVENT_REMOVED);
-
-		_g_object_list_unref (files);
-		g_object_unref (catalog_file);
-	}
-
-	remove_from_catalog_end (error, data);
-}
-
-
-static void
-catalog_buffer_ready_cb (void     **buffer,
-			 gsize      count,
-			 GError    *error,
-			 gpointer   user_data)
-{
-	RemoveFromCatalogData *data = user_data;
-	GList                 *scan;
-	void                  *catalog_buffer;
-	gsize                  catalog_size;
-
-	if (error != NULL) {
-		remove_from_catalog_end (error, data);
-		return;
-	}
-
-	data->catalog = gth_hook_invoke_get ("gth-catalog-load-from-data", *buffer);
-	if (data->catalog == NULL) {
-		error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _("Invalid file format"));
-		remove_from_catalog_end (error, data);
-		return;
-	}
-
-	gth_catalog_load_from_data (data->catalog, *buffer, count, &error);
-	if (error != NULL) {
-		remove_from_catalog_end (error, data);
-		return;
-	}
-
-	for (scan = data->file_data_list; scan; scan = scan->next) {
-		GthFileData *file_data = scan->data;
-		gth_catalog_remove_file (data->catalog, file_data->file);
-	}
-
-	catalog_buffer = gth_catalog_to_data (data->catalog, &catalog_size);
-	if (error != NULL) {
-		remove_from_catalog_end (error, data);
-		return;
-	}
-
-	g_write_file_async (data->gio_file,
-			    catalog_buffer,
-			    catalog_size,
-			    TRUE,
-			    G_PRIORITY_DEFAULT,
-			    NULL,
-			    catalog_save_done_cb,
-			    data);
-}
-
-
 void
 gth_browser_activate_action_edit_remove_from_catalog (GtkAction  *action,
 						      GthBrowser *browser)
 {
-	RemoveFromCatalogData *data;
-	GList                 *items;
+	GList *items;
+	GList *file_data_list;
 
-	data = g_new0 (RemoveFromCatalogData, 1);
-	data->browser = browser;
 	items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
-	data->file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
-	data->gio_file = gth_main_get_gio_file (gth_browser_get_location (browser));
-	g_load_file_async (data->gio_file,
-			   G_PRIORITY_DEFAULT,
-			   NULL,
-			   catalog_buffer_ready_cb,
-			   data);
+	file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+
+	gth_catalog_manager_remove_files (GTK_WINDOW (browser),
+					  gth_browser_get_location_data (browser),
+					  file_data_list);
 
+	_g_object_list_unref (file_data_list);
 	_gtk_tree_path_list_free (items);
 }
 
diff --git a/extensions/catalogs/gth-file-source-catalogs.c b/extensions/catalogs/gth-file-source-catalogs.c
index ca05bc9..8f11d79 100644
--- a/extensions/catalogs/gth-file-source-catalogs.c
+++ b/extensions/catalogs/gth-file-source-catalogs.c
@@ -680,10 +680,10 @@ copy_op_data_free (CopyOpData *cod)
 
 
 static void
-catalog_save_done_cb (void     **buffer,
-		      gsize      count,
-		      GError    *error,
-		      gpointer   user_data)
+copy__catalog_save_done_cb (void     **buffer,
+			    gsize      count,
+			    GError    *error,
+			    gpointer   user_data)
 {
 	CopyOpData *cod = user_data;
 
@@ -728,7 +728,7 @@ catalog_ready_cb (GObject  *catalog,
 			    TRUE,
 			    G_PRIORITY_DEFAULT,
 			    NULL,
-			    catalog_save_done_cb,
+			    copy__catalog_save_done_cb,
 			    cod);
 
 	g_object_unref (gio_file);
@@ -1252,6 +1252,143 @@ gth_file_source_catalogs_reorder (GthFileSource *file_source,
 }
 
 
+/* -- gth_catalog_manager_remove_files -- */
+
+
+typedef struct {
+	GtkWindow  *parent;
+	GList      *file_data_list;
+	GFile      *gio_file;
+	GthCatalog *catalog;
+} RemoveFromCatalogData;
+
+
+static void
+remove_from_catalog_end (GError                *error,
+			 RemoveFromCatalogData *data)
+{
+	if (error != NULL)
+		_gtk_error_dialog_from_gerror_show (data->parent, _("Could not remove the files from the catalog"), &error);
+
+	g_object_unref (data->catalog);
+	g_object_unref (data->gio_file);
+	_g_object_list_unref (data->file_data_list);
+	g_free (data);
+}
+
+
+static void
+remove_files__catalog_save_done_cb (void     **buffer,
+				    gsize      count,
+				    GError    *error,
+				    gpointer   user_data)
+{
+	RemoveFromCatalogData *data = user_data;
+
+	if (error == NULL) {
+		GFile *catalog_file;
+		GList *files = NULL;
+		GList *scan;
+
+		catalog_file = gth_catalog_file_from_gio_file (data->gio_file, NULL);
+		for (scan = data->file_data_list; scan; scan = scan->next)
+			files = g_list_prepend (files, g_object_ref (((GthFileData*) scan->data)->file));
+		files = g_list_reverse (files);
+
+		gth_monitor_folder_changed (gth_main_get_default_monitor (),
+					    catalog_file,
+					    files,
+					    GTH_MONITOR_EVENT_REMOVED);
+
+		_g_object_list_unref (files);
+		g_object_unref (catalog_file);
+	}
+
+	remove_from_catalog_end (error, data);
+}
+
+
+static void
+catalog_buffer_ready_cb (void     **buffer,
+			 gsize      count,
+			 GError    *error,
+			 gpointer   user_data)
+{
+	RemoveFromCatalogData *data = user_data;
+	GList                 *scan;
+	void                  *catalog_buffer;
+	gsize                  catalog_size;
+
+	if (error != NULL) {
+		remove_from_catalog_end (error, data);
+		return;
+	}
+
+	data->catalog = gth_hook_invoke_get ("gth-catalog-load-from-data", *buffer);
+	if (data->catalog == NULL) {
+		error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _("Invalid file format"));
+		remove_from_catalog_end (error, data);
+		return;
+	}
+
+	gth_catalog_load_from_data (data->catalog, *buffer, count, &error);
+	if (error != NULL) {
+		remove_from_catalog_end (error, data);
+		return;
+	}
+
+	for (scan = data->file_data_list; scan; scan = scan->next) {
+		GthFileData *file_data = scan->data;
+		gth_catalog_remove_file (data->catalog, file_data->file);
+	}
+
+	catalog_buffer = gth_catalog_to_data (data->catalog, &catalog_size);
+	if (error != NULL) {
+		remove_from_catalog_end (error, data);
+		return;
+	}
+
+	g_write_file_async (data->gio_file,
+			    catalog_buffer,
+			    catalog_size,
+			    TRUE,
+			    G_PRIORITY_DEFAULT,
+			    NULL,
+			    remove_files__catalog_save_done_cb,
+			    data);
+}
+
+
+void
+gth_catalog_manager_remove_files (GtkWindow   *parent,
+				  GthFileData *location,
+				  GList       *file_list)
+{
+	RemoveFromCatalogData *data;
+
+	data = g_new0 (RemoveFromCatalogData, 1);
+	data->parent = parent;
+	data->file_data_list = gth_file_data_list_dup (file_list);
+	data->gio_file = gth_main_get_gio_file (location->file);
+
+	g_load_file_async (data->gio_file,
+			   G_PRIORITY_DEFAULT,
+			   NULL,
+			   catalog_buffer_ready_cb,
+			   data);
+}
+
+
+static void
+gth_file_source_catalogs_remove (GthFileSource *file_source,
+				 GthFileData   *location,
+	       	       	         GList         *file_list /* GthFileData list */,
+	       	       	         gboolean       permanently,
+	       	       	         GtkWindow     *parent)
+{
+	gth_catalog_manager_remove_files (parent, location, file_list);
+}
+
 
 static void
 gth_file_source_catalogs_finalize (GObject *object)
@@ -1293,7 +1430,7 @@ gth_file_source_catalogs_class_init (GthFileSourceCatalogsClass *class)
 	file_source_class->can_cut = gth_file_source_catalogs_can_cut;
 	file_source_class->is_reorderable  = gth_file_source_catalogs_is_reorderable;
 	file_source_class->reorder = gth_file_source_catalogs_reorder;
-
+	file_source_class->remove = gth_file_source_catalogs_remove;
 }
 
 
diff --git a/extensions/catalogs/gth-file-source-catalogs.h b/extensions/catalogs/gth-file-source-catalogs.h
index a7a8f1a..bd2c7fa 100644
--- a/extensions/catalogs/gth-file-source-catalogs.h
+++ b/extensions/catalogs/gth-file-source-catalogs.h
@@ -43,9 +43,12 @@ struct _GthFileSourceCatalogs
 
 struct _GthFileSourceCatalogsClass
 {
-	GthFileSourceClass __parent_class;	
+	GthFileSourceClass __parent_class;
 };
 
 GType gth_file_source_catalogs_get_type (void) G_GNUC_CONST;
+void  gth_catalog_manager_remove_files  (GtkWindow   *parent,
+				  	 GthFileData *location,
+				  	 GList       *file_list /* GthFileData list */);
 
 #endif /* GTH_FILE_SOURCE_CATALOGS_H */
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index f4b8502..456984c 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -1075,6 +1075,7 @@ fm__gth_browser_file_list_key_press_cb (GthBrowser  *browser,
 				items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
 				file_data_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
 				gth_file_source_remove (gth_browser_get_location_source (browser),
+							gth_browser_get_location_data (browser),
 							file_data_list,
 							(event->state & modifiers) == GDK_SHIFT_MASK,
 							GTK_WINDOW (browser));
diff --git a/gthumb/gth-file-source-vfs.c b/gthumb/gth-file-source-vfs.c
index d3405bd..1a48b91 100644
--- a/gthumb/gth-file-source-vfs.c
+++ b/gthumb/gth-file-source-vfs.c
@@ -804,6 +804,7 @@ gth_file_mananger_delete_files (GtkWindow *window,
 
 static void
 gth_file_source_vfs_remove (GthFileSource *file_source,
+			    GthFileData   *location,
 	       	       	    GList         *file_list /* GthFileData list */,
 	       	       	    gboolean       permanently,
 	       	       	    GtkWindow     *parent)
diff --git a/gthumb/gth-file-source.c b/gthumb/gth-file-source.c
index ce6a436..a0ca471 100644
--- a/gthumb/gth-file-source.c
+++ b/gthumb/gth-file-source.c
@@ -131,9 +131,10 @@ typedef struct {
 
 
 typedef struct {
-	GList     *file_list;
-	gboolean   permanently;
-	GtkWindow *parent;
+	GthFileData *location;
+	GList       *file_list;
+	gboolean     permanently;
+	GtkWindow   *parent;
 } RemoveData;
 
 
@@ -188,6 +189,7 @@ file_source_async_op_free (FileSourceAsyncOp *async_op)
 		_g_object_list_unref (async_op->data.copy.file_list);
 		break;
 	case FILE_SOURCE_OP_REMOVE:
+		_g_object_unref (async_op->data.remove.location);
 		_g_object_list_unref (async_op->data.remove.file_list);
 		break;
 	}
@@ -382,6 +384,7 @@ gth_file_source_queue_reorder (GthFileSource    *file_source,
 
 static void
 gth_file_source_queue_remove (GthFileSource *file_source,
+			      GthFileData   *location,
 			      GList         *file_list,
 			      gboolean       permanently,
 			      GtkWindow     *parent)
@@ -391,6 +394,7 @@ gth_file_source_queue_remove (GthFileSource *file_source,
 	async_op = g_new0 (FileSourceAsyncOp, 1);
 	async_op->file_source = file_source;
 	async_op->op = FILE_SOURCE_OP_REMOVE;
+	async_op->data.remove.location = gth_file_data_dup (location);
 	async_op->data.remove.file_list = gth_file_data_list_dup (file_list);
 	async_op->data.remove.permanently = permanently;
 	async_op->data.remove.parent = parent;
@@ -481,6 +485,7 @@ gth_file_source_exec_next_in_queue (GthFileSource *file_source)
 		break;
 	case FILE_SOURCE_OP_REMOVE:
 		gth_file_source_remove (file_source,
+					async_op->data.remove.location,
 					async_op->data.remove.file_list,
 					async_op->data.remove.permanently,
 					async_op->data.remove.parent);
@@ -715,6 +720,7 @@ base_reorder (GthFileSource *file_source,
 
 static void
 base_remove (GthFileSource *file_source,
+	     GthFileData   *location,
 	     GList         *file_list, /* GFile list */
 	     gboolean       permanently)
 {
@@ -1232,14 +1238,15 @@ gth_file_source_reorder (GthFileSource *file_source,
 
 void
 gth_file_source_remove (GthFileSource *file_source,
+			GthFileData   *location,
 		        GList         *file_list, /* GthFileData list */
 		        gboolean       permanently,
 		        GtkWindow     *parent)
 {
 	if (gth_file_source_is_active (file_source)) {
-		gth_file_source_queue_remove (file_source, file_list, permanently, parent);
+		gth_file_source_queue_remove (file_source, location, file_list, permanently, parent);
 		return;
 	}
 	g_cancellable_reset (file_source->priv->cancellable);
-	GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->remove (file_source, file_list, permanently, parent);
+	GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->remove (file_source, location, file_list, permanently, parent);
 }
diff --git a/gthumb/gth-file-source.h b/gthumb/gth-file-source.h
index 9527939..90334e8 100644
--- a/gthumb/gth-file-source.h
+++ b/gthumb/gth-file-source.h
@@ -122,6 +122,7 @@ struct _GthFileSourceClass
 					       ReadyCallback         callback,
 					       gpointer              data);
 	void         (*remove)                (GthFileSource        *file_source,
+					       GthFileData          *location,
 					       GList                *file_list, /* GthFileData list */
 					       gboolean              permanently,
 					       GtkWindow            *parent);
@@ -204,6 +205,7 @@ void           gth_file_source_reorder               (GthFileSource        *file
 						      ReadyCallback         callback,
 						      gpointer              data);
 void           gth_file_source_remove                (GthFileSource        *file_source,
+						      GthFileData          *location,
 		       	       	       	       	      GList                *file_list /* GthFileData list */,
 		       	       	       	       	      gboolean              permanently,
 		       	       	       	       	      GtkWindow            *parent);



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