[Xfce4-commits] <midori:master> Don't include http(s), file or www. in page title
Christian Dywan
noreply at xfce.org
Wed Nov 7 01:22:03 CET 2012
Updating branch refs/heads/master
to ea953650e2a0ac8fa27597e8f99e3e4a5aab509e (commit)
from 4a598983d541dc5f60b0b9d115cf01d6d9fbc582 (commit)
commit ea953650e2a0ac8fa27597e8f99e3e4a5aab509e
Author: Christian Dywan <christian at twotoasts.de>
Date: Tue Nov 6 23:16:37 2012 +0100
Don't include http(s), file or www. in page title
Same code is now shared with url completion.
Fixes: https://bugs.launchpad.net/midori/+bug/1075033
katze/midori-uri.vala | 12 ++++++++++++
midori/midori-locationaction.c | 13 ++-----------
midori/midori-tab.vala | 2 +-
tests/magic-uri.c | 28 ++++++++++++++++++++++++++++
tests/tab.vala | 2 +-
5 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/katze/midori-uri.vala b/katze/midori-uri.vala
index 88e3027..dc98fc9 100644
--- a/katze/midori-uri.vala
+++ b/katze/midori-uri.vala
@@ -63,6 +63,18 @@ namespace Midori {
}
return uri;
}
+
+ /* Strip http(s), file and www. for tab titles or completion */
+ public static string strip_prefix_for_display (string uri) {
+ if (is_http (uri) || uri.has_prefix ("file://")) {
+ string stripped_uri = uri.split ("://")[1];
+ if (is_http (uri) && stripped_uri.has_prefix ("www."))
+ return stripped_uri.substring (4, -1);
+ return stripped_uri;
+ }
+ return uri;
+ }
+
public static string format_for_display (string? uri) {
/* Percent-decode and decode puniycode for user display */
if (uri != null && uri.has_prefix ("http://")) {
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index 079448e..6449244 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -1336,17 +1336,7 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
if (G_LIKELY (uri))
{
- /* Strip URI scheme and www. for display to reduce visual noise */
- gchar* stripped_uri = uri;
- if (g_str_has_prefix (uri, "http://"))
- stripped_uri = &uri[7];
- else if (g_str_has_prefix (uri, "https://"))
- stripped_uri = &uri[8];
- else if (g_str_has_prefix (uri, "file://"))
- stripped_uri = &uri[7];
- if (g_str_has_prefix (stripped_uri, "www."))
- stripped_uri = &stripped_uri[4];
-
+ gchar* stripped_uri = midori_uri_strip_prefix_for_display (uri);
temp_iter = temp = g_utf8_strdown (stripped_uri, -1);
desc_iter = stripped_uri;
key_idx = 0;
@@ -1400,6 +1390,7 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
else
desc_uri = g_markup_escape_text (stripped_uri, -1);
g_free (temp);
+ g_free (stripped_uri);
}
if (G_LIKELY (title))
diff --git a/midori/midori-tab.vala b/midori/midori-tab.vala
index 1ab694a..4c8072f 100644
--- a/midori/midori-tab.vala
+++ b/midori/midori-tab.vala
@@ -151,7 +151,7 @@ namespace Midori {
/* Work-around libSoup not setting a proper directory title */
if (title == null || (title == "OMG!" && uri.has_prefix ("file://")))
- return uri;
+ return Midori.URI.strip_prefix_for_display (uri);
#if !HAVE_WIN32
/* If left-to-right text is combined with right-to-left text the default
diff --git a/tests/magic-uri.c b/tests/magic-uri.c
index 714a078..cf9d60f 100644
--- a/tests/magic-uri.c
+++ b/tests/magic-uri.c
@@ -300,6 +300,33 @@ magic_uri_format (void)
}
static void
+magic_uri_prefix (void)
+{
+
+ typedef struct
+ {
+ const gchar* before;
+ const gchar* after;
+ } URIItem;
+
+ static const URIItem items[] = {
+ { "http://www.example.com", "example.com" },
+ { "http://example.com", "example.com" },
+ { "https://example.com", "example.com" },
+ { "file:///path/to/my/heart", "/path/to/my/heart" },
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (items); i++)
+ {
+ gchar* result = midori_uri_strip_prefix_for_display (items[i].before);
+ const gchar* after = items[i].after ? items[i].after : items[i].before;
+ katze_assert_str_equal (items[i].before, result, after);
+ g_free (result);
+ }
+}
+
+static void
magic_uri_prefetch (void)
{
g_assert (!sokoke_prefetch_uri (NULL, NULL, NULL, NULL));
@@ -374,6 +401,7 @@ main (int argc,
g_test_add_func ("/magic-uri/fingerprint", magic_uri_fingerprint);
g_test_add_func ("/magic-uri/ip", magic_uri_ip);
g_test_add_func ("/magic-uri/format", magic_uri_format);
+ g_test_add_func ("/magic-uri/prefix", magic_uri_prefix);
g_test_add_func ("/magic-uri/prefetch", magic_uri_prefetch);
g_test_add_func ("/magic-uri/commands", magic_uri_commands);
diff --git a/tests/tab.vala b/tests/tab.vala
index 3fe1439..7566175 100644
--- a/tests/tab.vala
+++ b/tests/tab.vala
@@ -42,7 +42,7 @@ const TestCaseEllipsize[] titles = {
Pango.EllipsizeMode.START, null },
{ "file:///home/user",
"OMG!",
- Pango.EllipsizeMode.START, "file:///home/user" },
+ Pango.EllipsizeMode.START, "/home/user" },
{ "http://paste.foo/0007-Bump-version-to-0.4.7.patch",
null,
Pango.EllipsizeMode.START, "0007-Bump-version-to-0.4.7.patch" },
More information about the Xfce4-commits
mailing list