]> spindle.queued.net Git - midori/commitdiff
Format addresses nicely, with no percents and no punycode
authorChristian Dywan <christian@twotoasts.de>
Mon, 5 Oct 2009 18:50:08 +0000 (20:50 +0200)
committerChristian Dywan <christian@twotoasts.de>
Mon, 5 Oct 2009 18:50:08 +0000 (20:50 +0200)
midori/midori-browser.c
midori/midori-view.c
midori/sokoke.c
midori/sokoke.h

index 2d48f23b86212fd9cbb8db4b9a7547cb70805265..dc549a88902cc231eeaa18174b0355e0278b8c0c 100644 (file)
@@ -351,7 +351,7 @@ _midori_browser_set_statusbar_text (MidoriBrowser* browser,
     gboolean is_location = widget ?
         MIDORI_IS_LOCATION_ENTRY (gtk_widget_get_parent (widget)) : FALSE;
 
-    katze_assign (browser->statusbar_text, g_strdup (text));
+    katze_assign (browser->statusbar_text, sokoke_format_uri_for_display (text));
 
     if (!GTK_WIDGET_VISIBLE (browser->statusbar) && !is_location)
     {
index 35bcb691afdaf587df67a23cde07c17feeb12aec..01c743e2dfb04bb753b51404420ce5902be66b62 100644 (file)
@@ -748,7 +748,7 @@ webkit_web_view_load_committed_cb (WebKitWebView*  web_view,
 
     uri = webkit_web_frame_get_uri (web_frame);
     g_return_if_fail (uri != NULL);
-    katze_assign (view->uri, g_strdup (uri));
+    katze_assign (view->uri, sokoke_format_uri_for_display (uri));
     if (view->item)
     {
         #if 0
@@ -2831,7 +2831,7 @@ midori_view_set_uri (MidoriView*  view,
         }
         else
         {
-            katze_assign (view->uri, g_strdup (uri));
+            katze_assign (view->uri, sokoke_format_uri_for_display (uri));
             g_object_notify (G_OBJECT (view), "uri");
             if (view->item)
                 katze_item_set_uri (view->item, uri);
index 7d40e8d0769a756cbd2cbceefb2d75356101565a..a1fa336fe4c26f2c7102fd4808b85d52e638886a 100644 (file)
@@ -358,6 +358,42 @@ sokoke_magic_uri (const gchar* uri,
     return search;
 }
 
+/**
+ * sokoke_format_uri_for_display:
+ * @uri: an URI string
+ *
+ * Formats an URI for display, for instance by converting
+ * percent encoded characters and by decoding punycode.
+ *
+ * Return value: a newly allocated URI
+ **/
+gchar*
+sokoke_format_uri_for_display (const gchar* uri)
+{
+    if (uri && g_str_has_prefix (uri, "http://"))
+    {
+        gchar* unescaped = g_uri_unescape_string (uri, NULL);
+        #ifdef HAVE_LIBSOUP_2_27_90
+        gchar* decoded = g_hostname_to_unicode (unescaped);
+        if (decoded)
+        {
+            g_free (unescaped);
+            return decoded;
+        }
+        return unescaped;
+        #elif HAVE_LIBIDN
+        gchar* decoded;
+        if (!idna_to_unicode_8z8z (unescaped, &decoded, 0) == IDNA_SUCCESS)
+            return unescaped;
+        g_free (unescaped);
+        return decoded;
+        #else
+        return unescaped;
+        #endif
+    }
+    return g_strdup (uri);
+}
+
 void
 sokoke_combo_box_add_strings (GtkComboBox* combobox,
                               const gchar* label_first, ...)
index ea23caafaad7e8fe1c09b066460d431d04645e06..15f2c882c6495b747bdbfabbfb9fa32412a74000 100644 (file)
@@ -48,6 +48,9 @@ gchar*
 sokoke_magic_uri                        (const gchar*    uri,
                                          KatzeArray*     search_engines);
 
+gchar*
+sokoke_format_uri_for_display           (const gchar*    uri);
+
 typedef enum {
     SOKOKE_MENU_POSITION_CURSOR = 0,
     SOKOKE_MENU_POSITION_LEFT,