# HG changeset patch # User zas_ # Date 1210634495 0 # Node ID b50deb0f9968528119f5858fabe19312dc4c720a # Parent d062f6b5711a8a5c55813347ca8068209c0059ef Rename bar_exif_validate_text() to utf8_validate_or_convert() and move it to main.[ch]. diff -r d062f6b5711a -r b50deb0f9968 src/bar_exif.c --- a/src/bar_exif.c Mon May 12 23:00:04 2008 +0000 +++ b/src/bar_exif.c Mon May 12 23:21:35 2008 +0000 @@ -141,25 +141,6 @@ EXIF_ADVCOL_COUNT }; -gchar *bar_exif_validate_text(gchar *text) -{ - gint len; - - if (!text) return NULL; - - len = strlen(text); - if (!g_utf8_validate(text, len, NULL)) - { - gchar *conv_text; - - conv_text = g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); - g_free(text); - text = conv_text; - } - - return text; -} - static void bar_exif_sensitive(ExifBar *eb, gint enable) { gtk_widget_set_sensitive(eb->table, enable); @@ -209,7 +190,7 @@ continue; } text = exif_get_data_as_text(exif, ExifUIList[i].key); - text = bar_exif_validate_text(text); + text = utf8_validate_or_convert(text); if (ExifUIList[i].current == EXIF_UI_IFSET && (!text || !*text)) { @@ -243,7 +224,7 @@ list = list->prev; text = exif_get_data_as_text(exif, name); - text = bar_exif_validate_text(text); + text = utf8_validate_or_convert(text); buf = g_strconcat(name, ":", NULL); gtk_label_set_text(GTK_LABEL(eb->custom_name[i]), buf); @@ -287,11 +268,11 @@ tag_name = exif_item_get_tag_name(item); format = exif_item_get_format_name(item, TRUE); text = exif_item_get_data_as_text(item); - text = bar_exif_validate_text(text); + text = utf8_validate_or_convert(text); elements = g_strdup_printf("%d", exif_item_get_elements(item)); description = exif_item_get_description(item); if (!description) description = g_strdup(""); - description = bar_exif_validate_text(description); + description = utf8_validate_or_convert(description); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, EXIF_ADVCOL_ENABLED, bar_exif_row_enabled(tag_name), diff -r d062f6b5711a -r b50deb0f9968 src/bar_exif.h --- a/src/bar_exif.h Mon May 12 23:00:04 2008 +0000 +++ b/src/bar_exif.h Mon May 12 23:21:35 2008 +0000 @@ -41,7 +41,5 @@ const gchar **bar_exif_key_list; const gint bar_exif_key_count; -gchar *bar_exif_validate_text(gchar *text); - #endif diff -r d062f6b5711a -r b50deb0f9968 src/main.c --- a/src/main.c Mon May 12 23:00:04 2008 +0000 +++ b/src/main.c Mon May 12 23:21:35 2008 +0000 @@ -120,6 +120,25 @@ return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0); } +gchar *utf8_validate_or_convert(gchar *text) +{ + gint len; + + if (!text) return NULL; + + len = strlen(text); + if (!g_utf8_validate(text, len, NULL)) + { + gchar *conv_text; + + conv_text = g_convert(text, len, "UTF-8", "ISO-8859-1", NULL, NULL, NULL); + g_free(text); + text = conv_text; + } + + return text; +} + /* *----------------------------------------------------------------------------- diff -r d062f6b5711a -r b50deb0f9968 src/main.h --- a/src/main.h Mon May 12 23:00:04 2008 +0000 +++ b/src/main.h Mon May 12 23:21:35 2008 +0000 @@ -130,6 +130,7 @@ gint window_maximized(GtkWidget *window); gdouble get_zoom_increment(void); +gchar *utf8_validate_or_convert(gchar *text); void help_window_show(const gchar *key); diff -r d062f6b5711a -r b50deb0f9968 src/pan-view.c --- a/src/pan-view.c Mon May 12 23:00:04 2008 +0000 +++ b/src/pan-view.c Mon May 12 23:21:35 2008 +0000 @@ -1448,7 +1448,7 @@ if (ExifUIList[i].current == EXIF_UI_OFF) continue; text = exif_get_data_as_text(exif, ExifUIList[i].key); - text = bar_exif_validate_text(text); + text = utf8_validate_or_convert(text); if (ExifUIList[i].current == EXIF_UI_IFSET && (!text || !*text)) { if (text) g_free(text); @@ -1474,7 +1474,7 @@ label = g_strdup_printf("%s:", name); text = exif_get_data_as_text(exif, name); - text = bar_exif_validate_text(text); + text = utf8_validate_or_convert(text); pan_text_alignment_add(ta, label, text); g_free(label); g_free(text);