summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Hallendal <micke@codefactory.se>2002-01-30 11:29:04 +0000
committerMikael Hallendal <hallski@src.gnome.org>2002-01-30 11:29:04 +0000
commita9501ac84610d574824c8010395299a5bc15a59a (patch)
tree165528b977ca38b4084a8c599f014e8663eb7dbc
parent6bd9ea3839e63fef0cd5d34c26e92e35237709ef (diff)
downloadyelp-a9501ac84610d574824c8010395299a5bc15a59a.tar.gz
- if both base_url and url is set call resolve_relative_url to get the
2002-01-30 Mikael Hallendal <micke@codefactory.se> * src/yelp-window.c: (yw_url_selected_cb): - if both base_url and url is set call resolve_relative_url to get the absolute url. - if only one of them is set, use that one. * src/yelp-view-content.c: - moved the scrolled window for the tree into the priv-class. (yvc_tree_selection_changed_cb): emit url-selected signal. (yelp_view_content_show_path): removed, unused. (yelp_view_content_show_uri): - hide the tree if: man, info or xml/sgml document without TOC. - don't reload the tree if it's the same document that's going to be showed again. - Retrieve the ScrollKeeper tree based on fullpath uri to file, relative link stripped. * src/yelp-util.c: (yelp_util_contents_add_section): removed, unused. (yelp_util_resolve_relative_uri): if uri starts with ? just concat the base_uri with the relative link. (tree_find_node): Search a tree to find a node that matches an uri. (yelp_util_find_node_from_uri): traverse the tree to find the node for a certain URI. (yelp_util_extract_docpath_from_uri): added, helper function that takes a URI and calculates an absolute path to the document (without anchors). This is used to find the TOC tree for that document. This function needs some tweaking. * src/yelp-scrollkeeper.[ch] (yelp_scrollkeeper_get_toc_tree): renamed from ..._get_toc_tree_model.
-rw-r--r--ChangeLog36
-rw-r--r--src/yelp-scrollkeeper.c10
-rw-r--r--src/yelp-scrollkeeper.h2
-rw-r--r--src/yelp-util.c135
-rw-r--r--src/yelp-util.h21
-rw-r--r--src/yelp-view-content.c117
-rw-r--r--src/yelp-window.c19
7 files changed, 227 insertions, 113 deletions
diff --git a/ChangeLog b/ChangeLog
index 401fffed..1d81708d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,39 @@
+2002-01-30 Mikael Hallendal <micke@codefactory.se>
+
+ * src/yelp-window.c:
+ (yw_url_selected_cb):
+ - if both base_url and url is set call resolve_relative_url to get
+ the absolute url.
+ - if only one of them is set, use that one.
+
+ * src/yelp-view-content.c:
+ - moved the scrolled window for the tree into the priv-class.
+ (yvc_tree_selection_changed_cb): emit url-selected signal.
+ (yelp_view_content_show_path): removed, unused.
+ (yelp_view_content_show_uri):
+ - hide the tree if: man, info or xml/sgml document without TOC.
+ - don't reload the tree if it's the same document that's going to
+ be showed again.
+ - Retrieve the ScrollKeeper tree based on fullpath uri to file,
+ relative link stripped.
+
+ * src/yelp-util.c:
+ (yelp_util_contents_add_section): removed, unused.
+ (yelp_util_resolve_relative_uri): if uri starts with ? just concat
+ the base_uri with the relative link.
+ (tree_find_node): Search a tree to find a node that matches an
+ uri.
+ (yelp_util_find_node_from_uri): traverse the tree to find the node
+ for a certain URI.
+ (yelp_util_extract_docpath_from_uri): added, helper function that
+ takes a URI and calculates an absolute path to the document
+ (without anchors). This is used to find the TOC tree for that
+ document. This function needs some tweaking.
+
+ * src/yelp-scrollkeeper.[ch]
+ (yelp_scrollkeeper_get_toc_tree): renamed from
+ ..._get_toc_tree_model.
+
2002-01-29 Seth Nickell <snickell@stanford.edu>
* yelp.desktop.in:
diff --git a/src/yelp-scrollkeeper.c b/src/yelp-scrollkeeper.c
index ca66b9d5..d056aba3 100644
--- a/src/yelp-scrollkeeper.c
+++ b/src/yelp-scrollkeeper.c
@@ -242,10 +242,6 @@ ys_parse_doc (GNode *parent, xmlNode *xml_node)
g_hash_table_insert (seriesid_hash, docseriesid, node);
}
-#if 0
- ys_parse_toc (NULL, NULL, docsource);
-#endif
-
/* index_location = ys_get_xml_docpath ("scrollkeeper-get-index-from-docpath", */
/* docsource); */
@@ -417,7 +413,7 @@ yelp_scrollkeeper_lookup_seriesid (const gchar *seriesid)
}
GNode *
-yelp_scrollkeeper_get_toc_tree_model (const gchar *docpath)
+yelp_scrollkeeper_get_toc_tree (const gchar *docpath)
{
gchar *toc_file;
xmlDoc *doc = NULL;
@@ -427,8 +423,6 @@ yelp_scrollkeeper_get_toc_tree_model (const gchar *docpath)
g_return_val_if_fail (docpath != NULL, NULL);
- g_print ("Trying to get tree for: %s\n", docpath);
-
tree = g_node_new (NULL);
toc_file = ys_get_xml_docpath ("scrollkeeper-get-toc-from-docpath",
@@ -440,7 +434,7 @@ yelp_scrollkeeper_get_toc_tree_model (const gchar *docpath)
}
if (!doc) {
-/* g_warning ("Tried to parse a non-valid TOC file"); */
+ /* g_warning ("Tried to parse a non-valid TOC file"); */
return NULL;
}
diff --git a/src/yelp-scrollkeeper.h b/src/yelp-scrollkeeper.h
index 53e99b85..176f82ab 100644
--- a/src/yelp-scrollkeeper.h
+++ b/src/yelp-scrollkeeper.h
@@ -29,6 +29,6 @@
gboolean yelp_scrollkeeper_init (GNode *tree);
GNode * yelp_scrollkeeper_lookup_seriesid (const gchar *seriesid);
-GNode * yelp_scrollkeeper_get_toc_tree_model (const gchar *docpath);
+GNode * yelp_scrollkeeper_get_toc_tree (const gchar *docpath);
#endif /* __YELP_SCROLLKEEPER_H__ */
diff --git a/src/yelp-util.c b/src/yelp-util.c
index ddab5b4b..ecd7f9a6 100644
--- a/src/yelp-util.c
+++ b/src/yelp-util.c
@@ -22,31 +22,9 @@
#include "yelp-util.h"
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
-GtkTreeIter *
-yelp_util_contents_add_section (GtkTreeStore *store,
- GtkTreeIter *parent,
- YelpSection *section)
-{
- GtkTreeIter *iter;
-
- g_return_val_if_fail (GTK_IS_TREE_STORE (store), NULL);
- g_return_val_if_fail (section != NULL, NULL);
-
- iter = g_new0 (GtkTreeIter, 1);
-
- gtk_tree_store_append (store, iter, parent);
-
- gtk_tree_store_set (store, iter,
- 0, section->name,
- 1, section,
- 2, TRUE,
- -1);
- return iter;
-}
-
/* This code comes from gnome vfs: */
@@ -173,7 +151,10 @@ yelp_util_resolve_relative_uri (const char *base_uri,
* functionality differs from what Mozilla itself would do.
*/
- if (is_uri_relative (uri)) {
+ if (uri[0] == '?') {
+ result = g_strconcat (base_uri, uri, NULL);
+ }
+ else if (is_uri_relative (uri)) {
char *mutable_base_uri;
char *mutable_uri;
@@ -383,14 +364,14 @@ yelp_util_string_path_to_node (const char *string_path,
GNode *
-yelp_util_decompose_path_url (GNode *root,
- const char *path_url,
- char **embedded_url)
+yelp_util_decompose_path_url (GNode *root,
+ const char *path_url,
+ gchar **embedded_url)
{
- const char *first_part;
- const char *second_part;
- char *path;
- GNode *res;
+ const gchar *first_part;
+ const gchar *second_part;
+ gchar *path;
+ GNode *res;
*embedded_url = NULL;
@@ -400,6 +381,7 @@ yelp_util_decompose_path_url (GNode *root,
first_part = path_url + 5;
second_part = strchr(first_part, ';');
+
if (second_part) {
path = g_strndup (first_part, second_part - first_part);
second_part += 1;
@@ -454,9 +436,98 @@ yelp_util_find_toplevel (GNode *doc_tree,
return NULL;
}
+static GNode *found_node;
+
+static gboolean
+tree_find_node (GNode *node, const gchar *uri)
+{
+ YelpSection *section;
+
+ section = (YelpSection *) node->data;
+
+ if (!section || !section->uri) {
+ return FALSE;
+ }
+
+ if (!g_ascii_strcasecmp (uri, section->uri)) {
+ g_print (">>>>>>>>>>>>>>>> FOUND A MATCH: %s == %s\n",
+ uri, section->uri);
+
+ found_node = node;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
GNode *
yelp_util_find_node_from_uri (GNode *doc_tree, const gchar *uri)
{
- return NULL;
+ found_node = NULL;
+
+ g_node_traverse (doc_tree, G_IN_ORDER,
+ G_TRAVERSE_ALL,
+ -1,
+ (GNodeTraverseFunc) tree_find_node,
+ (gchar *) uri);
+
+ return found_node;
+}
+
+gchar *
+yelp_util_extract_docpath_from_uri (const gchar *str_uri)
+{
+ GnomeVFSURI *uri;
+ gchar *transformed_uri;
+ gchar *docpath = NULL;
+ gchar *extension;
+
+ if (strncmp (str_uri, "ghelp:", 6)) {
+ /* This function is only valid for ghelp-uri's */
+ g_warning ("URI not of ghelp: form");
+ return NULL;
+ }
+
+ docpath = str_uri + 6;
+
+ if ((extension = strstr (str_uri, ".xml"))) {
+ /* This means we have a ghelp-uri with full path */
+ docpath = g_strndup (docpath, extension + 4 - docpath);
+ } else {
+ /* URI not a fullpath URI, let the GnomeVFS help module
+ calculate the full URI */
+ uri = gnome_vfs_uri_new (str_uri);
+
+ if (uri) {
+ transformed_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_NONE);
+
+ if (!strncmp (transformed_uri, "file://", 7)) {
+ docpath = g_strdup (transformed_uri + 7);
+ }
+ else if (!strncmp (transformed_uri, "pipe:", 5)) {
+ gchar *start, *end;
+ gchar *escaped_string;
+
+ /* pipe:gnome2-db2html%20'%2Fusr%2Fshare%2Fgnome%2Fhelp%2Fgaleon-manual%2FC%2Fgaleon-manual.sgml'%3Bmime-type%3Dtext%2Fhtml */
+
+ start = strchr (transformed_uri, '\'') + 1;
+ end = strrchr (transformed_uri, '\'');
+
+ escaped_string = g_strndup (start,
+ end - start);
+
+ docpath = gnome_vfs_unescape_string (escaped_string,
+ NULL);
+ }
+ }
+ }
+
+ if (docpath) {
+ g_print ("||||| docpath: %s\n", docpath);
+ } else {
+ g_print ("----- transformed_uri: %s\n", transformed_uri);
+ }
+
+ return docpath;
}
diff --git a/src/yelp-util.h b/src/yelp-util.h
index e9482168..ca259b5b 100644
--- a/src/yelp-util.h
+++ b/src/yelp-util.h
@@ -23,30 +23,27 @@
#ifndef __YELP_UTIL_H__
#define __YELP_UTIL_H__
-#include <gtk/gtktreestore.h>
-#include <gtk/gtktreemodel.h>
#include "yelp-section.h"
-GtkTreeIter *yelp_util_contents_add_section (GtkTreeStore *store,
- GtkTreeIter *parent,
- YelpSection *section);
-gchar * yelp_util_resolve_relative_uri (const gchar *base_uri,
+gchar * yelp_util_resolve_relative_uri (const gchar *base_uri,
const gchar *uri);
-gchar * yelp_util_node_to_string_path (GNode *node);
-GNode * yelp_util_string_path_to_node (const gchar *string_path,
+gchar * yelp_util_node_to_string_path (GNode *node);
+GNode * yelp_util_string_path_to_node (const gchar *string_path,
GNode *root);
-GNode * yelp_util_decompose_path_url (GNode *root,
+GNode * yelp_util_decompose_path_url (GNode *root,
const gchar *path_url,
char **embedded_url);
-gchar * yelp_util_compose_path_url (GNode *node,
+gchar * yelp_util_compose_path_url (GNode *node,
const gchar *embedded_url);
-GNode * yelp_util_find_toplevel (GNode *doc_tree,
+GNode * yelp_util_find_toplevel (GNode *doc_tree,
gchar *name);
-GNode * yelp_util_find_node_from_uri (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);
+
#endif /* __YELP_UTIL_H__ */
diff --git a/src/yelp-view-content.c b/src/yelp-view-content.c
index 16a202b8..c0313f55 100644
--- a/src/yelp-view-content.c
+++ b/src/yelp-view-content.c
@@ -38,7 +38,6 @@ static void yvc_class_init (YelpViewContentClass *klass);
static void yvc_tree_selection_changed_cb (GtkTreeSelection *selection,
YelpViewContent *content);
-
enum {
URL_SELECTED,
TITLE_CHANGED,
@@ -49,12 +48,15 @@ static gint signals[LAST_SIGNAL] = { 0 };
struct _YelpViewContentPriv {
/* Content tree */
+ GtkWidget *tree_sw;
GtkWidget *content_tree;
GtkTreeStore *tree_store;
GNode *doc_tree;
/* Html view */
GtkWidget *html_view;
+
+ gchar *current_docpath;
};
GType
@@ -94,6 +96,8 @@ yvc_html_url_selected_cb (YelpHtml *html,
YelpViewContent *view)
{
/* Just propagate the signal to the view */
+ g_print ("***** URI Clicked: %s, %s\n", base_url, url);
+
g_signal_emit (view, signals[URL_SELECTED], 0,
url, base_url, handled);
}
@@ -115,8 +119,9 @@ yvc_init (YelpViewContent *view)
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->content_tree),
GTK_TREE_MODEL (priv->tree_store));
- priv->html_view = yelp_html_new ();
-
+ priv->html_view = yelp_html_new ();
+ priv->current_docpath = g_strdup ("");
+
g_signal_connect (priv->html_view, "url_selected",
G_CALLBACK (yvc_html_url_selected_cb),
view);
@@ -169,11 +174,10 @@ yvc_tree_selection_changed_cb (GtkTreeSelection *selection,
1, &section,
-1);
- yelp_html_open_section (YELP_HTML (priv->html_view), section);
+/* yelp_html_open_section (YELP_HTML (priv->html_view), section); */
+ g_signal_emit (content, signals[URL_SELECTED], 0,
+ section->reference, section->uri, FALSE);
}
-
- /* FIXME: Emit section_selected?? */
-/* yelp_history_goto (priv->history, section); */
}
GtkWidget *
@@ -183,7 +187,6 @@ yelp_view_content_new (GNode *doc_tree)
YelpViewContentPriv *priv;
GtkTreeSelection *selection;
GtkWidget *html_sw;
- GtkWidget *tree_sw;
GtkWidget *frame;
view = g_object_new (YELP_TYPE_VIEW_CONTENT, NULL);
@@ -192,8 +195,8 @@ yelp_view_content_new (GNode *doc_tree)
priv->doc_tree = doc_tree;
/* Setup the content tree */
- tree_sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (tree_sw),
+ priv->tree_sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->tree_sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
@@ -210,7 +213,7 @@ yelp_view_content_new (GNode *doc_tree)
G_CALLBACK (yvc_tree_selection_changed_cb),
view);
- gtk_container_add (GTK_CONTAINER (tree_sw), priv->content_tree);
+ gtk_container_add (GTK_CONTAINER (priv->tree_sw), priv->content_tree);
/* Setup the Html view */
html_sw = gtk_scrolled_window_new (NULL, NULL);
@@ -224,33 +227,13 @@ yelp_view_content_new (GNode *doc_tree)
gtk_container_add (GTK_CONTAINER (html_sw), priv->html_view);
/* Add the tree and html view to the paned */
- gtk_paned_add1 (GTK_PANED (view), tree_sw);
+ gtk_paned_add1 (GTK_PANED (view), priv->tree_sw);
gtk_paned_add2 (GTK_PANED (view), frame);
gtk_paned_set_position (GTK_PANED (view), 250);
return GTK_WIDGET (view);
}
-#if 0
-void
-yelp_view_content_show_path (YelpViewContent *content_view,
- GtkTreePath *path)
-{
- YelpViewContentPriv *priv;
- GtkTreeModel *model;
-
- g_return_if_fail (YELP_IS_VIEW_CONTENT (content_view));
-
- priv = content_view->priv;
-
- model = gtk_tree_model_filter_new_with_model (priv->tree_model,
- 2, path);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (priv->content_tree), model);
-
-}
-#endif
-
static void
yelp_view_content_insert_tree (YelpViewContent *content,
GtkTreeIter *parent,
@@ -271,6 +254,7 @@ yelp_view_content_insert_tree (YelpViewContent *content,
-1);
child = node->children;
+
while (child) {
yelp_view_content_insert_tree (content, &iter, child);
@@ -282,11 +266,15 @@ static void
yelp_view_content_set_tree (YelpViewContent *content,
GNode *node)
{
- GNode *child;
-
+ GNode *child;
+
+ g_return_if_fail (YELP_IS_VIEW_CONTENT (content));
+ g_return_if_fail (node != NULL);
+
gtk_tree_store_clear (content->priv->tree_store);
child = node->children;
+
while (child) {
yelp_view_content_insert_tree (content, NULL, child);
child = child->next;
@@ -300,44 +288,65 @@ yelp_view_content_show_uri (YelpViewContent *content,
YelpViewContentPriv *priv;
YelpSection *section;
gchar *content_url;
- gchar *title = NULL;
GNode *node;
g_return_if_fail (YELP_IS_VIEW_CONTENT (content));
-
- priv = content->priv;
+ g_return_if_fail (url != NULL);
+ priv = content->priv;
+
if (strncmp (url, "path:", 5) == 0) {
node = yelp_util_decompose_path_url (priv->doc_tree,
url,
&content_url);
- title = ((YelpSection *) node->data)->name;
-
yelp_view_content_set_tree (content, node);
+
+ if (!strncmp (content_url, "info:", 5) ||
+ !strncmp (content_url, "man:", 4)) {
+ gtk_widget_hide (priv->tree_sw);
+ }
+ else {
+ gtk_widget_show (priv->tree_sw);
+ }
} else if (strncmp (url, "ghelp:", 6) == 0) {
- const gchar *docpath;
- GNode *doc_node;
+ /* ghelp uri-scheme /usr/share/gnome/help... */
+ gchar *docpath;
- docpath = url + 6;
+ docpath = yelp_util_extract_docpath_from_uri (url);
+
+ if (docpath && strcmp (docpath, priv->current_docpath)) {
+ /* Try to find it in the scrollkeeper database,
+ doesn't have to exist here */
+ node = yelp_scrollkeeper_get_toc_tree (docpath);
+
+ if (node) {
+ yelp_view_content_set_tree (content, node);
+
+ gtk_widget_show (priv->tree_sw);
+ } else {
+ gtk_widget_hide (priv->tree_sw);
+ }
+
+ g_free (priv->current_docpath);
+ priv->current_docpath = g_strdup (docpath);
+ }
- node = yelp_scrollkeeper_get_toc_tree_model (docpath);
+ g_free (docpath);
+
+ content_url = (char *) url;
+ } else if (!strncmp (url, "info:", 5) || !strncmp (url, "man:", 4)) {
+ node = yelp_util_find_node_from_uri (priv->doc_tree, url);
- doc_node = yelp_util_find_node_from_uri (priv->doc_tree,
- url);
+ gtk_widget_hide (priv->tree_sw);
- if (node) {
- yelp_view_content_set_tree (content, node);
+ if (node && node->parent) {
+ /* yelp_view_content_set_tree (content, node->parent); */
}
-
- content_url = (char *)url;
- } else {
- }
- if (title) {
- g_signal_emit (content, signals[TITLE_CHANGED], 0, title);
+ content_url = (char *) url;
}
-
+
/* FIXME: This is a quite dubious way to load the url... */
section = yelp_section_new (YELP_SECTION_DOCUMENT,
NULL, content_url, NULL, NULL);
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 6dcf1f8b..000c8576 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -277,7 +277,7 @@ yw_url_selected_cb (gpointer view,
YelpWindow *window)
{
YelpWindowPriv *priv;
- gchar *abs_url;
+ gchar *abs_url = NULL;
g_return_if_fail (YELP_IS_WINDOW (window));
@@ -285,18 +285,25 @@ yw_url_selected_cb (gpointer view,
priv = window->priv;
- if (base_url) {
+ if (url && base_url) {
abs_url = yelp_util_resolve_relative_uri (base_url, url);
g_print ("Link '%s' pressed relative to: %s -> %s\n",
url,
base_url,
abs_url);
} else {
- abs_url = g_strdup (url);
+ if (url) {
+ abs_url = g_strdup (url);
+ }
+ else if (base_url) {
+ abs_url = g_strdup (base_url);
+ }
}
- if (!handled) {
- if (yw_handle_url (window, url)) {
+ if (handled) {
+ yelp_history_goto (priv->history, abs_url);
+ } else {
+ if (yw_handle_url (window, abs_url)) {
yelp_history_goto (priv->history, abs_url);
}
}
@@ -398,7 +405,7 @@ yw_about_cb (gpointer data, guint section, GtkWidget *widget)
};
about = gnome_about_new (PACKAGE, VERSION,
- "(C) 2001 Mikael Hallendal <micke@codefactory.se>",
+ "(C) 2001-2002 Mikael Hallendal <micke@codefactory.se>",
_("Help Browser for GNOME 2.0"),
authors,
NULL,