Format addresses nicely, with no percents and no punycode

This commit is contained in:
Christian Dywan 2009-10-05 20:50:08 +02:00
parent 1998219933
commit 7aaf59ec9a
4 changed files with 42 additions and 3 deletions

View 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)
{

View 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);

View 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, ...)

View 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,