From: Christian Dywan Date: Mon, 5 Oct 2009 18:50:08 +0000 (+0200) Subject: Format addresses nicely, with no percents and no punycode X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7aaf59ec9a75553ea081c9988bf03b6d3006bb3c;p=midori Format addresses nicely, with no percents and no punycode --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 2d48f23b..dc549a88 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -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) { diff --git a/midori/midori-view.c b/midori/midori-view.c index 35bcb691..01c743e2 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -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); diff --git a/midori/sokoke.c b/midori/sokoke.c index 7d40e8d0..a1fa336f 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -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, ...) diff --git a/midori/sokoke.h b/midori/sokoke.h index ea23caaf..15f2c882 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -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,