From af67fbedccab5044808a489a9f3a5540d42adcf2 Mon Sep 17 00:00:00 2001 From: Enrico Tröge Date: Thu, 19 Feb 2009 10:02:43 +0000 Subject: Use file: URIs instead of local paths, fixes use with more recent webkit 2009-02-19 Enrico Tröge * src/dh-assistant-view.c: (assistant_view_set_link): * src/dh-book-tree.c: (book_tree_find_uri_foreach): * src/dh-link.c: (link_free), (dh_link_new): * src/dh-link.h: Use file: URIs instead of local paths, fixes use with more recent webkit versions. svn path=/trunk/; revision=1265 --- Gentoo bug 272886 --- --- a/src/dh-assistant-view.c +++ b/src/dh-assistant-view.c @@ -169,6 +169,7 @@ assistant_view_set_link (DhAssistantView *view, gsize length; gchar *key; gsize key_length; + gsize offset = 0; const gchar *start; const gchar *end; @@ -203,7 +204,10 @@ assistant_view_set_link (DhAssistantView *view, return; } - file = g_mapped_file_new (filename, FALSE, NULL); + if (g_str_has_prefix (filename, "file://")) + offset = 7; + + file = g_mapped_file_new (filename + offset, FALSE, NULL); if (!file) { g_free (filename); return; @@ -326,7 +330,7 @@ assistant_view_set_link (DhAssistantView *view, * anchor links are handled internally in webkit. */ tmp = g_path_get_dirname (filename); - base = g_strconcat ("file://", tmp, "/fake", NULL); + base = g_strconcat (tmp, "/fake", NULL); g_free (tmp); webkit_web_view_load_html_string ( --- a/src/dh-book-tree.c +++ b/src/dh-book-tree.c @@ -245,22 +245,14 @@ book_tree_find_uri_foreach (GtkTreeModel *model, FindURIData *data) { DhLink *link; - const gchar *uri; gchar *link_uri; gtk_tree_model_get (model, iter, COL_LINK, &link, -1); - /* A bit hackish, could be made more generic. */ - if (g_str_has_prefix (data->uri, "file://")) { - uri = data->uri + 7; - } else { - uri = data->uri; - } - link_uri = dh_link_get_uri (link); - if (g_str_has_prefix (uri, link_uri)) { + if (g_str_has_prefix (data->uri, link_uri)) { data->found = TRUE; data->iter = *iter; data->path = gtk_tree_path_copy (path); diff --git a/src/dh-link.c b/src/dh-link.c index 230af73..f320daa 100644 --- a/src/dh-link.c +++ b/src/dh-link.c @@ -33,7 +33,7 @@ struct _DhLink { gchar *base; gchar *name; - gchar *uri; + gchar *filename; DhLink *book; DhLink *page; @@ -64,7 +64,7 @@ link_free (DhLink *link) g_free (link->base); g_free (link->id); g_free (link->name); - g_free (link->uri); + g_free (link->filename); if (link->book) { dh_link_unref (link->book); @@ -83,12 +83,12 @@ dh_link_new (DhLinkType type, const gchar *name, DhLink *book, DhLink *page, - const gchar *uri) + const gchar *filename) { DhLink *link; g_return_val_if_fail (name != NULL, NULL); - g_return_val_if_fail (uri != NULL, NULL); + g_return_val_if_fail (filename != NULL, NULL); if (type == DH_LINK_TYPE_BOOK) { g_return_val_if_fail (base != NULL, NULL); @@ -110,7 +110,7 @@ dh_link_new (DhLinkType type, } link->name = g_strdup (name); - link->uri = g_strdup (uri); + link->filename = g_strdup (filename); if (book) { link->book = dh_link_ref (book); @@ -205,11 +205,16 @@ dh_link_get_book_id (DhLink *link) gchar * dh_link_get_uri (DhLink *link) { - if (link->type == DH_LINK_TYPE_BOOK) { - return g_strconcat (link->base, "/", link->uri, NULL); - } + gchar *base, *uri; + + if (link->type == DH_LINK_TYPE_BOOK) + base = link->base; + else + base = link->book->base; + + uri = g_strconcat ("file://", base, "/", link->filename, NULL, NULL); - return g_strconcat (link->book->base, "/", link->uri, NULL); + return uri; } DhLinkType --- a/src/dh-link.h +++ b/src/dh-link.h @@ -51,7 +51,7 @@ DhLink * dh_link_new (DhLinkType type, const gchar *name, DhLink *book, DhLink *page, - const gchar *uri); + const gchar *filename); void dh_link_free (DhLink *link); gint dh_link_compare (gconstpointer a, gconstpointer b); -- cgit v0.8.2