[epiphany/gnome-2-28] Add back support for the "direction up" navigation (GNOME bug 595653)



commit 8b8b015b6585c143fce8b59c0ea770bc38fe607a
Author: Frédéric Péters <fpeters 0d be>
Date:   Sat Sep 19 09:56:11 2009 +0200

    Add back support for the "direction up" navigation (GNOME bug 595653)

 embed/ephy-web-view.c        |   70 +++++++++++++++++++++++++++++++++++++++--
 src/ephy-navigation-action.c |    2 +
 2 files changed, 68 insertions(+), 4 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index d787c3a..f59ffa2 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1660,15 +1660,30 @@ ephy_web_view_set_icon_address (EphyWebView *view,
  * @view: an #EphyWebView
  *
  * Returns whether @view can travel to a higher-level directory on the server.
- * For example, for http://www.example.com/subdir/index.html, returns %TRUE; for
- * http://www.example.com/index.html, returns %FALSE.
+ * For example, for http://www.example.com/subdir/foo.html, returns %TRUE; for
+ * http://www.example.com/, returns %FALSE.
  *
  * Return value: %TRUE if @view can browse to a higher-level directory
  **/
 gboolean
 ephy_web_view_can_go_up (EphyWebView *view)
 {
-  return FALSE;
+  SoupURI *uri;
+  gboolean result;
+
+  uri = soup_uri_new (ephy_web_view_get_address (view));
+  if (uri == NULL)
+    return FALSE;
+
+  if (strcmp (uri->scheme, "about") == 0 || strcmp (uri->scheme, "data") == 0) {
+    soup_uri_free (uri);
+    return FALSE;
+  }
+
+  result = (uri->fragment || uri->query || strlen (uri->path) > 1);
+  soup_uri_free (uri);
+
+  return result;
 }
 
 /**
@@ -2088,7 +2103,54 @@ ephy_web_view_print_preview_navigate (EphyWebView *view,
 GSList *
 ephy_web_view_get_go_up_list (EphyWebView *view)
 {
-  return NULL;
+  SoupURI *uri;
+  GSList *result = NULL;
+  char *t1, *t2;
+
+  uri = soup_uri_new (ephy_web_view_get_address (view));
+  if (uri == NULL)
+    return NULL;
+
+  if (strcmp (uri->scheme, "about") == 0 || strcmp (uri->scheme, "data") == 0) {
+    soup_uri_free (uri);
+    return NULL;
+  }
+
+  /* remove fragment, then query, then go up path */
+  if (uri->fragment) {
+    soup_uri_set_fragment (uri, NULL);
+    result = g_slist_prepend (result, soup_uri_to_string (uri, FALSE));
+  }
+
+  if (uri->query) {
+    soup_uri_set_query (uri, NULL);
+    result = g_slist_prepend (result, soup_uri_to_string (uri, FALSE));
+  }
+
+  if (uri->path[strlen(uri->path)-1] != '/') {
+    /* not a trailing slash, remove "file" part */
+    t1 = strrchr (uri->path, '/');
+    t2 = g_strndup (uri->path, t1-uri->path+1);
+    soup_uri_set_path (uri, t2);
+    g_free (t2);
+    result = g_slist_prepend (result, soup_uri_to_string (uri, FALSE));
+  }
+
+  while (strcmp(uri->path, "/") != 0) {
+    /* chop trailing / */
+    uri->path[strlen (uri->path)-1] = 0;
+    t1 = strrchr (uri->path, '/');
+    t2 = g_strndup (uri->path, t1-uri->path+1);
+    soup_uri_set_path (uri, t2);
+    g_free (t2);
+    result = g_slist_prepend (result, soup_uri_to_string (uri, FALSE));
+  }
+
+  result = g_slist_reverse (result);
+
+  soup_uri_free (uri);
+
+  return result;
 }
 
 /**
diff --git a/src/ephy-navigation-action.c b/src/ephy-navigation-action.c
index bfbae85..972f86d 100644
--- a/src/ephy-navigation-action.c
+++ b/src/ephy-navigation-action.c
@@ -318,6 +318,7 @@ build_up_menu (EphyNavigationAction *action)
 	}
 
 	/* the list data has been consumed */
+	g_slist_foreach (list, (GFunc) g_free, NULL);
 	g_slist_free (list);
 
 	return GTK_WIDGET (menu);
@@ -434,6 +435,7 @@ ephy_navigation_action_activate (GtkAction *gtk_action)
 				up_list->data,
 				NULL,
 				ephy_gui_is_middle_click () ? EPHY_LINK_NEW_TAB : 0);
+		g_slist_foreach (up_list, (GFunc) g_free, NULL);
 		g_slist_free (up_list);
 	}
 }



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