[gthumb] implemeted the "delete-metadata" function for embedded metadata and comments



commit f581c7fe23124646181009ebd912d9995bbb6121
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 29 16:51:57 2011 +0200

    implemeted the "delete-metadata" function for embedded metadata and comments

 extensions/comments/main.c             |   21 +++++++++++++++++++--
 extensions/exiv2_tools/exiv2-utils.cpp |    7 ++++++-
 extensions/exiv2_tools/main.c          |   13 ++++++++++++-
 3 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/extensions/comments/main.c b/extensions/comments/main.c
index b983c9e..7a7fb83 100644
--- a/extensions/comments/main.c
+++ b/extensions/comments/main.c
@@ -68,7 +68,7 @@ get_place_for_test (GthTest        *test,
 }
 
 
-void
+static void
 comments__add_sidecars_cb (GFile  *file,
 			   GList **sidecars)
 {
@@ -76,7 +76,7 @@ comments__add_sidecars_cb (GFile  *file,
 }
 
 
-void
+static void
 comments__read_metadata_ready_cb (GthFileData *file_data,
 				  const char  *attributes)
 {
@@ -217,6 +217,21 @@ comments__read_metadata_ready_cb (GthFileData *file_data,
 }
 
 
+static void
+comments__delete_metadata_cb (GFile  *file,
+			      void  **buffer,
+			      gsize  *size)
+{
+	GFile *comment_file;
+
+	comment_file = gth_comment_get_comment_file (file);
+	if (comment_file != NULL) {
+		g_file_delete (comment_file, NULL, NULL);
+		g_object_unref (comment_file);
+	}
+}
+
+
 G_MODULE_EXPORT void
 gthumb_extension_activate (void)
 {
@@ -248,6 +263,8 @@ gthumb_extension_activate (void)
 
 	gth_hook_add_callback ("add-sidecars", 10, G_CALLBACK (comments__add_sidecars_cb), NULL);
 	gth_hook_add_callback ("read-metadata-ready", 10, G_CALLBACK (comments__read_metadata_ready_cb), NULL);
+	if (gth_main_extension_is_active ("edit_metadata"))
+		gth_hook_add_callback ("delete-metadata", 10, G_CALLBACK (comments__delete_metadata_cb), NULL);
 }
 
 
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index 34c7b41..7506236 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -1151,7 +1151,12 @@ exiv2_clear_metadata (void   **buffer,
 {
 	try {
 		Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) *buffer, *buffer_size);
-		g_assert (image.get() != 0);
+
+		if (image.get() == 0) {
+			if (error != NULL)
+				*error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED, _("Invalid file format"));
+			return FALSE;
+		}
 
 		try {
 			image->clearMetadata();
diff --git a/extensions/exiv2_tools/main.c b/extensions/exiv2_tools/main.c
index 24f114e..d41b7a8 100644
--- a/extensions/exiv2_tools/main.c
+++ b/extensions/exiv2_tools/main.c
@@ -218,6 +218,15 @@ exiv2_jpeg_tran_cb (JpegTranInfo *tran_info)
 }
 
 
+static void
+exiv2_delete_metadata_cb (GFile  *file,
+			  void  **buffer,
+			  gsize  *size)
+{
+	exiv2_clear_metadata (buffer, size, NULL);
+}
+
+
 static int
 gth_file_data_cmp_date_time_original (GthFileData *a,
 				      GthFileData *b)
@@ -256,8 +265,10 @@ gthumb_extension_activate (void)
 	gth_main_register_metadata_category (exiv2_metadata_category);
 	gth_main_register_metadata_info_v (exiv2_metadata_info);
 	gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_EXIV2);
-	if (gth_main_extension_is_active ("edit_metadata"))
+	if (gth_main_extension_is_active ("edit_metadata")) {
 		gth_main_register_type ("edit-metadata-dialog-page", GTH_TYPE_EDIT_EXIV2_PAGE);
+		gth_hook_add_callback ("delete-metadata", 10, G_CALLBACK (exiv2_delete_metadata_cb), NULL);
+	}
 	gth_hook_add_callback ("save-pixbuf", 10, G_CALLBACK (exiv2_write_metadata), NULL);
 	if (gth_hook_present ("jpegtran-after"))
 		gth_hook_add_callback ("jpegtran-after", 10, G_CALLBACK (exiv2_jpeg_tran_cb), NULL);



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