[epiphany] Remove redundant parameters in location-set API



commit 5aee0deca12e14554ce0fa0d4b02613e99ba77a9
Author: Diego Escalante Urrelo <diegoe gnome org>
Date:   Wed Dec 2 17:01:24 2009 -0500

    Remove redundant parameters in location-set API
    
    EphyLocationEntry, EphyLocationAction and EphyToolbar take an @adress and
    @typed_address parameter, while both are useful we only end up using one so we
    can easily decide which one to use in ephy-window.c instead of carrying both
    around until ephy-location-entry.c
    
    Bonus: make ephy_location_entry_set_location accept NULL as @address safely.
    
    Bug #603651

 lib/widgets/ephy-location-entry.c |   22 +++++++---------------
 lib/widgets/ephy-location-entry.h |    3 +--
 src/ephy-location-action.c        |   20 ++++++--------------
 src/ephy-location-action.h        |    3 +--
 src/ephy-lockdown.c               |    2 +-
 src/ephy-toolbar.c                |   11 ++++-------
 src/ephy-toolbar.h                |    3 +--
 src/ephy-window.c                 |   11 +++++++----
 tests/testephylocationentry.c     |   19 ++++++-------------
 9 files changed, 34 insertions(+), 60 deletions(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 009d5f8..217aa80 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -561,7 +561,7 @@ match_selected_cb (GtkEntryCompletion *completion,
 	priv->needs_reset = (state == GDK_CONTROL_MASK ||
 			     state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
 
-	ephy_location_entry_set_location (entry, item, NULL);
+	ephy_location_entry_set_location (entry, item);
 	//gtk_im_context_reset (GTK_ENTRY (entry->priv->entry)->im_context);
 	g_signal_emit_by_name (priv->entry, "activate");
 
@@ -1304,15 +1304,13 @@ ephy_location_entry_set_completion (EphyLocationEntry *entry,
 /**
  * ephy_location_entry_set_location:
  * @entry: an #EphyLocationEntry widget
- * @address: current location address
- * @typed_address: address shown in the location entry
+ * @address: new location address
  *
- * Sets the current address of @entry to @address or @typed_address if given.
+ * Sets the current address of @entry to @address.
  **/
 void
 ephy_location_entry_set_location (EphyLocationEntry *entry,
-				  const char *address,
-				  const char *typed_address)
+				  const char *address)
 {
 	EphyLocationEntryPrivate *priv = entry->priv;
 	GtkClipboard *clipboard;
@@ -1320,8 +1318,6 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
 	char* selection = NULL;
 	int start, end;
 
-	g_return_if_fail (address != NULL);
-
 	/* Setting a new text will clear the clipboard. This makes it impossible
 	 * to copy&paste from the location entry of one tab into another tab, see
 	 * bug #155824. So we save the selection iff the clipboard was owned by
@@ -1342,11 +1338,7 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
 		}
 	}
 
-	if (typed_address != NULL)
-	{
-		text = typed_address;
-	}
-	else if (address != NULL && strcmp (address, "about:blank") != 0)
+	if (address != NULL && strcmp (address, "about:blank") != 0)
 	{
 		text = address;
 	}
@@ -1356,7 +1348,7 @@ ephy_location_entry_set_location (EphyLocationEntry *entry,
 	}
 
 	/* First record the new hash, then update the entry text */
-	priv->hash = g_str_hash (address);
+	priv->hash = g_str_hash (text);
 
 	priv->block_update = TRUE;
 	gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
@@ -1452,7 +1444,7 @@ ephy_location_entry_reset_internal (EphyLocationEntry *entry,
 
 	retval = g_str_hash (text) != g_str_hash (old_text);
 
-	ephy_location_entry_set_location (entry, text, NULL);
+	ephy_location_entry_set_location (entry, text);
 	g_free (url);
 
 	if (notify)
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 708510d..2bb0d46 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -76,8 +76,7 @@ void		ephy_location_entry_set_completion	(EphyLocationEntry *entry,
 							 guint favicon_col);
 
 void		ephy_location_entry_set_location	(EphyLocationEntry *entry,
-							 const char *address,
-							 const char *typed_address);
+							 const char *address);
 
 void		ephy_location_entry_set_match_func	(EphyLocationEntry *entry, 
 							 GtkEntryCompletionMatchFunc match_func,
diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c
index 580aa90..598f9ff 100644
--- a/src/ephy-location-action.c
+++ b/src/ephy-location-action.c
@@ -50,7 +50,6 @@ struct _EphyLocationActionPrivate
 	GtkWidget *proxy;
 	GList *actions;
 	char *address;
-	char *typed_address;
 	EphyNode *smart_bmks;
 	EphyBookmarks *bookmarks;
 	GdkPixbuf *icon;
@@ -224,7 +223,7 @@ user_changed_cb (GtkWidget *proxy, EphyLocationAction *action)
 	LOG ("user_changed_cb, new address %s", address);
 
 	g_signal_handlers_block_by_func (action, G_CALLBACK (sync_address), proxy);
-	ephy_location_action_set_address (action, address, NULL);
+	ephy_location_action_set_address (action, address);
 	g_signal_handlers_unblock_by_func (action, G_CALLBACK (sync_address), proxy);
 }
 
@@ -247,8 +246,7 @@ sync_address (GtkAction *gaction,
 	LOG ("sync_address %s", action->priv->address);
 
 	g_signal_handlers_block_by_func (proxy, G_CALLBACK (user_changed_cb), action);
-	ephy_location_entry_set_location (lentry, priv->address,
-					  priv->typed_address);
+	ephy_location_entry_set_location (lentry, priv->address);
 	g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (user_changed_cb), action);
 }
 
@@ -579,7 +577,7 @@ ephy_location_action_set_property (GObject *object,
 	switch (prop_id)
 	{
 		case PROP_ADDRESS:
-			ephy_location_action_set_address (action, g_value_get_string (value), NULL);
+			ephy_location_action_set_address (action, g_value_get_string (value));
 			break;
 		case PROP_EDITABLE:
 			priv->editable = g_value_get_boolean (value);
@@ -935,7 +933,6 @@ ephy_location_action_finalize (GObject *object)
 
 	g_list_free (priv->actions);
 	g_free (priv->address);
-	g_free (priv->typed_address);
 	g_free (priv->lock_stock_id);
 	g_free (priv->lock_tooltip);
 
@@ -961,15 +958,13 @@ ephy_location_action_get_address (EphyLocationAction *action)
 /**
  * ephy_location_action_set_address:
  * @action: an #EphyLocationAction
- * @address: the current address
- * @typed_address: address typed by the user
+ * @address: new address
  *
- * Sets the @address and @typed_address in @action.
+ * Sets @address as the address of @action.
  **/
 void
 ephy_location_action_set_address (EphyLocationAction *action,
-				  const char *address,
-				  const char *typed_address)
+				  const char *address)
 {
 	EphyLocationActionPrivate *priv;
 
@@ -982,8 +977,5 @@ ephy_location_action_set_address (EphyLocationAction *action,
 	g_free (priv->address);
 	priv->address = g_strdup (address);
 
-	g_free (priv->typed_address);
-	priv->typed_address = g_strdup (typed_address);
-
 	g_object_notify (G_OBJECT (action), "address");
 }
diff --git a/src/ephy-location-action.h b/src/ephy-location-action.h
index 2fa69a6..e94931a 100644
--- a/src/ephy-location-action.h
+++ b/src/ephy-location-action.h
@@ -60,8 +60,7 @@ GType		ephy_location_action_get_type		(void);
 const char     *ephy_location_action_get_address	(EphyLocationAction *action);
 
 void		ephy_location_action_set_address	(EphyLocationAction *action,
-							 const char *address,
-							 const char *typed_address);
+							 const char *address);
 
 G_END_DECLS
 
diff --git a/src/ephy-lockdown.c b/src/ephy-lockdown.c
index f11d7b0..bb3a035 100644
--- a/src/ephy-lockdown.c
+++ b/src/ephy-lockdown.c
@@ -105,7 +105,7 @@ update_location_editable (EphyWindow *window,
 		if (embed != NULL)
 		{
 			address = ephy_web_view_get_location (EPHY_GET_EPHY_WEB_VIEW_FROM_EMBED (embed), TRUE);
-			ephy_toolbar_set_location (EPHY_TOOLBAR (toolbar), address, NULL);
+			ephy_toolbar_set_location (EPHY_TOOLBAR (toolbar), address);
 			ephy_web_view_set_typed_address (EPHY_GET_EPHY_WEB_VIEW_FROM_EMBED (embed), NULL);
 			g_free (address);
 		}
diff --git a/src/ephy-toolbar.c b/src/ephy-toolbar.c
index b562ebb..83c34e9 100644
--- a/src/ephy-toolbar.c
+++ b/src/ephy-toolbar.c
@@ -475,16 +475,13 @@ ephy_toolbar_get_location (EphyToolbar *toolbar)
 /**
  * ephy_toolbar_set_location:
  * @toolbar: an #EphyToolbar widget
- * @address: current @toolbar address
- * @typed_address: address currently typed by the user
+ * @address: new address
  *
- * Calls ephy_location_action_set_address in the internal #EphyLocationAction
- * with @address and @typed_address.
+ * Sets the internal #EphyLocationAction address to @address.
  **/
 void
 ephy_toolbar_set_location (EphyToolbar *toolbar,
-			   const char *address,
-			   const char *typed_address)
+			   const char *address)
 {
 	EphyToolbarPrivate *priv = toolbar->priv;
 	EphyLocationAction *action = EPHY_LOCATION_ACTION (priv->actions[LOCATION_ACTION]);
@@ -492,7 +489,7 @@ ephy_toolbar_set_location (EphyToolbar *toolbar,
 	if (priv->updating_address) return;
 
 	priv->updating_address = TRUE;
-	ephy_location_action_set_address (action, address, typed_address);
+	ephy_location_action_set_address (action, address);
 	priv->updating_address = FALSE;
 }
 
diff --git a/src/ephy-toolbar.h b/src/ephy-toolbar.h
index 13a3d7d..060a3ad 100644
--- a/src/ephy-toolbar.h
+++ b/src/ephy-toolbar.h
@@ -81,8 +81,7 @@ void		ephy_toolbar_activate_location		(EphyToolbar *toolbar);
 const char     *ephy_toolbar_get_location		(EphyToolbar *toolbar);
 
 void		ephy_toolbar_set_location		(EphyToolbar *toolbar,
-							 const char *address,
-							 const char *typed_address);
+							 const char *address);
 
 void		ephy_toolbar_set_navigation_actions	(EphyToolbar *toolbar,
 							 gboolean back,
diff --git a/src/ephy-window.c b/src/ephy-window.c
index aa10f2a..0f2ceed 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -1547,12 +1547,15 @@ sync_tab_address (EphyWebView *view,
 		  EphyWindow *window)
 {
 	EphyWindowPrivate *priv = window->priv;
+	const char *address;
+	const char *typed_address;
 
 	if (priv->closing) return;
 
-	ephy_toolbar_set_location (priv->toolbar,
-				   ephy_web_view_get_address (view),
-				   ephy_web_view_get_typed_address (view));
+	address = ephy_web_view_get_address (view);
+	typed_address = ephy_web_view_get_typed_address (view);
+
+	ephy_toolbar_set_location (priv->toolbar, typed_address ? typed_address : address);
 	ephy_find_toolbar_request_close (priv->find_toolbar);
 }
 
@@ -2922,7 +2925,7 @@ embed_modal_alert_cb (EphyEmbed *embed,
 
 	/* make sure the location entry shows the real URL of the tab's page */
 	address = ephy_web_view_get_address (EPHY_GET_EPHY_WEB_VIEW_FROM_EMBED (embed));
-	ephy_toolbar_set_location (priv->toolbar, address, NULL);
+	ephy_toolbar_set_location (priv->toolbar, address);
 
 	/* don't suppress alert */
 	return FALSE;
diff --git a/tests/testephylocationentry.c b/tests/testephylocationentry.c
index 905ae85..440fe18 100644
--- a/tests/testephylocationentry.c
+++ b/tests/testephylocationentry.c
@@ -56,15 +56,11 @@ test_entry_set_location (void)
 
   null = ephy_location_entry_get_location (entry);
 
-  ephy_location_entry_set_location (entry, set, NULL);
+  ephy_location_entry_set_location (entry, set);
   get = ephy_location_entry_get_location (entry);
   g_assert_cmpstr (set, ==, get);
 }
 
-/*
- * FIXME: there's an already an assertion to avoid null as the arg, but we
- * should *confirm* that it indeed fails, although I'm not pretty sure it's
- * required to fail if the text is NULL.
 static void
 test_entry_set_location_null (void)
 {
@@ -74,11 +70,10 @@ test_entry_set_location_null (void)
   EphyLocationEntry *entry;
   entry = EPHY_LOCATION_ENTRY (ephy_location_entry_new ());
 
-  ephy_location_entry_set_location (entry, NULL, NULL);
+  ephy_location_entry_set_location (entry, NULL);
   get = ephy_location_entry_get_location (entry);
-  g_assert_cmpstr (set, ==, get);
+  g_assert_cmpstr (set, !=, get);
 }
-*/
 
 static void
 test_entry_get_location (void)
@@ -89,7 +84,7 @@ test_entry_get_location (void)
   EphyLocationEntry *entry;
   entry = EPHY_LOCATION_ENTRY (ephy_location_entry_new ());
 
-  ephy_location_entry_set_location (entry, set, NULL);
+  ephy_location_entry_set_location (entry, set);
   get = ephy_location_entry_get_location (entry);
   g_assert_cmpstr (set, ==, get);
 }
@@ -132,8 +127,8 @@ test_entry_can_redo (void)
   entry = EPHY_LOCATION_ENTRY (ephy_location_entry_new ());
   g_assert_cmpint (ephy_location_entry_get_can_redo (entry), ==, FALSE);
 
-  /* Can't redo, in this point we can UNdo */
-  ephy_location_entry_set_location (entry, test, NULL);
+  /* Can't redo, in this point we can undo */
+  ephy_location_entry_set_location (entry, test);
   g_assert_cmpint (ephy_location_entry_get_can_redo (entry), ==, FALSE);
 
   /* Reset should set redo to TRUE */
@@ -158,11 +153,9 @@ main (int argc, char *argv[])
   g_test_add_func (
     "/lib/widgets/ephy-location-entry/get_location",
     test_entry_get_location);
-  /*
   g_test_add_func (
     "/lib/widgets/ephy-location-entry/set_location_null",
     test_entry_set_location_null);
-  */
   g_test_add_func (
     "/lib/widgets/ephy-location-entry/get_location_empty",
     test_entry_get_location_empty);



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