[epiphany] ephy-window: centralize the logic about invisible URIs in one place



commit 2d13b6f05db1f5982b790769001549254b2480f9
Author: Xan Lopez <xan igalia com>
Date:   Fri Aug 24 15:58:15 2012 +0200

    ephy-window: centralize the logic about invisible URIs in one place
    
    Let's make EphyWindow the one in charge of deciding whether a URI is
    actually shown or not in the location entry. This allows to remove
    some code to that effect in EphyLocationController (and perhaps some
    more in EphyWebView in the future), and makes this feature more
    extensible for the future.

 lib/widgets/ephy-location-entry.c |    2 +-
 src/ephy-window.c                 |   34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index a812845..34e8e48 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -1305,7 +1305,7 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
 		}
 	}
 
-	if (address != NULL && strcmp (address, "about:blank") != 0)
+	if (address != NULL)
 	{
 		if (g_str_has_prefix (address, EPHY_ABOUT_SCHEME))
 			effective_text = g_strdup_printf ("about:%s",
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 0177e51..a710258 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1469,6 +1469,35 @@ setup_ui_manager (EphyWindow *window)
 				    gtk_ui_manager_get_accel_group (manager));
 }
 
+/* This is the list of addresses that should never be shown in the
+ * window's location entry. */
+static const char * do_not_show_address[] = {
+	"about:blank",
+	NULL
+};
+
+static char *
+calculate_location (const char *typed_address, const char *address)
+{
+	int i;
+	const char *location;
+
+	/* If there's a typed address, use that over address. Never
+	 * show URIs in the 'do_not_show_address' array. */
+	location = typed_address ? typed_address : address;
+	
+	for (i = 0; do_not_show_address[i]; i++)
+	{
+		if (g_str_equal (location, do_not_show_address[i]))
+		{
+			location = NULL;
+			break;
+		}
+	}
+
+	return g_strdup (location);
+}
+
 static void
 sync_tab_address (EphyWebView *view,
 	          GParamSpec *pspec,
@@ -1477,13 +1506,16 @@ sync_tab_address (EphyWebView *view,
 	EphyWindowPrivate *priv = window->priv;
 	const char *address;
 	const char *typed_address;
+	char *location;
 
 	if (priv->closing) return;
 
 	address = ephy_web_view_get_address (view);
 	typed_address = ephy_web_view_get_typed_address (view);
 
-	ephy_window_set_location (window, typed_address ? typed_address : address);
+	location = calculate_location (typed_address, address);
+	ephy_window_set_location (window, location);
+	g_free (location);
 	ephy_find_toolbar_request_close (priv->find_toolbar);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]