From 69282a3890ec9264e5471249ad51c8fdb0ed7418 Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Sat, 4 Oct 2008 20:28:31 +0000 Subject: [PATCH] fixed charset of exiv2 strings in non-utf8 locales --- src/bar_exif.c | 3 ++- src/exif-common.c | 4 ++-- src/exif.c | 4 ++-- src/exif.h | 4 ++-- src/exiv2.cc | 11 ++++++----- src/pan-view.c | 5 ++++- src/preferences.c | 3 ++- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/bar_exif.c b/src/bar_exif.c index accba869..a6e3dfa7 100644 --- a/src/bar_exif.c +++ b/src/bar_exif.c @@ -625,11 +625,12 @@ GtkWidget *bar_exif_new(gint show_title, FileData *fd, gint advanced, GtkWidget 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(); diff --git a/src/exif-common.c b/src/exif-common.c index 9660e53d..77becdd6 100644 --- a/src/exif-common.c +++ b/src/exif-common.c @@ -541,7 +541,7 @@ gchar *exif_get_formatted_by_key(ExifData *exif, const gchar *key, gint *key_val 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 @@ const gchar *exif_get_description_by_key(const gchar *key) 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); diff --git a/src/exif.c b/src/exif.c index 58f06b34..ce20cb6b 100644 --- a/src/exif.c +++ b/src/exif.c @@ -1493,7 +1493,7 @@ ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, gint n) 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 @@ const gchar *exif_get_tag_description_by_key(const gchar *key) 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++; } diff --git a/src/exif.h b/src/exif.h index cd0afeb7..db7e7e02 100644 --- a/src/exif.h +++ b/src/exif.h @@ -137,8 +137,8 @@ ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, gint n); 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); diff --git a/src/exiv2.cc b/src/exiv2.cc index 9c5d9e70..6382294a 100644 --- a/src/exiv2.cc +++ b/src/exiv2.cc @@ -375,7 +375,7 @@ char *exif_item_get_description(ExifItem *item) { 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 @@ gchar *exif_item_get_data_as_text(ExifItem *item) 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 @@ gchar *exif_item_get_data_as_text(ExifItem *item) 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 @@ gchar *exif_item_get_string(ExifItem *item, int idx) 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 @@ ExifRational *exif_item_get_rational(ExifItem *item, gint *sign, gint n) } } -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"; diff --git a/src/pan-view.c b/src/pan-view.c index f055e555..f141d207 100644 --- a/src/pan-view.c +++ b/src/pan-view.c @@ -1446,6 +1446,7 @@ static void pan_info_add_exif(PanTextAlignment *ta, FileData *fd) for (i = 0; ExifUIList[i].key; i++) { gchar *label; + gchar *desc; gchar *text; gchar *utf8_text; @@ -1458,7 +1459,9 @@ static void pan_info_add_exif(PanTextAlignment *ta, FileData *fd) 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); diff --git a/src/preferences.c b/src/preferences.c index dcaa97c6..48c8ddc6 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -1328,11 +1328,12 @@ static void config_tab_properties(GtkWidget *notebook) 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); } } -- 2.20.1