]> www.fi.muni.cz Git - evince.git/commitdiff
escape the text correctly. Handles non-UTF-8 properties and escaped
authorJonathan Blandford <jrb@redhat.com>
Sun, 19 Jun 2005 03:04:20 +0000 (03:04 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Sun, 19 Jun 2005 03:04:20 +0000 (03:04 +0000)
Sat Jun 18 22:46:42 2005  Jonathan Blandford  <jrb@redhat.com>

        * shell/ev-properties.c (set_property): escape the text correctly.
        Handles non-UTF-8 properties and escaped properties.  Also, sets
        the text to "<i>None</i>" if the property isn't set.

        * data/evince-properties.glade: Change the label to be ellipsized,
        and give it a minimum size.

ChangeLog
data/evince-properties.glade
shell/ev-properties.c

index 64d0462a76ff18dc22d17b92ebe27980b87ba496..ececb0b8ec4473d22a5146106cacf6f2920105f2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Jun 18 22:46:42 2005  Jonathan Blandford  <jrb@redhat.com>
+
+       * shell/ev-properties.c (set_property): escape the text correctly.
+       Handles non-UTF-8 properties and escaped properties.  Also, sets
+       the text to "<i>None</i>" if the property isn't set.
+
+       * data/evince-properties.glade: Change the label to be ellipsized,
+       and give it a minimum size.
+
 2005-06-19  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * lib/ev-file-helpers.c: (ev_file_helpers_shutdown):
index 80423fa66596174d0b855fb77e2cb81b96d296e2..c18a08f74f778a5084a408139c54f0ddc31ef5ed 100644 (file)
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
                  <property name="yalign">0.5</property>
                  <property name="xpad">0</property>
                  <property name="ypad">0</property>
-                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-                 <property name="width_chars">-1</property>
+                 <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+                 <property name="width_chars">25</property>
                  <property name="single_line_mode">False</property>
                  <property name="angle">0</property>
                </widget>
index 0b9d8975232e16ef12c8f8f16764c7bd193cf7a8..d7974c0f1ef5b16bb3777e73075fd9cabac85196 100644 (file)
@@ -33,6 +33,7 @@
 #include <glade/glade.h>
 #include <time.h>
 #include <sys/time.h>
+#include <string.h>
 
 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 ("<i>%s</i>", _("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