[yelp] [libyelp] Make relative links work for HTML documents



commit 12847b689b9d4e436940b213ca35c3b87401b545
Author: Shaun McCance <shaunm gnome org>
Date:   Mon May 10 10:48:29 2010 -0500

    [libyelp] Make relative links work for HTML documents

 libyelp/yelp-uri.c  |   14 +++++++++++++-
 libyelp/yelp-view.c |    9 +++++----
 tests/test-uri.c    |    4 ++--
 3 files changed, 20 insertions(+), 7 deletions(-)
---
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index ee17b75..7e76042 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -482,7 +482,19 @@ resolve_file_path (YelpUri *uri)
         priv->gfile = g_file_new_for_path (path);
     }
     else if (base_priv && base_priv->gfile) {
-        priv->gfile = g_file_resolve_relative_path (base_priv->gfile, path);
+        GFileInfo *info;
+        info = g_file_query_info (base_priv->gfile,
+                                  G_FILE_ATTRIBUTE_STANDARD_TYPE,
+                                  G_FILE_QUERY_INFO_NONE,
+                                  NULL, NULL);
+        if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) {
+            GFile *parent = g_file_get_parent (base_priv->gfile);
+            priv->gfile = g_file_resolve_relative_path (parent, path);
+            g_object_unref (parent);
+        }
+        else {
+            priv->gfile = g_file_resolve_relative_path (base_priv->gfile, path);
+        }
     }
     else {
         gchar *cur;
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 767299b..baf15bd 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -560,13 +560,14 @@ view_navigation_requested (WebKitWebView             *view,
                            WebKitWebPolicyDecision   *decision,
                            gpointer                   user_data)
 {
+    const gchar *requri = webkit_network_request_get_uri (request);
     YelpViewPrivate *priv = GET_PRIV (view);
     YelpUri *uri;
 
-    debug_print (DB_FUNCTION, "entering\n");
-
-    uri = yelp_uri_new_relative (priv->uri,
-                                 webkit_network_request_get_uri (request));
+    if (g_str_has_prefix (requri, BOGUS_URI))
+        uri = yelp_uri_new_relative (priv->uri, requri + BOGUS_URI_LEN);
+    else
+        uri = yelp_uri_new_relative (priv->uri, requri);
 
     webkit_web_policy_decision_ignore (decision);
 
diff --git a/tests/test-uri.c b/tests/test-uri.c
index 869d9b1..d288999 100644
--- a/tests/test-uri.c
+++ b/tests/test-uri.c
@@ -35,7 +35,7 @@ static void
 print_uri (gchar *orig, YelpUri *uri, GOutputStream *stream)
 {
     GFile *file;
-    gchar *type, *tmp, **tmpv, *out;
+    gchar *type = NULL, *tmp, **tmpv, *out;
 
     g_output_stream_write (stream, orig, strlen (orig), NULL, NULL);
     g_output_stream_write (stream, "\n", 1, NULL, NULL);
@@ -199,7 +199,7 @@ run_all_tests (int argc, char **argv)
                                                                    G_FILE_ATTRIBUTE_STANDARD_NAME);
         if (!g_str_has_suffix (name, ".test"))
             continue;
-        list = g_list_insert_sorted (list, name, strcmp);
+        list = g_list_insert_sorted (list, (gchar *) name, (GCompareFunc) strcmp);
     }
 
     while (list) {



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