fixed charset of exiv2 strings in non-utf8 locales
authorVladimir Nadvornik <nadvornik@suse.cz>
Sat, 4 Oct 2008 20:28:31 +0000 (20:28 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Sat, 4 Oct 2008 20:28:31 +0000 (20:28 +0000)
src/bar_exif.c
src/exif-common.c
src/exif.c
src/exif.h
src/exiv2.cc
src/pan-view.c
src/preferences.c

index accba86..a6e3dfa 100644 (file)
@@ -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();
index 9660e53..77becdd 100644 (file)
@@ -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);
index 58f06b3..ce20cb6 100644 (file)
@@ -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++;
                }
 
index cd0afeb..db7e7e0 100644 (file)
@@ -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);
 
index 9c5d9e7..6382294 100644 (file)
@@ -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";
index f055e55..f141d20 100644 (file)
@@ -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);
index dcaa97c..48c8ddc 100644 (file)
@@ -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);
                }
 }