changeset 1053:77ca9a5d42be

fixed charset of exiv2 strings in non-utf8 locales
author nadvornik
date Sat, 04 Oct 2008 20:28:31 +0000
parents 338c21c87ff5
children 9157291b79a4
files src/bar_exif.c src/exif-common.c src/exif.c src/exif.h src/exiv2.cc src/pan-view.c src/preferences.c
diffstat 7 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_exif.c	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/bar_exif.c	Sat Oct 04 20:28:31 2008 +0000
@@ -625,11 +625,12 @@
 
 	for (i = 0; ExifUIList[i].key; i++)
 		{
-		const gchar *text;
+		gchar *text;
 
 		text = exif_get_description_by_key(ExifUIList[i].key);
 		eb->labels[i] = table_add_line(table, 0, i, text, NULL,
 		      &eb->keys[i]);
+		g_free(text);
 		}
 
 	eb->custom_sep = gtk_hseparator_new();
--- a/src/exif-common.c	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/exif-common.c	Sat Oct 04 20:28:31 2008 +0000
@@ -541,7 +541,7 @@
 	return NULL;
 }
 
-const gchar *exif_get_description_by_key(const gchar *key)
+gchar *exif_get_description_by_key(const gchar *key)
 {
 	if (!key) return NULL;
 
@@ -552,7 +552,7 @@
 		key += 10;
 		for (i = 0; ExifFormattedList[i].key; i++)
 			if (strcmp(key, ExifFormattedList[i].key + 10) == 0)
-				return _(ExifFormattedList[i].description);
+				return g_strdup(_(ExifFormattedList[i].description));
 		}
 
 	return exif_get_tag_description_by_key(key);
--- a/src/exif.c	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/exif.c	Sat Oct 04 20:28:31 2008 +0000
@@ -1493,7 +1493,7 @@
 	return NULL;
 }
 
-const gchar *exif_get_tag_description_by_key(const gchar *key)
+gchar *exif_get_tag_description_by_key(const gchar *key)
 {
 	gint i;
 
@@ -1502,7 +1502,7 @@
 	i = 0;
 	while (ExifKnownMarkersList[i].tag > 0)
 		{
-		if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return _(ExifKnownMarkersList[i].description);
+		if (strcmp(key, ExifKnownMarkersList[i].key) == 0) return g_strdup(_(ExifKnownMarkersList[i].description));
 		i++;
 		}
 
--- a/src/exif.h	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/exif.h	Sat Oct 04 20:28:31 2008 +0000
@@ -137,8 +137,8 @@
 
 gchar *exif_item_get_string(ExifItem *item, gint idx);
 
-const gchar *exif_get_description_by_key(const gchar *key);
-const gchar *exif_get_tag_description_by_key(const gchar *key);
+gchar *exif_get_description_by_key(const gchar *key);
+gchar *exif_get_tag_description_by_key(const gchar *key);
 
 gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_valid);
 
--- a/src/exiv2.cc	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/exiv2.cc	Sat Oct 04 20:28:31 2008 +0000
@@ -375,7 +375,7 @@
 {
 	try {
 		if (!item) return NULL;
-		return g_strdup(((Exiv2::Metadatum *)item)->tagLabel().c_str());
+		return g_locale_to_utf8(((Exiv2::Metadatum *)item)->tagLabel().c_str(), -1, NULL, NULL, NULL);
 	}
 	catch (std::exception& e) {
 //		std::cout << "Caught Exiv2 exception '" << e << "'\n";
@@ -449,7 +449,7 @@
 		if (!item) return NULL;
 		Exiv2::Metadatum *metadatum = (Exiv2::Metadatum *)item;
 #if EXIV2_TEST_VERSION(0,17,0)
-		return g_strdup(metadatum->print().c_str());
+		return g_locale_to_utf8(metadatum->print().c_str(), -1, NULL, NULL, NULL);
 #else
 		std::stringstream str;
 		Exiv2::Exifdatum *exifdatum;
@@ -466,7 +466,7 @@
 			str << *xmpdatum;
 #endif
 
-		return g_strdup(str.str().c_str());
+		return g_locale_to_utf8(str.str().c_str(), -1, NULL, NULL, NULL);
 #endif
 	}
 	catch (Exiv2::AnyError& e) {
@@ -491,6 +491,7 @@
 			if (pos != std::string::npos) str = str.substr(pos+1);
 			}
 
+//		return g_locale_to_utf8(str.c_str(), -1, NULL, NULL, NULL); // FIXME
 		return g_strdup(str.c_str());
 	}
 	catch (Exiv2::AnyError& e) {
@@ -530,11 +531,11 @@
 	}
 }
 
-const gchar *exif_get_tag_description_by_key(const gchar *key)
+gchar *exif_get_tag_description_by_key(const gchar *key)
 {
 	try {
 		Exiv2::ExifKey ekey(key);
-		return Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ());
+		return g_locale_to_utf8(Exiv2::ExifTags::tagLabel(ekey.tag(), ekey.ifdId ()), -1, NULL, NULL, NULL);
 	}
 	catch (Exiv2::AnyError& e) {
 		std::cout << "Caught Exiv2 exception '" << e << "'\n";
--- a/src/pan-view.c	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/pan-view.c	Sat Oct 04 20:28:31 2008 +0000
@@ -1446,6 +1446,7 @@
 	for (i = 0; ExifUIList[i].key; i++)
 		{
 		gchar *label;
+		gchar *desc;
 		gchar *text;
 		gchar *utf8_text;
 
@@ -1458,7 +1459,9 @@
 			continue;
 			}
 		
-		label = g_strdup_printf("%s:", exif_get_description_by_key(ExifUIList[i].key));
+		desc = exif_get_description_by_key(ExifUIList[i].key);
+		label = g_strdup_printf("%s:", desc);
+		g_free(desc);
 		utf8_text = utf8_validate_or_convert(text);
 		g_free(text);
 		pan_text_alignment_add(ta, label, utf8_text);
--- a/src/preferences.c	Wed Oct 01 20:57:56 2008 +0000
+++ b/src/preferences.c	Sat Oct 04 20:28:31 2008 +0000
@@ -1328,11 +1328,12 @@
 
 	for (i = 0; ExifUIList[i].key; i++)
 		{
-		const gchar *title;
+		gchar *title;
 
 		title = exif_get_description_by_key(ExifUIList[i].key);
 		exif_item(table, 0, i, title, ExifUIList[i].current,
 			  &ExifUIList[i].temp);
+		g_free(title);
 		}
 }