[gthumb] gth-file-source: added the remove virtual function



commit de1c8d3e9249bed23db43af526ebb860eede79dc
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 22 10:29:16 2011 +0200

    gth-file-source: added the remove virtual function

 gthumb/gth-file-source.c |   51 ++++++++++-
 gthumb/gth-file-source.h |  246 +++++++++++++++++++++++-----------------------
 2 files changed, 175 insertions(+), 122 deletions(-)
---
diff --git a/gthumb/gth-file-source.c b/gthumb/gth-file-source.c
index ff127cc..4b6dd50 100644
--- a/gthumb/gth-file-source.c
+++ b/gthumb/gth-file-source.c
@@ -53,7 +53,8 @@ typedef enum {
 	FILE_SOURCE_OP_READ_ATTRIBUTES,
 	FILE_SOURCE_OP_RENAME,
 	FILE_SOURCE_OP_COPY,
-	FILE_SOURCE_OP_REORDER
+	FILE_SOURCE_OP_REORDER,
+	FILE_SOURCE_OP_REMOVE
 } FileSourceOp;
 
 
@@ -130,6 +131,10 @@ typedef struct {
 
 
 typedef struct {
+	GList *file_list;
+} RemoveData;
+
+typedef struct {
 	GthFileSource *file_source;
 	FileSourceOp   op;
 	union {
@@ -141,6 +146,7 @@ typedef struct {
 		ReorderData        reorder;
 		WriteMetadataData  write_metadata;
 		ReadMetadataData   read_metadata;
+		RemoveData         remove;
 	} data;
 } FileSourceAsyncOp;
 
@@ -178,6 +184,9 @@ file_source_async_op_free (FileSourceAsyncOp *async_op)
 		g_object_unref (async_op->data.copy.destination);
 		_g_object_list_unref (async_op->data.copy.file_list);
 		break;
+	case FILE_SOURCE_OP_REMOVE:
+		_g_object_list_unref (async_op->data.remove.file_list);
+		break;
 	}
 
 	g_free (async_op);
@@ -369,6 +378,21 @@ gth_file_source_queue_reorder (GthFileSource    *file_source,
 
 
 static void
+gth_file_source_queue_remove (GthFileSource *file_source,
+			      GList         *file_list)
+{
+	FileSourceAsyncOp *async_op;
+
+	async_op = g_new0 (FileSourceAsyncOp, 1);
+	async_op->file_source = file_source;
+	async_op->op = FILE_SOURCE_OP_REMOVE;
+	async_op->data.remove.file_list = _g_file_list_dup (file_list);
+
+	file_source->priv->queue = g_list_append (file_source->priv->queue, async_op);
+}
+
+
+static void
 gth_file_source_exec_next_in_queue (GthFileSource *file_source)
 {
 	GList             *head;
@@ -448,6 +472,10 @@ gth_file_source_exec_next_in_queue (GthFileSource *file_source)
 				         async_op->data.reorder.ready_callback,
 					 async_op->data.reorder.data);
 		break;
+	case FILE_SOURCE_OP_REMOVE:
+		gth_file_source_remove (file_source,
+					async_op->data.remove.file_list);
+		break;
 	}
 
 	file_source_async_op_free (async_op);
@@ -677,6 +705,14 @@ base_reorder (GthFileSource *file_source,
 
 
 static void
+base_remove (GthFileSource *file_source,
+	     GList         *file_list /* GFile list */)
+{
+	/* void */
+}
+
+
+static void
 gth_file_source_finalize (GObject *object)
 {
 	GthFileSource *file_source = GTH_FILE_SOURCE (object);
@@ -716,6 +752,7 @@ gth_file_source_class_init (GthFileSourceClass *class)
 	class->monitor_directory = base_monitor_directory;
 	class->is_reorderable = base_is_reorderable;
 	class->reorder = base_reorder;
+	class->remove = base_remove;
 }
 
 
@@ -1182,3 +1219,15 @@ gth_file_source_reorder (GthFileSource *file_source,
 	GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->reorder (file_source, destination, visible_files, files_to_move, dest_pos, callback, data);
 }
 
+
+void
+gth_file_source_remove (GthFileSource *file_source,
+		        GList         *file_list /* GFile list */)
+{
+	if (gth_file_source_is_active (file_source)) {
+		gth_file_source_queue_remove (file_source, file_list);
+		return;
+	}
+	g_cancellable_reset (file_source->priv->cancellable);
+	GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->remove (file_source, file_list);
+}
diff --git a/gthumb/gth-file-source.h b/gthumb/gth-file-source.h
index 57ce3dd..95f81ad 100644
--- a/gthumb/gth-file-source.h
+++ b/gthumb/gth-file-source.h
@@ -55,8 +55,8 @@ struct _GthFileSource
 
 	/*< protected >*/
 
-	GList        *folders; /* list of GthFileData */
-	GList        *files;   /* list of GthFileData */
+	GList *folders; /* list of GthFileData */
+	GList *files;   /* list of GthFileData */
 };
 
 struct _GthFileSourceClass
@@ -65,27 +65,27 @@ struct _GthFileSourceClass
 
 	/*< virtual functions >*/
 
-	GList *      (*get_entry_points)      (GthFileSource    *file_source);
-	GList *      (*get_current_list)      (GthFileSource    *file_source,
-					       GFile            *file);
-	GFile *      (*to_gio_file)           (GthFileSource    *file_source,
-					       GFile            *file);
-	GFileInfo *  (*get_file_info)         (GthFileSource    *file_source,
-					       GFile            *file,
-					       const char       *attributes);
-	GthFileData *(*get_file_data)         (GthFileSource    *file_source,
-					       GFile            *file,
-					       GFileInfo        *info);
-	void         (*write_metadata)        (GthFileSource    *file_source,
-					       GthFileData      *file_data,
-					       const char       *attributes,
-					       ReadyCallback     callback,
-       					       gpointer          data);
-	void         (*read_metadata)         (GthFileSource    *file_source,
-					       GthFileData      *file_data,
-					       const char       *attributes,
-					       ReadyCallback     callback,
-					       gpointer          data);
+	GList *      (*get_entry_points)      (GthFileSource        *file_source);
+	GList *      (*get_current_list)      (GthFileSource        *file_source,
+					       GFile                *file);
+	GFile *      (*to_gio_file)           (GthFileSource        *file_source,
+					       GFile                *file);
+	GFileInfo *  (*get_file_info)         (GthFileSource        *file_source,
+					       GFile                *file,
+					       const char           *attributes);
+	GthFileData *(*get_file_data)         (GthFileSource        *file_source,
+					       GFile                *file,
+					       GFileInfo            *info);
+	void         (*write_metadata)        (GthFileSource        *file_source,
+					       GthFileData          *file_data,
+					       const char           *attributes,
+					       ReadyCallback         callback,
+       					       gpointer              data);
+	void         (*read_metadata)         (GthFileSource        *file_source,
+					       GthFileData          *file_data,
+					       const char           *attributes,
+					       ReadyCallback         callback,
+					       gpointer              data);
 	void         (*for_each_child)        (GthFileSource        *file_source,
 					       GFile                *parent,
 					       gboolean              recursive,
@@ -94,71 +94,73 @@ struct _GthFileSourceClass
 					       ForEachChildCallback  child_func,
 					       ReadyCallback         ready_func,
 					       gpointer              data);
-	void         (*rename)                (GthFileSource    *file_source,
-					       GFile            *file,
-					       GFile            *new_file,
-					       ReadyCallback     callback,
-					       gpointer          data);
-	void         (*copy)                  (GthFileSource    *file_source,
-					       GthFileData      *destination,
-					       GList            *file_list, /* GFile * list */
-					       gboolean          move,
-					       ProgressCallback  progress_callback,
-					       DialogCallback    dialog_callback,
-					       ReadyCallback     callback,
-					       gpointer          data);
-	gboolean     (*can_cut)               (GthFileSource    *file_source,
-					       GFile            *file);
-	void         (*monitor_entry_points)  (GthFileSource    *file_source);
-	void         (*monitor_directory)     (GthFileSource    *file_source,
-					       GFile            *file,
-					       gboolean          activate);
-	gboolean     (*is_reorderable)        (GthFileSource    *file_source);
-	void         (*reorder)               (GthFileSource    *file_source,
-					       GthFileData      *destination,
-					       GList            *visible_files, /* GFile list */
-					       GList            *files_to_move, /* GFile list */
-					       int               dest_pos,
-					       ReadyCallback     callback,
-					       gpointer          data);
+	void         (*rename)                (GthFileSource        *file_source,
+					       GFile                *file,
+					       GFile                *new_file,
+					       ReadyCallback         callback,
+					       gpointer              data);
+	void         (*copy)                  (GthFileSource        *file_source,
+					       GthFileData          *destination,
+					       GList                *file_list, /* GFile list */
+					       gboolean              move,
+					       ProgressCallback      progress_callback,
+					       DialogCallback        dialog_callback,
+					       ReadyCallback         callback,
+					       gpointer              data);
+	gboolean     (*can_cut)               (GthFileSource        *file_source,
+					       GFile                *file);
+	void         (*monitor_entry_points)  (GthFileSource        *file_source);
+	void         (*monitor_directory)     (GthFileSource        *file_source,
+					       GFile                *file,
+					       gboolean              activate);
+	gboolean     (*is_reorderable)        (GthFileSource        *file_source);
+	void         (*reorder)               (GthFileSource        *file_source,
+					       GthFileData          *destination,
+					       GList                *visible_files, /* GFile list */
+					       GList                *files_to_move, /* GFile list */
+					       int                   dest_pos,
+					       ReadyCallback         callback,
+					       gpointer              data);
+	void         (*remove)                (GthFileSource        *file_source,
+					       GList                *file_list /* GFile list */);
 };
 
 GType          gth_file_source_get_type              (void) G_GNUC_CONST;
 
 /*< public >*/
 
-void           gth_file_source_set_cancellable       (GthFileSource    *file_source,
-						      GCancellable     *cancellable);
-GList *        gth_file_source_get_entry_points      (GthFileSource    *file_source); /* returns GthFileData list */
-GList *        gth_file_source_get_current_list      (GthFileSource    *file_source,  /* GFile list */
-						      GFile            *file);
-GFile *        gth_file_source_to_gio_file           (GthFileSource    *file_source,
-						      GFile            *file);
-GList *        gth_file_source_to_gio_file_list      (GthFileSource    *file_source,
-						      GList            *files);
-GFileInfo *    gth_file_source_get_file_info         (GthFileSource    *file_source,
-						      GFile            *file,
-						      const char       *attributes);
-GthFileData *  gth_file_source_get_file_data         (GthFileSource    *file_source,
-					              GFile            *file,
-					              GFileInfo        *info);
-gboolean       gth_file_source_is_active             (GthFileSource    *file_source);
-void           gth_file_source_cancel                (GthFileSource    *file_source);
-void           gth_file_source_write_metadata        (GthFileSource    *file_source,
-						      GthFileData      *file_data,
-						      const char       *attributes,
-						      ReadyCallback     callback,
-						      gpointer          data);
-void           gth_file_source_read_metadata         (GthFileSource    *file_source,
-						      GthFileData      *file_data,
-						      const char       *attributes,
-						      ReadyCallback     callback,
-						      gpointer          data);
-void           gth_file_source_list                  (GthFileSource    *file_source,
-						      GFile            *folder,
-						      const char       *attributes,
-						      ListReady         func,
-						      gpointer          data);
+void           gth_file_source_set_cancellable       (GthFileSource        *file_source,
+						      GCancellable         *cancellable);
+GList *        gth_file_source_get_entry_points      (GthFileSource        *file_source); /* returns GthFileData list */
+GList *        gth_file_source_get_current_list      (GthFileSource        *file_source,  /* GFile list */
+						      GFile                *file);
+GFile *        gth_file_source_to_gio_file           (GthFileSource        *file_source,
+						      GFile                *file);
+GList *        gth_file_source_to_gio_file_list      (GthFileSource        *file_source,
+						      GList                *files);
+GFileInfo *    gth_file_source_get_file_info         (GthFileSource        *file_source,
+						      GFile                *file,
+						      const char           *attributes);
+GthFileData *  gth_file_source_get_file_data         (GthFileSource        *file_source,
+					              GFile                *file,
+					              GFileInfo            *info);
+gboolean       gth_file_source_is_active             (GthFileSource        *file_source);
+void           gth_file_source_cancel                (GthFileSource        *file_source);
+void           gth_file_source_write_metadata        (GthFileSource        *file_source,
+						      GthFileData          *file_data,
+						      const char           *attributes,
+						      ReadyCallback         callback,
+						      gpointer              data);
+void           gth_file_source_read_metadata         (GthFileSource        *file_source,
+						      GthFileData          *file_data,
+						      const char           *attributes,
+						      ReadyCallback         callback,
+						      gpointer              data);
+void           gth_file_source_list                  (GthFileSource        *file_source,
+						      GFile                *folder,
+						      const char           *attributes,
+						      ListReady             func,
+						      gpointer              data);
 void           gth_file_source_for_each_child        (GthFileSource        *file_source,
 						      GFile                *parent,
 						      gboolean              recursive,
@@ -167,48 +169,50 @@ void           gth_file_source_for_each_child        (GthFileSource        *file
 						      ForEachChildCallback  child_func,
 						      ReadyCallback         ready_func,
 						      gpointer              data);
-void           gth_file_source_read_attributes       (GthFileSource    *file_source,
-						      GList            *files,
-						      const char       *attributes,
-						      ListReady         func,
-						      gpointer          data);
-void           gth_file_source_rename                (GthFileSource    *file_source,
-						      GFile            *file,
-						      GFile            *new_file,
-						      ReadyCallback     ready_callback,
-						      gpointer          data);
-void           gth_file_source_copy                  (GthFileSource    *file_source,
-						      GthFileData      *destination,
-						      GList            *file_list, /* GFile list */
-						      gboolean          move,
-						      ProgressCallback  progress_callback,
-						      DialogCallback    dialog_callback,
-						      ReadyCallback     ready_callback,
-						      gpointer          data);
-gboolean       gth_file_source_can_cut               (GthFileSource    *file_source,
-						      GFile            *file);
-void           gth_file_source_monitor_entry_points  (GthFileSource    *file_source);
-void           gth_file_source_monitor_directory     (GthFileSource    *file_source,
-						      GFile            *file,
-						      gboolean          activate);
-gboolean       gth_file_source_is_reorderable        (GthFileSource    *file_source);
-void           gth_file_source_reorder               (GthFileSource    *file_source,
-						      GthFileData      *destination,
-						      GList            *visible_files, /* GFile list */
-						      GList            *files_to_move, /* GFile list */
-						      int               dest_pos,
-						      ReadyCallback     callback,
-						      gpointer          data);
+void           gth_file_source_read_attributes       (GthFileSource        *file_source,
+						      GList                *files,
+						      const char           *attributes,
+						      ListReady             func,
+						      gpointer              data);
+void           gth_file_source_rename                (GthFileSource        *file_source,
+						      GFile                *file,
+						      GFile                *new_file,
+						      ReadyCallback         ready_callback,
+						      gpointer              data);
+void           gth_file_source_copy                  (GthFileSource        *file_source,
+						      GthFileData          *destination,
+						      GList                *file_list, /* GFile list */
+						      gboolean              move,
+						      ProgressCallback      progress_callback,
+						      DialogCallback        dialog_callback,
+						      ReadyCallback         ready_callback,
+						      gpointer              data);
+gboolean       gth_file_source_can_cut               (GthFileSource        *file_source,
+						      GFile                *file);
+void           gth_file_source_monitor_entry_points  (GthFileSource        *file_source);
+void           gth_file_source_monitor_directory     (GthFileSource        *file_source,
+						      GFile                *file,
+						      gboolean              activate);
+gboolean       gth_file_source_is_reorderable        (GthFileSource        *file_source);
+void           gth_file_source_reorder               (GthFileSource        *file_source,
+						      GthFileData          *destination,
+						      GList                *visible_files, /* GFile list */
+						      GList                *files_to_move, /* GFile list */
+						      int                   dest_pos,
+						      ReadyCallback         callback,
+						      gpointer              data);
+void           gth_file_source_remove                (GthFileSource        *file_source,
+		       	       	       	       	      GList                *file_list /* GFile list */);
 
 /*< protected >*/
 
-void           gth_file_source_add_scheme            (GthFileSource  *file_source,
-						      const char     *scheme);
-gboolean       gth_file_source_supports_scheme       (GthFileSource  *file_source,
-						      const char     *uri);
-void           gth_file_source_set_active            (GthFileSource  *file_source,
-						      gboolean        pending);
-GCancellable * gth_file_source_get_cancellable       (GthFileSource  *file_source);
+void           gth_file_source_add_scheme            (GthFileSource        *file_source,
+						      const char           *scheme);
+gboolean       gth_file_source_supports_scheme       (GthFileSource        *file_source,
+						      const char           *uri);
+void           gth_file_source_set_active            (GthFileSource        *file_source,
+						      gboolean              pending);
+GCancellable * gth_file_source_get_cancellable       (GthFileSource        *file_source);
 
 G_END_DECLS
 



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