[gthumb] fixed saving of Xmp and Iptc description and title fields



commit 08fcb249ec7e6f2daaf99f50ece6612cfa5a272c
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Aug 13 12:49:19 2010 +0200

    fixed saving of Xmp and Iptc description and title fields
    
    [bug #626284]

 extensions/exiv2_tools/exiv2-utils.cpp             |   68 ++++++++++++++-----
 .../exiv2_tools/gth-metadata-provider-exiv2.c      |   17 +++++
 extensions/exiv2_tools/main.c                      |   14 ++++
 3 files changed, 81 insertions(+), 18 deletions(-)
---
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index 7da3ce7..ad19347 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -144,8 +144,8 @@ const char *_DESCRIPTION_TAG_NAMES[] = {
 	"Exif::Image::ImageDescription",
 	"Xmp::dc::description",
 	"Xmp::tiff::ImageDescription",
-	"Iptc::Application2::Caption",
 	"Iptc::Application2::Headline",
+	"Iptc::Application2::Caption",
 	NULL
 };
 
@@ -271,24 +271,15 @@ set_file_info (GFileInfo  *info,
 
 
 static void
-set_attribute_from_tagset (GFileInfo  *info,
-			   const char *attribute,
-			   const char *tagset[])
+set_attribute_from_metadata (GFileInfo  *info,
+			     const char *attribute,
+			     GObject    *metadata)
 {
-	GObject *metadata;
-	int      i;
-	char    *key;
-	char    *description;
-	char    *formatted_value;
-	char    *raw_value;
-	char    *type_name;
-
-	metadata = NULL;
-	for (i = 0; tagset[i] != NULL; i++) {
-		metadata = g_file_info_get_attribute_object (info, tagset[i]);
-		if (metadata != NULL)
-			break;
-	}
+	char *key;
+	char *description;
+	char *formatted_value;
+	char *raw_value;
+	char *type_name;
 
 	if (metadata == NULL)
 		return;
@@ -300,6 +291,7 @@ set_attribute_from_tagset (GFileInfo  *info,
 		      "raw", &raw_value,
 		      "value-type", &type_name,
 		      NULL);
+
 	set_file_info (info,
 		       attribute,
 		       description,
@@ -311,6 +303,26 @@ set_attribute_from_tagset (GFileInfo  *info,
 
 
 static void
+set_attribute_from_tagset (GFileInfo  *info,
+			   const char *attribute,
+			   const char *tagset[])
+{
+	GObject *metadata;
+	int      i;
+
+	metadata = NULL;
+	for (i = 0; tagset[i] != NULL; i++) {
+		metadata = g_file_info_get_attribute_object (info, tagset[i]);
+		if (metadata != NULL)
+			break;
+	}
+
+	if (metadata != NULL)
+		set_attribute_from_metadata (info, attribute, metadata);
+}
+
+
+static void
 set_string_list_attribute_from_tagset (GFileInfo  *info,
 				       const char *attribute,
 				       const char *tagset[])
@@ -350,6 +362,26 @@ set_attributes_from_tagsets (GFileInfo *info)
 
 	set_attribute_from_tagset (info, "general::description", _DESCRIPTION_TAG_NAMES);
 	set_attribute_from_tagset (info, "general::title", _TITLE_TAG_NAMES);
+
+	/* if iptc::caption and iptc::headline are different use iptc::caption
+	 * to set general::title, if not alreay set. */
+
+	if (g_file_info_get_attribute_object (info, "general::title") == NULL) {
+		GObject *iptc_caption;
+		GObject *iptc_headline;
+
+		iptc_caption = g_file_info_get_attribute_object (info, "Iptc::Application2::Caption");
+		iptc_headline = g_file_info_get_attribute_object (info, "Iptc::Application2::Headline");
+
+		if ((iptc_caption != NULL)
+		    && (iptc_headline != NULL)
+		    && (g_strcmp0 (gth_metadata_get_raw (GTH_METADATA (iptc_caption)),
+				   gth_metadata_get_raw (GTH_METADATA (iptc_headline))) != 0))
+		{
+			set_attribute_from_metadata (info, "general::title", iptc_caption);
+		}
+	}
+
 	set_attribute_from_tagset (info, "general::location", _LOCATION_TAG_NAMES);
 	set_string_list_attribute_from_tagset (info, "general::tags", _KEYWORDS_TAG_NAMES);
 	set_attribute_from_tagset (info, "Embedded::Photo::DateTimeOriginal", _ORIGINAL_DATE_TAG_NAMES);
diff --git a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
index 64b8451..62966cf 100644
--- a/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
+++ b/extensions/exiv2_tools/gth-metadata-provider-exiv2.c
@@ -134,11 +134,28 @@ gth_metadata_provider_exiv2_write (GthMetadataProvider   *self,
 
 	metadata = g_file_info_get_attribute_object (file_data->info, "general::description");
 	if (metadata != NULL) {
+		const char *tags_to_remove[] = {
+			"Exif::Image::ImageDescription",
+			"Xmp::tiff::ImageDescription",
+			"Iptc::Application2::Caption",
+			NULL
+		};
+		int i;
+
+		for (i = 0; tags_to_remove[i] != NULL; i++)
+			g_file_info_remove_attribute (file_data->info, tags_to_remove[i]);
+
 		g_file_info_set_attribute_object (file_data->info, "Exif::Photo::UserComment", metadata);
 		g_file_info_set_attribute_object (file_data->info, "Xmp::dc::description", metadata);
 		g_file_info_set_attribute_object (file_data->info, "Iptc::Application2::Headline", metadata);
 	}
 
+	metadata = g_file_info_get_attribute_object (file_data->info, "general::title");
+	if (metadata != NULL) {
+		g_file_info_set_attribute_object (file_data->info, "Xmp::dc::title", metadata);
+		g_file_info_set_attribute_object (file_data->info, "Iptc::Application2::Caption", metadata);
+	}
+
 	metadata = g_file_info_get_attribute_object (file_data->info, "general::location");
 	if (metadata != NULL) {
 		g_file_info_set_attribute_object (file_data->info, "Xmp::iptc::Location", metadata);
diff --git a/extensions/exiv2_tools/main.c b/extensions/exiv2_tools/main.c
index 4ebc1e9..8c3b3e9 100644
--- a/extensions/exiv2_tools/main.c
+++ b/extensions/exiv2_tools/main.c
@@ -46,6 +46,10 @@ GthMetadataCategory exiv2_metadata_category[] = {
 
 
 GthMetadataInfo exiv2_metadata_info[] = {
+
+	/* Specify the type of a field to allow to create it if it's not
+	 * already present in the image. */
+
 	{ "Exif::Image::Make", NULL, "Exif::General", 1, NULL, GTH_METADATA_ALLOW_EVERYWHERE },
 	{ "Exif::Image::Model", NULL, "Exif::General", 2, NULL, GTH_METADATA_ALLOW_EVERYWHERE },
 	{ "Exif::Image::Software", NULL, "Exif::General", 3, NULL, GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
@@ -142,6 +146,16 @@ GthMetadataInfo exiv2_metadata_info[] = {
 
 	{ "Exif::Photo::MakerNote", NULL, "Exif::Other", 0, NULL, GTH_METADATA_ALLOW_NOWHERE },
 
+	{ "Xmp::dc::description", NULL, "Xmp::Embedded", 0, "XmpText", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Xmp::dc::title", NULL, "Xmp::Embedded", 0, "XmpText", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Xmp::iptc::Location", NULL, "Xmp::Embedded", 0, "XmpText", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Xmp::iptc::Keywords", NULL, "Xmp::Embedded", 0, "XmpBag", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+
+	{ "Iptc::Application2::Headline", NULL, "Iptc", 0, "String", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Iptc::Application2::Caption", NULL, "Iptc", 0, "String", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Iptc::Application2::LocationName", NULL, "Iptc", 0, "String", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+	{ "Iptc::Application2::Keywords", NULL, "Iptc", 0, "String", GTH_METADATA_ALLOW_IN_PROPERTIES_VIEW },
+
 	{ NULL, NULL, NULL, 0, NULL, 0 }
 };
 



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