From 1bf44c8b97a1255c1be31d24f5c7be12951f8873 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 23 Jun 2013 19:27:41 -0400 Subject: EUrlEntry: Try harder to recognize a valid URL. Skip leading whitespace and hand the rest to g_uri_parse_scheme(). If that can identify a scheme then make the open button sensitive. (Have to be careful to skip leading whitespace when opening, too.) --- e-util/e-url-entry.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'e-util') diff --git a/e-util/e-url-entry.c b/e-util/e-url-entry.c index 5b90f4a14f..501f4e5760 100644 --- a/e-util/e-url-entry.c +++ b/e-util/e-url-entry.c @@ -45,10 +45,22 @@ url_entry_text_to_sensitive (GBinding *binding, gpointer user_data) { const gchar *text; - gboolean sensitive; + gboolean sensitive = FALSE; text = g_value_get_string (source_value); - sensitive = (text != NULL && *text != '\0'); + + if (text != NULL) { + gchar *scheme; + + /* Skip leading whitespace. */ + while (g_ascii_isspace (*text)) + text++; + + scheme = g_uri_parse_scheme (text); + sensitive = (scheme != NULL); + g_free (scheme); + } + g_value_set_boolean (target_value, sensitive); return TRUE; @@ -70,6 +82,10 @@ url_entry_icon_release_cb (GtkEntry *entry, text = gtk_entry_get_text (entry); g_return_if_fail (text != NULL); + /* Skip leading whitespace. */ + while (g_ascii_isspace (*text)) + text++; + e_show_uri (toplevel, text); } } -- cgit v1.2.3