summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Larsson <alexl@redhat.com>2002-01-23 02:51:04 +0000
committerAlexander Larsson <alexl@src.gnome.org>2002-01-23 02:51:04 +0000
commitf8188831bce1418a16ca8fe459299a9555de3b6d (patch)
treef39bde7e1bdcf96a42341f434fa755ad2053e685
parent7c752cd1d16dbc34d8fd773de31e96ff57ca5e2d (diff)
downloadyelp-f8188831bce1418a16ca8fe459299a9555de3b6d.tar.gz
Fix silly bug.
2002-01-22 Alex Larsson <alexl@redhat.com> * src/yelp-man.c (yelp_man_push_initial_tree): Fix silly bug. * src/yelp-util.[ch]: Add functions to go between Nodes in the doc tree and string paths. * src/yelp-view-toc.c: Update man handling to GNodes.
-rw-r--r--ChangeLog12
-rw-r--r--src/yelp-man.c2
-rw-r--r--src/yelp-util.c136
-rw-r--r--src/yelp-util.h20
-rw-r--r--src/yelp-view-toc.c148
5 files changed, 227 insertions, 91 deletions
diff --git a/ChangeLog b/ChangeLog
index a74c30e8..98151bae 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2002-01-22 Alex Larsson <alexl@redhat.com>
+
+ * src/yelp-man.c (yelp_man_push_initial_tree):
+ Fix silly bug.
+
+ * src/yelp-util.[ch]:
+ Add functions to go between Nodes in the doc tree and
+ string paths.
+
+ * src/yelp-view-toc.c:
+ Update man handling to GNodes.
+
2002-01-23 Mikael Hallendal <micke@codefactory.se>
* src/yelp-window.c (yw_history_button_clicked):
diff --git a/src/yelp-man.c b/src/yelp-man.c
index 51acfd6a..9c7d772a 100644
--- a/src/yelp-man.c
+++ b/src/yelp-man.c
@@ -533,7 +533,7 @@ yelp_man_push_initial_tree (struct TreeNode *node, GNode *parent)
page = l->data;
l = l->next;
- g_node_append_data (parent, page);
+ g_node_append_data (man_node, page);
}
}
diff --git a/src/yelp-util.c b/src/yelp-util.c
index 5aa51a7b..26fa8ee5 100644
--- a/src/yelp-util.c
+++ b/src/yelp-util.c
@@ -22,6 +22,7 @@
#include "yelp-util.h"
+#include <libgnomevfs/gnome-vfs-utils.h>
#include <string.h>
GtkTreeIter *
@@ -294,3 +295,138 @@ yelp_util_resolve_relative_uri (const char *base_uri,
return result;
}
+char *
+yelp_util_node_to_string_path (GNode *node)
+{
+ char *str, *t;
+ char *escaped_node_name;
+ YelpSection *section;
+
+ section = node->data;
+ escaped_node_name = gnome_vfs_escape_set (section->name, " \t\n;:%");
+
+ str = escaped_node_name;
+ while (node->parent != NULL) {
+ node = node->parent;
+
+ section = node->data;
+ if (section) {
+ escaped_node_name = gnome_vfs_escape_set (section->name, " \t\n;:%");
+
+ t = g_strconcat (escaped_node_name, ":", str, NULL);
+ g_free (escaped_node_name);
+ g_free (str);
+ str = t;
+ }
+ }
+ return str;
+}
+
+static GNode *
+yelp_util_string_path_to_node_helper (char **path,
+ GNode *node)
+{
+ char *node_name;
+ char *unescaped_pathname;
+ YelpSection *section;
+
+ if (*path == NULL) {
+ return NULL;
+ }
+
+ unescaped_pathname = gnome_vfs_unescape_string (*path, NULL);
+
+ do {
+ section = node->data;
+ node_name = section->name;
+
+ if (strcmp (node_name, unescaped_pathname) == 0) {
+ g_free (unescaped_pathname);
+ path += 1;
+
+ if (*path == NULL) {
+ return node;
+ }
+
+ if (node->children) {
+ return yelp_util_string_path_to_node_helper (path, node->children);
+ } else {
+ return NULL;
+ }
+ }
+
+ } while ((node = node->next) != NULL);
+
+ g_free (unescaped_pathname);
+
+ return NULL;
+}
+
+
+GNode *
+yelp_util_string_path_to_node (const char *string_path,
+ GNode *root)
+{
+ char **path;
+ GNode *node;
+
+ path = g_strsplit (string_path, ":", 0);
+
+ node = yelp_util_string_path_to_node_helper (path, root->children);
+
+ g_strfreev (path);
+
+ return node;
+}
+
+
+GNode *
+yelp_util_decompose_path_url (GNode *root,
+ const char *path_url,
+ char **embedded_url)
+{
+ const char *first_part;
+ const char *second_part;
+ char *path;
+ GNode *res;
+
+ *embedded_url = NULL;
+
+ if (strncmp (path_url, "path:", 5) != 0) {
+ return NULL;
+ }
+
+ 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;
+ } else {
+ path = g_strdup (first_part);
+ }
+
+ res = yelp_util_string_path_to_node (path, root);
+ g_free (path);
+
+ if (second_part) {
+ *embedded_url = g_strdup (second_part);
+ }
+
+ return res;
+}
+
+char *
+yelp_util_compose_path_url (GNode *node,
+ const char *embedded_url)
+{
+ char *path;
+
+ path = yelp_util_node_to_string_path (node);
+
+ if (path == NULL) {
+ return NULL;
+ }
+
+ return g_strconcat ("path:", path, ";", embedded_url, NULL);
+}
+
diff --git a/src/yelp-util.h b/src/yelp-util.h
index 75655471..a23aaa95 100644
--- a/src/yelp-util.h
+++ b/src/yelp-util.h
@@ -27,12 +27,22 @@
#include <gtk/gtktreemodel.h>
#include "yelp-section.h"
-GtkTreeIter * yelp_util_contents_add_section (GtkTreeStore *store,
- GtkTreeIter *parent,
- YelpSection *section);
+GtkTreeIter *yelp_util_contents_add_section (GtkTreeStore *store,
+ GtkTreeIter *parent,
+ YelpSection *section);
+char * yelp_util_resolve_relative_uri (const char *base_uri,
+ const char *uri);
+
+char * yelp_util_node_to_string_path (GNode *node);
+GNode * yelp_util_string_path_to_node (const char *string_path,
+ GNode *root);
+
+GNode * yelp_util_decompose_path_url (GNode *root,
+ const char *path_url,
+ char **embedded_url);
+char * yelp_util_compose_path_url (GNode *node,
+ const char *embedded_url);
-char * yelp_util_resolve_relative_uri (const char *base_uri,
- const char *uri);
#endif /* __YELP_UTIL_H__ */
diff --git a/src/yelp-view-toc.c b/src/yelp-view-toc.c
index f1aaa8a9..261ed81d 100644
--- a/src/yelp-view-toc.c
+++ b/src/yelp-view-toc.c
@@ -33,6 +33,7 @@
#include "yelp-view-toc.h"
#include "yelp-marshal.h"
+#include "yelp-util.h"
#define d(x) x
@@ -303,78 +304,65 @@ yelp_view_toc_find_toplevel (YelpViewTOC *view, gchar *name)
return NULL;
}
-#if 0
static char *
-yelp_view_toc_full_path_name (YelpViewTOC *view, GtkTreeIter *top)
+yelp_view_toc_full_path_name (YelpViewTOC *view, GNode *node)
{
char *str, *t;
-/* gtk_tree_model_get (priv->tree_model, &iter, */
-/* 0, &name, */
-/* -1); */
-
-/* path = gtk_tree_model_get_path (priv->tree_model, &iter); */
-/* path_str = gtk_tree_path_to_string (path); */
-
- GtkTreeIter iter;
- GtkTreeIter next_iter;
+ YelpSection *section;
char *node_name;
- gtk_tree_model_get (view->priv->tree_model, top,
- 0, &str,
- -1);
+ section = node->data;
+ node_name = section->name;
+
+ str = node_name;
- iter = *top;
- while (gtk_tree_model_iter_parent (view->priv->tree_model,
- &iter, &iter)) {
- if (!gtk_tree_model_iter_parent (view->priv->tree_model,
- &next_iter, &iter))
+ while (node->parent) {
+ node = node->parent;
+
+ if (node->parent == NULL) {
+ /* Skip top node */
break;
- gtk_tree_model_get (view->priv->tree_model, &iter,
- 0, &node_name,
- -1);
+ }
+
+ section = node->data;
+ node_name = section->name;
+
t = g_strconcat (node_name, "/", str, NULL);
g_free (str);
- g_free (node_name);
str = t;
}
return str;
}
static void
-yelp_view_toc_man_emit (YelpViewTOC *view, GtkTreeIter *first, int level)
+yelp_view_toc_man_emit (YelpViewTOC *view, GNode *first)
{
YelpViewTOCPriv *priv;
- GtkTreeIter iter, child;
- char level_c;
+ GNode *node, *child;
+ YelpSection *section;
char *name;
- char *path_string;
gboolean got_a_leaf;
- GtkTreePath *path;
+ char *path;
int i;
priv = view->priv;
- level_c = '1' + level;
got_a_leaf = FALSE;
- iter = *first;
+ node = first;
do {
- if (gtk_tree_model_iter_children (view->priv->tree_model,
- &child, &iter)) {
-
- gtk_tree_model_get (priv->tree_model, &iter,
- 0, &name,
- -1);
+ if (node->children != NULL) {
+ child = node->children;
- path = gtk_tree_model_get_path (priv->tree_model, &iter);
- path_string = gtk_tree_path_to_string (path);
- yelp_view_toc_printf (view, "<h2><a href=\"toc:man/%s\">%s</a></h2>\n", path_string, name);
- gtk_tree_path_free (path);
- g_free (path_string);
- g_free (name);
+ section = node->data;
+ name = section->name;
+
+ path = yelp_util_node_to_string_path (node);
+ yelp_view_toc_printf (view, "<h2><a href=\"toc:man/%s\">%s</a></h2>\n", path, name);
+ g_free (path);
} else {
got_a_leaf = TRUE;
}
- } while (gtk_tree_model_iter_next (priv->tree_model, &iter));
+ } while ((node = node->next) != NULL);
if (got_a_leaf) {
@@ -383,27 +371,25 @@ yelp_view_toc_man_emit (YelpViewTOC *view, GtkTreeIter *first, int level)
-1);
i = 0;
- iter = *first;
+ node = first;
do {
- if (i % 3 == 0) {
- if (i == 0) {
- yelp_view_toc_write (view, "<tr>\n", -1);
- } else {
- yelp_view_toc_write (view, "</tr>\n<tr>\n", -1);
+ if (node->children == NULL) {
+ YelpSection *section;
+
+ if (i % 3 == 0) {
+ if (i == 0) {
+ yelp_view_toc_write (view, "<tr>\n", -1);
+ } else {
+ yelp_view_toc_write (view, "</tr>\n<tr>\n", -1);
+ }
}
- }
- if (!gtk_tree_model_iter_has_child (view->priv->tree_model,
- &iter)) {
- YelpSection *section;
- gtk_tree_model_get (priv->tree_model, &iter,
- 0, &name,
- 1, &section, -1);
+ section = node->data;
+ name = section->name;
yelp_view_toc_printf (view, "<td valign=\"Top\"><a href=\"%s\">%s</a></td>\n", section->uri, name);
- g_free (name);
i++;
}
- } while (gtk_tree_model_iter_next (priv->tree_model, &iter));
+ } while ((node = node->next) != NULL);
yelp_view_toc_write (view, "</tr>\n", -1);
yelp_view_toc_write (view, "</tbody></table>\n", -1);
@@ -412,35 +398,30 @@ yelp_view_toc_man_emit (YelpViewTOC *view, GtkTreeIter *first, int level)
static void
yelp_view_toc_man_2 (YelpViewTOC *view,
- GtkTreeIter *root)
+ GNode *root)
{
- GtkTreeIter first;
+ GNode *first;
gchar *name;
- if (!gtk_tree_model_iter_children (view->priv->tree_model,
- &first,
- root)) {
+ if (root->children == NULL) {
return;
}
+
+ first = root->children;
yelp_view_toc_open (view);
yelp_view_toc_write_header (view, "Manual pages");
- /* gtk_tree_model_get (view->priv->tree_model, root,
- 0, &name,
- -1);*/
name = yelp_view_toc_full_path_name (view, root);
yelp_view_toc_printf (view, "<h1>Manual pages for section '%s'</h1>\n", name);
-
g_free (name);
- yelp_view_toc_man_emit (view, &first, 0);
+ yelp_view_toc_man_emit (view, first);
yelp_view_toc_write_footer (view);
yelp_view_toc_close (view);
}
-#endif
static void
yelp_view_toc_man_1 (YelpViewTOC *view)
@@ -448,12 +429,8 @@ yelp_view_toc_man_1 (YelpViewTOC *view)
YelpViewTOCPriv *priv;
GNode *root, *node, *child;
YelpSection *section;
+ char *path;
-/* gchar *name, *path_string; */
-/* GtkTreeIter root, first; */
-/* GtkTreeIter iter, child; */
-/* GtkTreePath *path; */
-
priv = view->priv;
root = yelp_view_toc_find_toplevel (view, "man");
@@ -480,9 +457,11 @@ yelp_view_toc_man_1 (YelpViewTOC *view)
if (child) {
section = (YelpSection *) node->data;
+ path = yelp_util_node_to_string_path (node);
yelp_view_toc_printf (view,
"<a href=\"toc:man/%s\">%s</a><br>\n",
- section->uri, section->name);
+ path, section->name);
+ g_free (path);
}
} while ((node = g_node_next_sibling (node)));
@@ -512,6 +491,7 @@ yelp_view_toc_open_url (YelpViewTOC *view, const char *url)
{
const char *toc_type;
const char *path_string;
+ GNode *node;
g_assert (strncmp (url, "toc:", 4) == 0);
@@ -520,31 +500,29 @@ yelp_view_toc_open_url (YelpViewTOC *view, const char *url)
}
toc_type = url + 4;
+
+ g_print ("toc_type: %s\n", toc_type);
if (*toc_type == 0) {
yelp_view_toc_start (view);
} else if (strncmp (toc_type, "man", 3) == 0) {
path_string = toc_type + 3;
+ g_print ("path_string: %s\n", path_string);
if (path_string[0] == 0) {
yelp_view_toc_man_1 (view);
} else if (path_string[0] == '/') {
/* Calculate where it should go */
- return ;
-#if 0
path_string++;
- path = gtk_tree_path_new_from_string (path_string);
-
- if (gtk_tree_model_get_iter (view->priv->tree_model,
- &iter, path)) {
- yelp_view_toc_man_2 (view, &iter);
+ g_print ("path_string: %s\n", path_string);
+ node = yelp_util_string_path_to_node (path_string,
+ view->priv->doc_tree);
+ if (node) {
+ yelp_view_toc_man_2 (view, node);
} else {
g_warning ("Bad path in toc url %s\n", url);
}
-
- gtk_tree_path_free (path);
-#endif
}
} else {
g_warning ("Unknown toc type %s\n", url);