[gthumb] added the delete metadata task



commit bbcb40a78e9a4ce470f0cf4e49b35223a0f64cf3
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 29 15:14:48 2011 +0200

    added the delete metadata task

 extensions/edit_metadata/Makefile.am               |    2 +
 extensions/edit_metadata/actions.c                 |   16 ++
 .../edit_metadata/gth-delete-metadata-task.c       |  209 ++++++++++++++++++++
 .../edit_metadata/gth-delete-metadata-task.h       |   56 ++++++
 extensions/edit_metadata/main.c                    |    9 +
 5 files changed, 292 insertions(+), 0 deletions(-)
---
diff --git a/extensions/edit_metadata/Makefile.am b/extensions/edit_metadata/Makefile.am
index 3e41b4c..77d3a9f 100644
--- a/extensions/edit_metadata/Makefile.am
+++ b/extensions/edit_metadata/Makefile.am
@@ -10,6 +10,8 @@ libedit_metadata_la_SOURCES = 		\
 	callbacks.h			\
 	dlg-edit-metadata.c		\
 	dlg-edit-metadata.h		\
+	gth-delete-metadata-task.c	\
+	gth-delete-metadata-task.h	\
 	gth-edit-comment-page.c		\
 	gth-edit-comment-page.h		\
 	gth-edit-metadata-dialog.c	\
diff --git a/extensions/edit_metadata/actions.c b/extensions/edit_metadata/actions.c
index c1ac26e..b086579 100644
--- a/extensions/edit_metadata/actions.c
+++ b/extensions/edit_metadata/actions.c
@@ -23,6 +23,7 @@
 #include <config.h>
 #include <gthumb.h>
 #include "dlg-edit-metadata.h"
+#include "gth-delete-metadata-task.h"
 #include "gth-tag-chooser-dialog.h"
 #include "gth-tag-task.h"
 
@@ -114,4 +115,19 @@ void
 gth_browser_activate_action_tool_delete_metadata (GtkAction  *action,
 						  GthBrowser *browser)
 {
+	GList   *items;
+	GList   *file_data_list;
+	GList   *file_list;
+	GthTask *task;
+
+	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);
+	file_list = gth_file_data_list_to_file_list (file_data_list);
+	task = gth_delete_metadata_task_new (browser, file_list);
+	gth_browser_exec_task (browser, task, FALSE);
+
+	g_object_unref (task);
+	_g_object_list_unref (file_list);
+	_g_object_list_unref (file_data_list);
+	_gtk_tree_path_list_free (items);
 }
diff --git a/extensions/edit_metadata/gth-delete-metadata-task.c b/extensions/edit_metadata/gth-delete-metadata-task.c
new file mode 100644
index 0000000..74e5536
--- /dev/null
+++ b/extensions/edit_metadata/gth-delete-metadata-task.c
@@ -0,0 +1,209 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include "gth-delete-metadata-task.h"
+
+
+struct _GthDeleteMetadataTaskPrivate {
+	GthBrowser    *browser;
+	GList         *file_list;
+	GList         *current;
+	GthFileData   *file_data;
+};
+
+
+static gpointer parent_class = NULL;
+
+
+static void
+gth_delete_metadata_task_finalize (GObject *object)
+{
+	GthDeleteMetadataTask *self;
+
+	self = GTH_DELETE_METADATA_TASK (object);
+
+	_g_object_unref (self->priv->file_data);
+	_g_object_list_unref (self->priv->file_list);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+static void transform_current_file (GthDeleteMetadataTask *self);
+
+
+static void
+transform_next_file (GthDeleteMetadataTask *self)
+{
+	self->priv->current = self->priv->current->next;
+	transform_current_file (self);
+}
+
+
+static void
+write_file_ready_cb (void     **buffer,
+		     gsize      count,
+		     GError    *error,
+		     gpointer   user_data)
+{
+	GthDeleteMetadataTask *self = user_data;
+
+	if (error != NULL) {
+		gth_task_completed (GTH_TASK (self), error);
+		return;
+	}
+
+	transform_next_file (self);
+}
+
+
+static void
+load_file_ready_cb (void     **buffer,
+		    gsize      count,
+		    GError    *error,
+		    gpointer   user_data)
+{
+	GthDeleteMetadataTask *self = user_data;
+	GFile                 *file;
+	void                  *tmp_buffer;
+
+	if (error != NULL) {
+		gth_task_completed (GTH_TASK (self), error);
+		return;
+	}
+
+	file = self->priv->current->data;
+
+	tmp_buffer = *buffer;
+	*buffer = NULL;
+
+	gth_hook_invoke ("delete-metadata", file, &tmp_buffer, &count);
+
+	g_write_file_async (file,
+			    tmp_buffer,
+	    		    count,
+	    		    TRUE,
+	    		    G_PRIORITY_DEFAULT,
+	    		    gth_task_get_cancellable (GTH_TASK (self)),
+			    write_file_ready_cb,
+			    self);
+}
+
+
+static void
+transform_current_file (GthDeleteMetadataTask *self)
+{
+	GFile *file;
+
+	if (self->priv->current == NULL) {
+		gth_task_completed (GTH_TASK (self), NULL);
+		return;
+	}
+
+	file = self->priv->current->data;
+	g_load_file_async (file,
+			   G_PRIORITY_DEFAULT,
+			   gth_task_get_cancellable (GTH_TASK (self)),
+			   load_file_ready_cb,
+			   self);
+}
+
+
+static void
+gth_delete_metadata_task_exec (GthTask *task)
+{
+	GthDeleteMetadataTask *self;
+
+	g_return_if_fail (GTH_IS_DELETE_METADATA_TASK (task));
+
+	self = GTH_DELETE_METADATA_TASK (task);
+
+	self->priv->current = self->priv->file_list;
+	transform_current_file (self);
+}
+
+
+static void
+gth_delete_metadata_task_class_init (GthDeleteMetadataTaskClass *klass)
+{
+	GObjectClass *object_class;
+	GthTaskClass *task_class;
+
+	parent_class = g_type_class_peek_parent (klass);
+	g_type_class_add_private (klass, sizeof (GthDeleteMetadataTaskPrivate));
+
+	object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gth_delete_metadata_task_finalize;
+
+	task_class = GTH_TASK_CLASS (klass);
+	task_class->exec = gth_delete_metadata_task_exec;
+}
+
+
+static void
+gth_delete_metadata_task_init (GthDeleteMetadataTask *self)
+{
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_DELETE_METADATA_TASK, GthDeleteMetadataTaskPrivate);
+	self->priv->file_data = NULL;
+}
+
+
+GType
+gth_delete_metadata_task_get_type (void)
+{
+	static GType type = 0;
+
+	if (! type) {
+		GTypeInfo type_info = {
+			sizeof (GthDeleteMetadataTaskClass),
+			NULL,
+			NULL,
+			(GClassInitFunc) gth_delete_metadata_task_class_init,
+			NULL,
+			NULL,
+			sizeof (GthDeleteMetadataTask),
+			0,
+			(GInstanceInitFunc) gth_delete_metadata_task_init
+		};
+
+		type = g_type_register_static (GTH_TYPE_TASK,
+					       "GthDeleteMetadataTask",
+					       &type_info,
+					       0);
+	}
+
+	return type;
+}
+
+
+GthTask *
+gth_delete_metadata_task_new (GthBrowser *browser,
+			      GList      *file_list)
+{
+	GthDeleteMetadataTask *self;
+
+	self = GTH_DELETE_METADATA_TASK (g_object_new (GTH_TYPE_DELETE_METADATA_TASK, NULL));
+	self->priv->browser = browser;
+	self->priv->file_list = _g_object_list_ref (file_list);
+
+	return (GthTask *) self;
+}
diff --git a/extensions/edit_metadata/gth-delete-metadata-task.h b/extensions/edit_metadata/gth-delete-metadata-task.h
new file mode 100644
index 0000000..3e5ec06
--- /dev/null
+++ b/extensions/edit_metadata/gth-delete-metadata-task.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2011 The Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_DELETE_METADATA_TASK_H
+#define GTH_DELETE_METADATA_TASK_H
+
+#include <glib.h>
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_DELETE_METADATA_TASK            (gth_delete_metadata_task_get_type ())
+#define GTH_DELETE_METADATA_TASK(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_DELETE_METADATA_TASK, GthDeleteMetadataTask))
+#define GTH_DELETE_METADATA_TASK_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_DELETE_METADATA_TASK, GthDeleteMetadataTaskClass))
+#define GTH_IS_DELETE_METADATA_TASK(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_DELETE_METADATA_TASK))
+#define GTH_IS_DELETE_METADATA_TASK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_DELETE_METADATA_TASK))
+#define GTH_DELETE_METADATA_TASK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTH_TYPE_DELETE_METADATA_TASK, GthDeleteMetadataTaskClass))
+
+typedef struct _GthDeleteMetadataTask        GthDeleteMetadataTask;
+typedef struct _GthDeleteMetadataTaskClass   GthDeleteMetadataTaskClass;
+typedef struct _GthDeleteMetadataTaskPrivate GthDeleteMetadataTaskPrivate;
+
+struct _GthDeleteMetadataTask {
+	GthTask __parent;
+	GthDeleteMetadataTaskPrivate *priv;
+};
+
+struct _GthDeleteMetadataTaskClass {
+	GthTaskClass __parent;
+};
+
+GType         gth_delete_metadata_task_get_type  (void);
+GthTask *     gth_delete_metadata_task_new       (GthBrowser   *browser,
+						  GList        *file_list /* GFile list */);
+
+G_END_DECLS
+
+#endif /* GTH_DELETE_METADATA_TASK_H */
diff --git a/extensions/edit_metadata/main.c b/extensions/edit_metadata/main.c
index 286c30e..7d91719 100644
--- a/extensions/edit_metadata/main.c
+++ b/extensions/edit_metadata/main.c
@@ -30,6 +30,15 @@
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
+	/**
+	 * Called to delete a file metadata
+	 *
+	 * @file (GFile *): the file
+	 * @buffer (void **buffer): the file content
+	 * @size (gsize *): the file size
+	 **/
+	gth_hook_register ("delete-metadata", 3);
+
 	gth_main_register_type ("edit-metadata-dialog-page", GTH_TYPE_EDIT_COMMENT_PAGE);
 	gth_hook_add_callback ("gth-browser-construct", 7, G_CALLBACK (edit_metadata__gth_browser_construct_cb), NULL);
 	gth_hook_add_callback ("gth-browser-set-current-page", 5, G_CALLBACK (edit_metadata__gth_browser_set_current_page_cb), NULL);



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