Rename bar_exif_validate_text() to utf8_validate_or_convert() and move it to main...
authorLaurent Monin <geeqie@norz.org>
Mon, 12 May 2008 23:21:35 +0000 (23:21 +0000)
committerLaurent Monin <geeqie@norz.org>
Mon, 12 May 2008 23:21:35 +0000 (23:21 +0000)
src/bar_exif.c
src/bar_exif.h
src/main.c
src/main.h
src/pan-view.c

index 2367dc3..e9d5a4d 100644 (file)
@@ -141,25 +141,6 @@ enum {
        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 @@ static void bar_exif_update(ExifBar *eb)
                                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 @@ static void bar_exif_update(ExifBar *eb)
                        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 @@ static void bar_exif_update(ExifBar *eb)
                        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),
index 927b60f..de147fd 100644 (file)
@@ -41,7 +41,5 @@ gint bar_exif_is_advanced(GtkWidget *bar);
 const gchar **bar_exif_key_list;
 const gint bar_exif_key_count;
 
-gchar *bar_exif_validate_text(gchar *text);
-
 
 #endif
index 5f5cf2d..fb83e3c 100644 (file)
@@ -120,6 +120,25 @@ gdouble get_zoom_increment(void)
        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;
+}
+
 
 /*
  *-----------------------------------------------------------------------------
index fab7d76..a210236 100644 (file)
@@ -130,6 +130,7 @@ void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file);
 gint window_maximized(GtkWidget *window);
 
 gdouble get_zoom_increment(void);
+gchar *utf8_validate_or_convert(gchar *text);
 
 void help_window_show(const gchar *key);
 
index 24b96be..d28330a 100644 (file)
@@ -1448,7 +1448,7 @@ static void pan_info_add_exif(PanTextAlignment *ta, FileData *fd)
                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 @@ static void pan_info_add_exif(PanTextAlignment *ta, FileData *fd)
 
                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);