diff options
author | Mikael Hallendal <micke@codefactory.se> | 2002-03-23 15:39:12 +0000 |
---|---|---|
committer | Mikael Hallendal <hallski@src.gnome.org> | 2002-03-23 15:39:12 +0000 |
commit | 5eea91668ae943be86c249b136aa9b86daaf54db (patch) | |
tree | d2e0e174ad3bbe8496f0f50adabe97bd4387f0ab | |
parent | ff964a4e080c49096ed530d02cc170c31a3cbf6d (diff) | |
download | yelp-5eea91668ae943be86c249b136aa9b86daaf54db.tar.gz |
added an argument if we want the return docpath to be prepended with
2002-03-23 Mikael Hallendal <micke@codefactory.se>
* src/yelp-util.c:
(yelp_util_extract_docpath_from_uri): added an argument if we want
the return docpath to be prepended with "ghelp:" or not.
(yelp_util_find_anchor_in_uri): added/impl.
* src/yelp-scrollkeeper.c (ys_parse_toc_section): use strstrip
instead of strchomp to clean up the name.
* src/yelp-html.c:
(yh_link_clicked_cb): also jump if the relative reference is ?foo
(yelp_html_open_uri): don't reload the page if it's the same as
already showing.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | src/yelp-html.c | 66 | ||||
-rw-r--r-- | src/yelp-scrollkeeper.c | 7 | ||||
-rw-r--r-- | src/yelp-util.c | 32 | ||||
-rw-r--r-- | src/yelp-util.h | 4 | ||||
-rw-r--r-- | src/yelp-view-content.c | 2 |
6 files changed, 87 insertions, 39 deletions
@@ -1,3 +1,18 @@ +2002-03-23 Mikael Hallendal <micke@codefactory.se> + + * src/yelp-util.c: + (yelp_util_extract_docpath_from_uri): added an argument if we want + the return docpath to be prepended with "ghelp:" or not. + (yelp_util_find_anchor_in_uri): added/impl. + + * src/yelp-scrollkeeper.c (ys_parse_toc_section): use strstrip + instead of strchomp to clean up the name. + + * src/yelp-html.c: + (yh_link_clicked_cb): also jump if the relative reference is ?foo + (yelp_html_open_uri): don't reload the page if it's the same as + already showing. + 2002-03-20 Mikael Hallendal <micke@codefactory.se> * src/yelp-view-index.c (set_relation): style-fixes. diff --git a/src/yelp-html.c b/src/yelp-html.c index df6b9a91..c582c18b 100644 --- a/src/yelp-html.c +++ b/src/yelp-html.c @@ -72,7 +72,8 @@ enum { LAST_SIGNAL }; -static gint signals[LAST_SIGNAL] = { 0 }; +static gint signals[LAST_SIGNAL] = { 0 }; +static GHashTable *cache_table = NULL; struct _YelpHtmlPriv { HtmlDocument *doc; @@ -150,6 +151,10 @@ yh_class_init (YelpHtmlClass *klass) yelp_marshal_VOID__STRING_STRING_BOOLEAN, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); + + if (cache_table == NULL) { + cache_table = g_hash_table_new (g_str_hash, g_str_equal); + } } @@ -159,7 +164,7 @@ yh_async_close_cb (GnomeVFSAsyncHandle *handle, gpointer callback_data) { StreamData *sdata; - + d(puts(G_GNUC_FUNCTION)); sdata = (StreamData *) callback_data; @@ -316,7 +321,7 @@ yh_link_clicked_cb (HtmlDocument *doc, const gchar *url, YelpHtml *html) handled = FALSE; /* If this is a relative reference. Shortcut reload. */ - if (url && url[0] == '#') { + if (url && (url[0] == '#' || url[0] == '?')) { html_view_jump_to_anchor (HTML_VIEW (html), &url[1]); handled = TRUE; @@ -341,7 +346,7 @@ yelp_html_new (void) gint len; gchar *text = "<html><body bgcolor=\"white\"><h1>Yelp</h1></body></html>"; len = strlen (text); - + html_document_write_stream (view->priv->doc, text, len); } @@ -359,7 +364,7 @@ yelp_html_open_uri (YelpHtml *view, YelpHtmlPriv *priv; StreamData *sdata; GnomeVFSURI *uri; - const char *fragment; + gchar *docpath; d(puts(G_GNUC_FUNCTION)); @@ -368,19 +373,33 @@ yelp_html_open_uri (YelpHtml *view, priv = view->priv; - d(g_print ("Trying to open: %s\n", str_uri)); - + docpath = yelp_util_extract_docpath_from_uri (str_uri, TRUE); + + if (!reference) { + reference = yelp_util_find_anchor_in_uri (str_uri); + } + + if (!strcmp (priv->base_uri, docpath)) { + /* Same document that are already shown in this view */ + /* Just jump if we have an anchor */ + if (reference) { + html_view_jump_to_anchor (HTML_VIEW (view), + reference); + } + + return; + } + + /* New document needs to be read. */ + g_free (priv->base_uri); + priv->base_uri = g_strdup (docpath); + html_document_clear (priv->doc); html_document_open_stream (priv->doc, "text/html"); - gtk_adjustment_set_value ( + gtk_adjustment_set_value ( gtk_layout_get_vadjustment (GTK_LAYOUT (view)), 0); - if (strcmp (priv->base_uri, str_uri)) { - g_free (priv->base_uri); - priv->base_uri = g_strdup (str_uri); - } - sdata = g_new0 (StreamData, 1); sdata->view = view; sdata->stream = priv->doc->current_stream; @@ -388,22 +407,15 @@ yelp_html_open_uri (YelpHtml *view, priv->connections = g_slist_prepend (priv->connections, sdata); - if (reference) { - gchar *tmp_uri = g_strconcat (str_uri, reference, NULL); - uri = gnome_vfs_uri_new (tmp_uri); - g_free (tmp_uri); - } else { - uri = gnome_vfs_uri_new (str_uri); - } - + uri = gnome_vfs_uri_new (docpath); + if (reference) { sdata->anchor = g_strdup (reference); - } else if (uri) { - fragment = gnome_vfs_uri_get_fragment_identifier (uri); - if (fragment) { - sdata->anchor = g_strdup (fragment); - } } + + d(g_print ("Trying to open: %s[%s]\n", docpath, reference)); + + /* FIXME: Implement some cache */ gnome_vfs_async_open_uri (&sdata->handle, uri, @@ -413,7 +425,7 @@ yelp_html_open_uri (YelpHtml *view, sdata); gnome_vfs_uri_unref (uri); - + html_stream_set_cancel_func (sdata->stream, yh_stream_cancel, sdata); diff --git a/src/yelp-scrollkeeper.c b/src/yelp-scrollkeeper.c index 6613722c..0fc515ec 100644 --- a/src/yelp-scrollkeeper.c +++ b/src/yelp-scrollkeeper.c @@ -288,7 +288,7 @@ ys_parse_toc_section (GNode *parent, return; } - g_strchomp (name); + g_strstrip (name); xml_str = xmlGetProp (xml_node, "linkid"); @@ -298,11 +298,6 @@ ys_parse_toc_section (GNode *parent, xmlFree (xml_str); } -/* if (link) { */ -/* uri = gnome_vfs_uri_resolve_relative (base_uri, link); */ -/* } else { */ -/* } */ - node = g_node_append_data (parent, yelp_section_new (YELP_SECTION_DOCUMENT_SECTION, name, diff --git a/src/yelp-util.c b/src/yelp-util.c index eb840c87..6ca106a3 100644 --- a/src/yelp-util.c +++ b/src/yelp-util.c @@ -472,17 +472,18 @@ yelp_util_find_node_from_uri (GNode *doc_tree, const gchar *uri) } gchar * -yelp_util_extract_docpath_from_uri (const gchar *str_uri) +yelp_util_extract_docpath_from_uri (const gchar *str_uri, gboolean add_ghelp) { GnomeVFSURI *uri; gchar *transformed_uri; gchar *docpath = NULL; gchar *extension; + gchar *ret; if (strncmp (str_uri, "ghelp:", 6)) { /* This function is only valid for ghelp-uri's */ - g_warning ("URI not of ghelp: form"); - return NULL; +/* g_warning ("URI not of ghelp: form"); */ + return str_uri; } if ((extension = strstr (str_uri, ".xml"))) { @@ -526,5 +527,28 @@ yelp_util_extract_docpath_from_uri (const gchar *str_uri) } } - return docpath; + if (add_ghelp) { + ret = g_strconcat ("ghelp:", docpath, NULL); + } else { + ret = g_strdup (docpath); + } + + g_free (docpath); + + return ret; +} + +const gchar * +yelp_util_find_anchor_in_uri (const gchar *str_uri) +{ + gchar *anchor; + + if ((anchor = strstr (str_uri, "?"))) { + return g_strdup (anchor + 1); + } + else if ((anchor = strstr (str_uri, "#"))) { + return g_strdup (anchor + 1); + } + + return NULL; } diff --git a/src/yelp-util.h b/src/yelp-util.h index 963d27a8..11f2ac2d 100644 --- a/src/yelp-util.h +++ b/src/yelp-util.h @@ -44,6 +44,8 @@ GNode * yelp_util_find_toplevel (GNode *doc_tree, GNode * yelp_util_find_node_from_uri (GNode *doc_tree, const gchar *uri); -gchar * yelp_util_extract_docpath_from_uri (const gchar *uri); +gchar * yelp_util_extract_docpath_from_uri (const gchar *uri, + gboolean add_ghelp); +const gchar * yelp_util_find_anchor_in_uri (const gchar *str_uri); #endif /* __YELP_UTIL_H__ */ diff --git a/src/yelp-view-content.c b/src/yelp-view-content.c index 2a32deb1..bc19bc3a 100644 --- a/src/yelp-view-content.c +++ b/src/yelp-view-content.c @@ -304,7 +304,7 @@ yelp_view_content_show_uri (YelpViewContent *content, /* ghelp uri-scheme /usr/share/gnome/help... */ gchar *docpath; - docpath = yelp_util_extract_docpath_from_uri (url); + docpath = yelp_util_extract_docpath_from_uri (url, FALSE); if (docpath && strcmp (docpath, priv->current_docpath)) { /* Try to find it in the scrollkeeper database, |