X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-properties.c;h=d7974c0f1ef5b16bb3777e73075fd9cabac85196;hb=1b553f2b8c0b409ff4a5c93d4341df6e4bfb4b61;hp=15e5ab1f250c0f7e0a92a90ffebbd56506beb8de;hpb=dbb1f2d648cdb8f6213cf42a52f466305f3964ed;p=evince.git diff --git a/shell/ev-properties.c b/shell/ev-properties.c index 15e5ab1f..d7974c0f 100644 --- a/shell/ev-properties.c +++ b/shell/ev-properties.c @@ -33,6 +33,7 @@ #include #include #include +#include enum { @@ -171,15 +172,71 @@ ev_properties_format_date (GTime utime) return g_locale_to_utf8 (s, -1, NULL, NULL, NULL); } +/* This is cut out of gconvert.c from glib (and mildly modified). Not all + backends give valid UTF-8 for properties, so we make sure that is. + */ +static gchar * +make_valid_utf8 (const gchar *name) +{ + GString *string; + const gchar *remainder, *invalid; + gint remaining_bytes, valid_bytes; + + string = NULL; + remainder = name; + remaining_bytes = strlen (name); + + while (remaining_bytes != 0) + { + if (g_utf8_validate (remainder, remaining_bytes, &invalid)) + break; + valid_bytes = invalid - remainder; + + if (string == NULL) + string = g_string_sized_new (remaining_bytes); + + g_string_append_len (string, remainder, valid_bytes); + g_string_append_c (string, '?'); + + remaining_bytes -= valid_bytes + 1; + remainder = invalid + 1; + } + + if (string == NULL) + return g_strdup (name); + + g_string_append (string, remainder); + + g_assert (g_utf8_validate (string->str, -1, NULL)); + + return g_string_free (string, FALSE); +} + static void set_property (GladeXML *xml, Property property, const char *text) { GtkWidget *widget; + char *valid_text; widget = glade_xml_get_widget (xml, properties_info[property].label_id); g_return_if_fail (GTK_IS_LABEL (widget)); - gtk_label_set_text (GTK_LABEL (widget), text ? text : ""); + if (text == NULL || text[0] == '\000') { + gchar *markup; + + markup = g_markup_printf_escaped ("%s", _("None")); + gtk_label_set_markup (GTK_LABEL (widget), markup); + g_free (markup); + + return; + } + text = text ? text : ""; + + valid_text = make_valid_utf8 (text); + + gtk_label_set_text (GTK_LABEL (widget), valid_text); + + g_free (valid_text); } static void @@ -191,8 +248,9 @@ update_progress_label (GtkWidget *label, double progress) (int) (progress * 100)); gtk_label_set_text (GTK_LABEL (label), progress_text); g_free (progress_text); + gtk_widget_show (label); } else { - gtk_label_set_text (GTK_LABEL (label), ""); + gtk_widget_hide (label); } } @@ -284,16 +342,11 @@ ev_properties_set_document (EvProperties *properties, g_free (text); } if (info->fields_mask & EV_DOCUMENT_INFO_FORMAT) { - char **format_str = g_strsplit (info->format, "-", 2); - - text = g_strdup_printf (_("%s"), format_str[1]); + text = g_strdup_printf ("%s", info->format); set_property (xml, FORMAT_PROPERTY, text); - - g_free (text); - g_strfreev (format_str); } if (info->fields_mask & EV_DOCUMENT_INFO_N_PAGES) { - text = g_strdup_printf (_("%d"), info->n_pages); + text = g_strdup_printf ("%d", info->n_pages); set_property (xml, N_PAGES_PROPERTY, text); g_free (text); }