]> www.fi.muni.cz Git - evince.git/commitdiff
[ui] Escape URIs for display
authorNickolay V. Shmyrev <nshmyrev@yandex.ru>
Sun, 3 May 2009 08:21:17 +0000 (12:21 +0400)
committerNickolay V. Shmyrev <nshmyrev@yandex.ru>
Sun, 3 May 2009 08:21:17 +0000 (12:21 +0400)
Uses uri escaping function to make more sensible URI's to display them.
Fixes GNOME bug #581064.

shell/ev-utils.c
shell/ev-utils.h
shell/ev-window-title.c
shell/ev-window.c

index 13f14598a1832d37538f0c8eae0300e5e614d0f6..540836fde5c2902c0426d73234abc4752672ee2d 100644 (file)
@@ -400,3 +400,43 @@ get_gdk_pixbuf_format_by_extension (gchar *uri)
        return NULL;
 }
 
+#define XDIGIT(c) ((c) <= '9' ? (c) - '0' : ((c) & 0x4F) - 'A' + 10)
+#define HEXCHAR(s) ((XDIGIT (s[1]) << 4) + XDIGIT (s[2]))
+
+static char *
+uri_decoded_copy (const char *part, int length)
+{
+       unsigned char *s, *d;
+       char *decoded = g_strndup (part, length);
+
+       s = d = (unsigned char *)decoded;
+       do {
+               if (*s == '%') {
+                       if (!g_ascii_isxdigit (s[1]) ||
+                           !g_ascii_isxdigit (s[2])) {
+                               g_free (decoded);
+                               return NULL;
+                       }
+                       *d++ = HEXCHAR (s);
+                       s += 2;
+               } else
+                       *d++ = *s;
+       } while (*s++);
+
+       return decoded;
+}
+
+char* escape_uri_for_display (const char *uri)
+{
+       GFile *file;
+       char *disp;
+       char *filename;
+
+       file = g_file_new_for_uri (uri);
+       filename = g_file_get_parse_name (file);
+       disp = uri_decoded_copy (filename, strlen (filename));
+       g_free (filename);
+       g_object_unref (file);
+
+       return disp;
+}
index f7c58a728c97ceb005513cfdb07bd63225919109..ac89b1ea6914a21a7fae0aa6de9437af4934d2ad 100644 (file)
@@ -44,6 +44,7 @@ gdouble               get_screen_dpi (GtkWindow * window);
 void                           file_chooser_dialog_add_writable_pixbuf_formats (GtkFileChooser *chooser);
 GdkPixbufFormat*       get_gdk_pixbuf_format_by_extension (gchar *uri);
 
+char*                  escape_uri_for_display (const char *uri);
 G_END_DECLS
 
 #endif /* __EV_VIEW_H__ */
index 9cfd865b71ec31bde6f2f0bbea3c25017270ac18..baafa74f399278d607418375085c43efb0c1d0d0 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 #include "ev-window-title.h"
 #include "ev-backends-manager.h"
+#include "ev-utils.h"
 
 #include <string.h>
 #include <gio/gio.h>
@@ -71,14 +72,14 @@ ev_window_title_new (EvWindow *window)
 static char *
 get_filename_from_uri (const char *uri)
 {
-       GFile *file;
        char *filename;
+       char *basename;
        
-       file = g_file_new_for_uri (uri);
-       filename = g_file_get_basename (file);
-       g_object_unref (file);
+       filename = escape_uri_for_display (uri);
+       basename = g_path_get_basename (filename);
+       g_free(filename);
 
-       return filename;
+       return basename;
 }
 
 /* Some docs report titles with confusing extensions (ex. .doc for pdf).
index 92f5089d150487e3da417b7c2dfba0fbe9834309..5d99f667764ac7e5f277143a88ff0df8334a8c31 100644 (file)
@@ -1586,12 +1586,15 @@ show_loading_progress (EvWindow *ev_window)
 {
        GtkWidget *area;
        gchar     *text;
+       gchar     *display_name;
        
        if (ev_window->priv->message_area)
                return FALSE;
-       
-       text = g_strdup_printf (_("Loading document from %s"),
-                               ev_window->priv->uri);
+
+       display_name = escape_uri_for_display (ev_window->priv->uri);
+       text = g_strdup_printf (_("Loading document from ā€œ%sā€"),
+                               display_name);
+
        area = ev_progress_message_area_new (GTK_STOCK_OPEN,
                                             text,
                                             GTK_STOCK_CLOSE,
@@ -1604,7 +1607,9 @@ show_loading_progress (EvWindow *ev_window)
                          ev_window);
        gtk_widget_show (area);
        ev_window_set_message_area (ev_window, area);
+
        g_free (text);
+       g_free (display_name);
 
        return FALSE;
 }