summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Hallendal <micke@codefactory.se>2002-04-14 11:49:50 +0000
committerMikael Hallendal <hallski@src.gnome.org>2002-04-14 11:49:50 +0000
commit88af72c87538c5a34d194becf69bfea9d8e0a728 (patch)
treefe444bd0a16db44ff14d97fc382f45d7f76ead07
parented0db98e29643e3ddd0a80133b95e6fe20d949cd (diff)
downloadyelp-88af72c87538c5a34d194becf69bfea9d8e0a728.tar.gz
added includes to fix warnings.
2002-04-14 Mikael Hallendal <micke@codefactory.se> * src/yelp-view-content.c: added includes to fix warnings. * src/yelp-view-index.c: same. * src/yelp-util.c (yelp_util_extract_docpath_from_uri): - added support for man and info pages too. * src/yelp-html.c: - loads of changes :) - don't use GnomeVFS Async calls. - Read non-docbook data in an idle - Shortcut the gnome vfs help module and call internal docbook2html code instead if document is xml/sgml docbook. - Needs more cleaning up and breaking out into another file/class. - Don't inherit HtmlView, instead inherit GObject and have a get_widget function. * src/yelp-db2html.[ch]: added from libgnome. Use this in-proc instead of calling as external scripts. * src/Makefile.am (yelp_SOURCES): added yelp-db2html.[ch] * configure.in (GNOMELOCALEDIR): depend on libxslt for the docbook->html conversion.
-rw-r--r--ChangeLog27
-rw-r--r--configure.in1
-rw-r--r--src/Makefile.am2
-rw-r--r--src/yelp-db2html.c161
-rw-r--r--src/yelp-db2html.h39
-rw-r--r--src/yelp-html.c423
-rw-r--r--src/yelp-html.h15
-rw-r--r--src/yelp-util.c11
-rw-r--r--src/yelp-view-content.c17
-rw-r--r--src/yelp-view-index.c15
-rw-r--r--src/yelp-window.c4
11 files changed, 474 insertions, 241 deletions
diff --git a/ChangeLog b/ChangeLog
index faa49ea4..ed597ec5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,30 @@
+2002-04-14 Mikael Hallendal <micke@codefactory.se>
+
+ * src/yelp-view-content.c: added includes to fix warnings.
+
+ * src/yelp-view-index.c: same.
+
+ * src/yelp-util.c (yelp_util_extract_docpath_from_uri):
+ - added support for man and info pages too.
+
+ * src/yelp-html.c:
+ - loads of changes :)
+ - don't use GnomeVFS Async calls.
+ - Read non-docbook data in an idle
+ - Shortcut the gnome vfs help module and call internal
+ docbook2html code instead if document is xml/sgml docbook.
+ - Needs more cleaning up and breaking out into another file/class.
+ - Don't inherit HtmlView, instead inherit GObject and have a
+ get_widget function.
+
+ * src/yelp-db2html.[ch]: added from libgnome. Use this in-proc
+ instead of calling as external scripts.
+
+ * src/Makefile.am (yelp_SOURCES): added yelp-db2html.[ch]
+
+ * configure.in (GNOMELOCALEDIR): depend on libxslt for the
+ docbook->html conversion.
+
2002-04-12 Mikael Hallendal <micke@codefactory.se>
* src/yelp-view-toc.c (TOC_BLOCK_SEPARATOR): fixed string, thanks
diff --git a/configure.in b/configure.in
index 0a23796b..f9b1047e 100644
--- a/configure.in
+++ b/configure.in
@@ -43,6 +43,7 @@ PKG_CHECK_MODULES(YELP, libgtkhtml-2.0 >= 1.99.3 \
libgnome-2.0 >= 1.112.1 \
libgnomeui-2.0 >= 1.103.0 \
libbonobo-2.0 >= 1.108.0 \
+ libxslt >= 1.0.15 \
gconf-2.0)
AC_SUBST(YELP_CFLAGS)
diff --git a/src/Makefile.am b/src/Makefile.am
index c3df17a8..22272512 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ yelp_SOURCES = \
$(gnome_yelp_idl_sources) \
yelp-marshal.c yelp-marshal.h \
yelp-base.c yelp-base.h \
+ yelp-db2html.c yelp-db2html.h \
yelp-history.c yelp-history.h \
yelp-html.c yelp-html.h \
yelp-index-model.c yelp-index-model.h \
@@ -43,6 +44,7 @@ yelp_SOURCES = \
yelp-view-toc.c yelp-view-toc.h \
yelp-window.c yelp-window.h
+
yelp_LDADD = \
$(YELP_LIBS)
diff --git a/src/yelp-db2html.c b/src/yelp-db2html.c
new file mode 100644
index 00000000..83239577
--- /dev/null
+++ b/src/yelp-db2html.c
@@ -0,0 +1,161 @@
+/*
+ * gnome-db2html3 - by John Fleck - based on Daniel Veillard's
+ * xsltproc: user program for the XSL Transformation engine
+ *
+ * Copyright (C) John Fleck, 2001
+ * Copyright (C) Mikael Hallendal, 2002
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <config.h>
+#include <glib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <libxml/xmlversion.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/debugXML.h>
+#include <libxml/HTMLtree.h>
+#include <libxml/DOCBparser.h>
+#include <libxml/catalog.h>
+#include <libxslt/xsltconfig.h>
+#include <libxslt/xslt.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+
+#include "yelp-db2html.h"
+
+#define d(x)
+
+gboolean
+yelp_db2html_convert (const gchar *document,
+ xmlOutputBufferPtr buf,
+ GError **error)
+{
+ static xsltStylesheetPtr gdb_xslreturn = NULL;
+ char *gdb_docname;
+ xmlDocPtr gdb_doc, gdb_results;
+ const char *params[16 + 1];
+ char *gdb_pathname; /* path to the file to be parsed */
+ char *gdb_rootid; /* id of sect, chapt, etc to be parsed */
+ static char *gdb_stylesheet; /* stylesheet to be used */
+ char **gdb_split_docname; /* placeholder for file type determination */
+ char *ptr;
+ gboolean has_rootid;
+ GTimer *timer;
+
+ has_rootid = FALSE;
+ gdb_doc = NULL;
+ gdb_rootid = NULL;
+
+ timer = g_timer_new ();
+
+ gdb_docname = g_strdup (document);
+
+ d(g_print ("Convert file: %s\n", gdb_docname));
+
+ /* stylesheet location based on Linux Standard Base *
+ * http://www.linuxbase.org/spec/gLSB/gLSB/sgmlr002.html */
+ gdb_stylesheet = g_strconcat (PREFIX "/share/sgml/docbook/gnome-customization-0.1/gnome-customization.xsl", NULL);
+
+ /* check to see if gdb_docname has a ?sectid included */
+ for (ptr = gdb_docname; *ptr; ptr++){
+ if (*ptr == '?') {
+ *ptr = '\000';
+ if (*(ptr + 1)) {
+ gdb_rootid = ptr;
+ has_rootid = TRUE;
+ }
+ }
+ }
+
+ /* libxml housekeeping */
+ xmlSubstituteEntitiesDefault(1);
+
+ /* parse the stylesheet */
+ if (!gdb_xslreturn) {
+ gdb_xslreturn = xsltParseStylesheetFile ((const xmlChar *)gdb_stylesheet);
+ }
+
+ if (!gdb_xslreturn) {
+ /* FIXME: Set GError */
+ return FALSE;
+ }
+
+ /* check the file type by looking at name
+ * FIXME - we need to be more sophisticated about this
+ * then parse as either xml or sgml */
+ gdb_split_docname = g_strsplit(gdb_docname, ".", 2);
+ if (!strcmp(gdb_split_docname[1], "sgml")) {
+ gdb_doc = docbParseFile(gdb_docname, "UTF-8");
+ } else {
+ (gdb_doc = xmlParseFile(gdb_docname));
+ }
+
+ if (gdb_doc == NULL) {
+ /* FIXME: Set something in the GError */
+ g_free (gdb_docname);
+
+ return FALSE;
+ }
+
+ /* retrieve path component of filename passed in at
+ command line */
+ gdb_pathname = g_path_get_dirname (gdb_doc->URL);
+ gdb_docname = g_path_get_basename (gdb_doc->URL);
+
+ for (ptr = gdb_docname; *ptr; ptr++){
+ if (*ptr == '.') {
+ *ptr = '\000';
+
+ }
+ }
+
+ /* set params to be passed to stylesheet */
+ params[0] = "gdb_docname";
+ params[1] = g_strconcat("\"", gdb_doc->URL, "\"", NULL) ;
+ params[2] = "gdb_pathname";
+ params[3] = g_strconcat("\"", gdb_pathname, "\"", NULL) ;
+ params[4] = NULL;
+
+ if (has_rootid) {
+/* params[4] = "rootid"; */
+ params[4] = "gdb_rootid";
+ params[5] = g_strconcat("\"", gdb_rootid + 1, "\"", NULL) ;
+ params[6] = NULL;
+ }
+
+ gdb_results = xsltApplyStylesheet(gdb_xslreturn, gdb_doc, params);
+
+ if (!gdb_results) {
+ /* FIXME: Set GError */
+ return FALSE;
+ }
+
+ /* Output the results to the OutputBuffer */
+ xsltSaveResultTo (buf, gdb_results, gdb_xslreturn);
+
+ xmlOutputBufferClose (buf);
+
+ g_free (gdb_docname);
+ xmlFree (gdb_results);
+
+ d(g_print ("docbook -> html took: %f s\n", g_timer_elapsed (timer, 0)));
+ return TRUE;
+}
diff --git a/src/yelp-db2html.h b/src/yelp-db2html.h
new file mode 100644
index 00000000..9f063547
--- /dev/null
+++ b/src/yelp-db2html.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002 Mikael Hallendal <micke@codefactory.se>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Mikael Hallendal <micke@codefactory.se>
+ */
+
+#ifndef __YELP_DB2HTML_H__
+#define __YELP_DB2HTML_H__
+
+#include <glib.h>
+#include <libxml/xmlversion.h>
+#include <libxml/xmlmemory.h>
+#include <libxml/debugXML.h>
+#include <libxml/HTMLtree.h>
+#include <libxml/DOCBparser.h>
+#include <libxml/catalog.h>
+
+gboolean
+yelp_db2html_convert (const gchar *document,
+ xmlOutputBufferPtr buf,
+ GError **error);
+
+#endif /* __YELP_DB2HTML_H__ */
diff --git a/src/yelp-html.c b/src/yelp-html.c
index 682296b9..2b16cdfb 100644
--- a/src/yelp-html.c
+++ b/src/yelp-html.c
@@ -25,13 +25,16 @@
#endif
#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnome/gnome-i18n.h>
+#include <libgtkhtml/gtkhtml.h>
#include <string.h>
#include <stdio.h>
#include "yelp-util.h"
#include "yelp-marshal.h"
+#include "yelp-db2html.h"
#include "yelp-html.h"
#define d(x)
@@ -40,23 +43,9 @@ typedef struct _StreamData StreamData;
static void yh_init (YelpHtml *html);
static void yh_class_init (YelpHtmlClass *klass);
-static void yh_async_open_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data);
-static void yh_async_read_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer buffer,
- GnomeVFSFileSize bytes_requested,
- GnomeVFSFileSize bytes_read,
- gpointer callback_data);
-static void yh_async_close_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data);
static void yh_link_clicked_cb (HtmlDocument *doc,
const gchar *url,
YelpHtml *html);
-static void yh_free_stream_data (StreamData *sdata,
- gboolean remove);
static void yh_stream_cancel (HtmlStream *stream,
gpointer user_data,
gpointer cancel_data);
@@ -76,18 +65,21 @@ static gint signals[LAST_SIGNAL] = { 0 };
static GHashTable *cache_table = NULL;
struct _YelpHtmlPriv {
+ HtmlView *view;
+
HtmlDocument *doc;
HtmlDocument *load_doc;
GSList *connections;
gchar *base_uri;
};
-struct _StreamData {
- YelpHtml *view;
- HtmlStream *stream;
- GnomeVFSAsyncHandle *handle;
- gchar *anchor;
-};
+typedef struct {
+ YelpHtml *html;
+ gchar *buffer;
+ GnomeVFSHandle *handle;
+ HtmlStream *stream;
+ gboolean is_doc;
+} ReadData;
GType
yelp_html_get_type (void)
@@ -109,7 +101,7 @@ yelp_html_get_type (void)
(GInstanceInitFunc) yh_init,
};
- view_type = g_type_register_static (HTML_TYPE_VIEW,
+ view_type = g_type_register_static (G_TYPE_OBJECT,
"YelpHtml",
&view_info, 0);
}
@@ -118,12 +110,13 @@ yelp_html_get_type (void)
}
static void
-yh_init (YelpHtml *view)
+yh_init (YelpHtml *html)
{
YelpHtmlPriv *priv;
priv = g_new0 (YelpHtmlPriv, 1);
+ priv->view = HTML_VIEW (html_view_new ());
priv->doc = html_document_new ();
priv->connections = NULL;
priv->base_uri = g_strdup ("");
@@ -143,15 +136,15 @@ yh_init (YelpHtml *view)
html_document_close_stream (priv->load_doc);
- html_view_set_document (HTML_VIEW (view), priv->doc);
+ html_view_set_document (HTML_VIEW (priv->view), priv->doc);
g_signal_connect (G_OBJECT (priv->doc), "link_clicked",
- G_CALLBACK (yh_link_clicked_cb), view);
+ G_CALLBACK (yh_link_clicked_cb), html);
g_signal_connect (G_OBJECT (priv->doc), "request_url",
- G_CALLBACK (yh_url_requested_cb), view);
+ G_CALLBACK (yh_url_requested_cb), html);
- view->priv = priv;
+ html->priv = priv;
}
static void
@@ -173,92 +166,156 @@ yh_class_init (YelpHtmlClass *klass)
}
}
-
-static void
-yh_async_close_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data)
+static int
+yelp_html_do_write (void * context, const char * buffer, int len)
{
- StreamData *sdata;
+ YelpHtml *html;
YelpHtmlPriv *priv;
- d(puts(G_GNUC_FUNCTION));
-
- sdata = (StreamData *) callback_data;
- priv = sdata->view->priv;
+ g_return_val_if_fail (YELP_IS_HTML (context), -1);
- if (sdata->anchor) {
- html_view_jump_to_anchor (HTML_VIEW (sdata->view),
- sdata->anchor);
- }
+ html = YELP_HTML (context);
+ priv = html->priv;
- yh_free_stream_data (sdata, TRUE);
+ if (len <= 0) {
+ return 0;
+ }
+
+ d(g_print ("Do Write: %d\n", len));
+
+ html_document_write_stream (priv->doc, buffer, len);
+
+ return len;
}
-static void
-yh_async_read_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer buffer,
- GnomeVFSFileSize bytes_requested,
- GnomeVFSFileSize bytes_read,
- gpointer callback_data)
+static int
+yelp_html_do_close (void *context)
{
- StreamData *sdata;
- YelpHtml *view;
+ YelpHtml *html;
YelpHtmlPriv *priv;
- d(puts(G_GNUC_FUNCTION));
+ g_return_val_if_fail (YELP_IS_HTML (context), -1);
+
+ html = YELP_HTML (context);
+ priv = html->priv;
- sdata = (StreamData *) callback_data;
- view = sdata->view;
- priv = view->priv;
+ d(g_print ("Do Close\n"));
- if (result != GNOME_VFS_OK) {
- gnome_vfs_async_close (handle,
- yh_async_close_cb,
- sdata);
+ html_document_close_stream (priv->doc);
+ gtk_adjustment_set_value (gtk_layout_get_vadjustment (GTK_LAYOUT (priv->view)),
+ 0);
+ return 0;
+}
- g_free (buffer);
- } else {
- html_stream_write (sdata->stream, buffer, bytes_read);
+static void
+yelp_html_do_docbook (YelpHtml *html, const gchar *uri)
+{
+ xmlOutputBufferPtr buf;
+ YelpHtmlPriv *priv;
+
+ g_return_if_fail (YELP_IS_HTML (html));
+
+ priv = html->priv;
+
+ buf = xmlAllocOutputBuffer (NULL);
+
+ buf->writecallback = yelp_html_do_write;
+ buf->closecallback = yelp_html_do_close;
+ buf->context = html;
+
+ yelp_db2html_convert (uri, buf, NULL);
+}
+
+static gboolean
+yelp_html_idle_read (gpointer data)
+{
+ ReadData *read_data = (ReadData *)data;
+ GnomeVFSFileSize read_len;
+ GnomeVFSResult result;
+
+ result = gnome_vfs_read (read_data->handle,
+ read_data->buffer,
+ BUFFER_SIZE,
+ &read_len);
- if (HTML_VIEW(view)->document == view->priv->load_doc) {
- html_view_set_document (HTML_VIEW (view),
- view->priv->doc);
- }
+ if (result == GNOME_VFS_OK) {
+ g_print ("-> ");
- gnome_vfs_async_read (handle, buffer, bytes_requested,
- yh_async_read_cb, sdata);
+ yelp_html_do_write (read_data->html,
+ read_data->buffer,
+ read_len);
+ } else {
+ return FALSE;
}
+
+ return TRUE;
}
static void
-yh_async_open_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- gpointer callback_data)
+yelp_html_idle_read_end (gpointer data)
{
- StreamData *sdata;
- YelpHtmlPriv *priv;
-
- d(puts(G_GNUC_FUNCTION));
+ ReadData *read_data = (ReadData *)data;
+ YelpHtml *html;
+ YelpHtmlPriv *priv;
+
+ html = read_data->html;
+ priv = html->priv;
+
+ gnome_vfs_close (read_data->handle);
+ gnome_vfs_handle_destroy (read_data->handle);
+
+ html_stream_close (read_data->stream);
- sdata = (StreamData *) callback_data;
- priv = sdata->view->priv;
+ d(g_print ("Close\n"));
- if (result != GNOME_VFS_OK) {
- g_warning ("Open failed: %s.\n",
- gnome_vfs_result_to_string (result));
+ if (read_data->is_doc) {
+ gtk_adjustment_set_value (
+ gtk_layout_get_vadjustment (GTK_LAYOUT (priv->view)),
+ 0);
+ }
- yh_free_stream_data (sdata, TRUE);
- } else {
- gchar *buffer;
+ g_free (read_data);
+}
- buffer = g_malloc (BUFFER_SIZE);
+static void
+yelp_html_do_non_docbook (YelpHtml *html, HtmlStream *stream,
+ const gchar *uri, gboolean is_doc)
+{
+ GnomeVFSHandle *handle;
+ GnomeVFSResult result;
+ gchar buffer[BUFFER_SIZE];
+ GTimer *timer;
+ ReadData *read_data;
+
+ g_return_if_fail (YELP_IS_HTML (html));
+
+ d(g_print ("Non docbook: %s\n", uri));
- gnome_vfs_async_read (handle, buffer,
- BUFFER_SIZE,
- yh_async_read_cb, sdata);
+ timer = g_timer_new ();
+
+ result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+
+ d(g_print ("Opening took: %f\n", g_timer_elapsed (timer, 0)));
+
+ if (result != GNOME_VFS_OK) {
+ g_warning ("Failed to open: %s", uri);
+ return;
}
+
+ g_timer_start (timer);
+
+ read_data = g_new0 (ReadData, 1);
+
+ read_data->html = html;
+ read_data->buffer = buffer;
+ read_data->handle = handle;
+ read_data->stream = stream;
+ read_data->is_doc = is_doc;
+
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ yelp_html_idle_read,
+ read_data,
+ yelp_html_idle_read_end);
}
static void
@@ -267,37 +324,33 @@ yh_url_requested_cb (HtmlDocument *doc,
HtmlStream *stream,
gpointer data)
{
- YelpHtml *view;
- YelpHtmlPriv *priv;
- GnomeVFSURI *vfs_uri;
- StreamData *sdata;
+ YelpHtml *html;
+ GnomeVFSHandle *handle;
+ GnomeVFSResult result;
+ gchar buffer[BUFFER_SIZE];
+ GnomeVFSFileSize read_len;
d(g_print ("URL REQUESTED: %s\n", uri));
- view = YELP_HTML (data);
- priv = view->priv;
+ html = YELP_HTML (data);
- g_assert (HTML_IS_DOCUMENT(doc));
- g_assert (stream != NULL);
+ html_stream_set_cancel_func (stream, yh_stream_cancel, html);
- sdata = g_new0 (StreamData, 1);
- sdata->view = view;
- sdata->stream = stream;
-
- priv->connections = g_slist_prepend (priv->connections, sdata);
-
- vfs_uri = gnome_vfs_uri_new (uri);
+ result = gnome_vfs_open (&handle, uri, GNOME_VFS_OPEN_READ);
+
+ if (result != GNOME_VFS_OK) {
+ g_warning ("Failed to open: %s", uri);
+ return;
+ }
- gnome_vfs_async_open_uri (&sdata->handle,
- vfs_uri,
- GNOME_VFS_OPEN_READ,
- GNOME_VFS_PRIORITY_DEFAULT,
- yh_async_open_cb,
- sdata);
+ while (gnome_vfs_read (handle, buffer, BUFFER_SIZE, &read_len) ==
+ GNOME_VFS_OK) {
+ html_stream_write (stream, buffer, read_len);
+ }
- gnome_vfs_uri_unref (vfs_uri);
+ gnome_vfs_close (handle);
- html_stream_set_cancel_func (stream, yh_stream_cancel, sdata);
+/* yelp_html_do_non_docbook (html, stream, uri, FALSE); */
}
static void
@@ -305,36 +358,9 @@ yh_stream_cancel (HtmlStream *stream,
gpointer user_data,
gpointer cancel_data)
{
- StreamData *sdata = (StreamData *)cancel_data;
-
- d(puts(G_GNUC_FUNCTION));
-
- gnome_vfs_async_cancel (sdata->handle);
-
- yh_free_stream_data (sdata, TRUE);
-}
-
-static void
-yh_free_stream_data (StreamData *sdata, gboolean remove)
-{
- YelpHtmlPriv *priv;
-
- d(puts(G_GNUC_FUNCTION));
-
- priv = sdata->view->priv;
-
- if (remove) {
- priv->connections = g_slist_remove (priv->connections, sdata);
- }
-
- if (sdata->anchor) {
- g_free (sdata->anchor);
- }
-
- html_stream_close(sdata->stream);
-
- g_free (sdata);
+ d(g_print ("CANCEL!!\n"));
+ /* Not sure what to do here */
}
static void
@@ -350,7 +376,7 @@ yh_link_clicked_cb (HtmlDocument *doc, const gchar *url, YelpHtml *html)
/* If this is a relative reference. Shortcut reload. */
if (url && (url[0] == '#' || url[0] == '?')) {
- html_view_jump_to_anchor (HTML_VIEW (html),
+ html_view_jump_to_anchor (HTML_VIEW (html->priv->view),
&url[1]);
handled = TRUE;
}
@@ -362,119 +388,76 @@ yh_link_clicked_cb (HtmlDocument *doc, const gchar *url, YelpHtml *html)
url, html->priv->base_uri, handled);
}
-GtkWidget *
+YelpHtml *
yelp_html_new (void)
{
- YelpHtml *view;
+ YelpHtml *html;
d(puts(G_GNUC_FUNCTION));
- view = g_object_new (YELP_TYPE_HTML, NULL);
+ html = g_object_new (YELP_TYPE_HTML, NULL);
- html_document_open_stream (view->priv->doc, "text/html");
+ html_document_open_stream (html->priv->doc, "text/html");
{
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);
+ html_document_write_stream (html->priv->doc, text, len);
}
- html_document_close_stream (view->priv->doc);
+ html_document_close_stream (html->priv->doc);
- return GTK_WIDGET (view);
+ return html;
}
-
void
-yelp_html_open_uri (YelpHtml *view,
+yelp_html_open_uri (YelpHtml *html,
const gchar *str_uri,
const gchar *reference)
{
YelpHtmlPriv *priv;
- StreamData *sdata;
- GnomeVFSURI *uri;
- gchar *docpath;
- gchar *anchor;
- d(puts(G_GNUC_FUNCTION));
-
- g_return_if_fail (YELP_IS_HTML (view));
- g_return_if_fail (str_uri != NULL);
-
- priv = view->priv;
-
- docpath = yelp_util_split_uri (str_uri, &anchor);
-
- if (reference && !anchor) {
- anchor = g_strdup (reference);
- }
-
- if (!strcmp (priv->base_uri, docpath)) {
- /* Same document that are already shown in this view */
- /* Just jump if we have an anchor */
- if (anchor) {
- d(g_print ("Jumping to [%s]\n", anchor));
-
- html_view_jump_to_anchor (HTML_VIEW (view),
- anchor);
- } else {
- d(g_print ("Going to the beginning of the page"));
-
- gtk_adjustment_set_value (
- gtk_layout_get_vadjustment (GTK_LAYOUT (view)),
- 0);
- }
+ d(g_print ("Open URI: %s\n", str_uri));
- return;
- }
-
- html_view_set_document (HTML_VIEW (view), priv->load_doc);
-
- /* New document needs to be read. */
+ g_return_if_fail (YELP_IS_HTML (html));
+ g_return_if_fail (str_uri != NULL);
- g_free (priv->base_uri);
- priv->base_uri = g_strdup (docpath);
+ priv = html->priv;
html_document_clear (priv->doc);
html_document_open_stream (priv->doc, "text/html");
-
- gtk_adjustment_set_value (
- gtk_layout_get_vadjustment (GTK_LAYOUT (view)), 0);
-
- sdata = g_new0 (StreamData, 1);
- sdata->view = view;
- sdata->stream = priv->doc->current_stream;
- sdata->anchor = NULL;
-
- priv->connections = g_slist_prepend (priv->connections, sdata);
-
- uri = gnome_vfs_uri_new (docpath);
-
- if (anchor) {
- sdata->anchor = anchor;
+ html_stream_set_cancel_func (priv->doc->current_stream,
+ yh_stream_cancel,
+ html);
+ gtk_adjustment_set_value (
+ gtk_layout_get_vadjustment (
+ GTK_LAYOUT (priv->view)), 0);
+ gtk_adjustment_set_value (
+ gtk_layout_get_hadjustment (
+ GTK_LAYOUT (priv->view)), 0);
+
+ if (!strncmp (str_uri, "ghelp:", 6)) {
+ yelp_html_do_docbook (html, str_uri + 6);
+ /* Docbook or HTML */
+ return;
}
- d(g_print ("Trying to open: %s[%s]\n", docpath, reference));
-
- /* FIXME: Implement some cache */
-
- gnome_vfs_async_open_uri (&sdata->handle,
- uri,
- GNOME_VFS_OPEN_READ,
- GNOME_VFS_PRIORITY_DEFAULT,
- yh_async_open_cb,
- sdata);
-
- gnome_vfs_uri_unref (uri);
-
- html_stream_set_cancel_func (sdata->stream,
- yh_stream_cancel,
- sdata);
+ yelp_html_do_non_docbook (html, priv->doc->current_stream,
+ str_uri, TRUE);
}
void
-yelp_html_cancel_loading (YelpHtml *view)
+yelp_html_cancel_loading (YelpHtml *html)
{
}
+
+GtkWidget *
+yelp_html_get_widget (YelpHtml *html)
+{
+ g_return_val_if_fail (YELP_IS_HTML (html), NULL);
+
+ return GTK_WIDGET (html->priv->view);
+}
+
diff --git a/src/yelp-html.h b/src/yelp-html.h
index 8e18b617..6f801b20 100644
--- a/src/yelp-html.h
+++ b/src/yelp-html.h
@@ -26,7 +26,6 @@
#include <gtk/gtkobject.h>
#include <gtk/gtktypeutils.h>
#include <gtk/gtkmarshal.h>
-#include <libgtkhtml/gtkhtml.h>
#include "yelp-section.h"
#define YELP_TYPE_HTML (yelp_html_get_type ())
@@ -40,13 +39,13 @@ typedef struct _YelpHtmlClass YelpHtmlClass;
typedef struct _YelpHtmlPriv YelpHtmlPriv;
struct _YelpHtml {
- HtmlView parent;
+ GObject parent;
- YelpHtmlPriv *priv;
+ YelpHtmlPriv *priv;
};
struct _YelpHtmlClass {
- HtmlViewClass parent_class;
+ GObjectClass parent_class;
/* Signals */
void (*url_selected) (YelpHtml *view,
@@ -56,12 +55,14 @@ struct _YelpHtmlClass {
};
GType yelp_html_get_type (void);
-GtkWidget *yelp_html_new (void);
+YelpHtml * yelp_html_new (void);
-void yelp_html_open_uri (YelpHtml *view,
+void yelp_html_open_uri (YelpHtml *html,
const gchar *uri,
const gchar *reference);
-void yelp_html_cancel_loading (YelpHtml *view);
+void yelp_html_cancel_loading (YelpHtml *html);
+GtkWidget * yelp_html_get_widget (YelpHtml *html);
+
#endif /* __YELP_HTML_H__ */
diff --git a/src/yelp-util.c b/src/yelp-util.c
index 862a66a6..b0d82950 100644
--- a/src/yelp-util.c
+++ b/src/yelp-util.c
@@ -511,9 +511,14 @@ yelp_util_extract_docpath_from_uri (const gchar *str_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"); */
+ if (!strncmp (str_uri, "man:", 4)) {
+ return g_strdup (str_uri + 4);
+ }
+ else if (!strncmp (str_uri, "info:", 5)) {
+ return g_strdup (str_uri + 5);
+ }
+ else if (strncmp (str_uri, "ghelp:", 6)) {
+ /* Strange uri, just return the same string */
return g_strdup (str_uri);
}
diff --git a/src/yelp-view-content.c b/src/yelp-view-content.c
index c9edfbc4..4961f3f5 100644
--- a/src/yelp-view-content.c
+++ b/src/yelp-view-content.c
@@ -26,6 +26,10 @@
#include <libgnome/gnome-i18n.h>
#include <gtk/gtktreeview.h>
+#include <gtk/gtktreeselection.h>
+#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <gtk/gtkframe.h>
#include <string.h>
@@ -57,7 +61,7 @@ struct _YelpViewContentPriv {
GNode *doc_tree;
/* Html view */
- GtkWidget *html_view;
+ YelpHtml *html_view;
gchar *current_docpath;
};
@@ -213,10 +217,11 @@ yelp_view_content_new (GNode *doc_tree)
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
frame = gtk_frame_new (NULL);
- gtk_container_add (GTK_CONTAINER (frame), html_sw);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (html_sw), priv->html_view);
+ gtk_container_add (GTK_CONTAINER (frame), html_sw);
+ gtk_container_add (GTK_CONTAINER (html_sw),
+ yelp_html_get_widget (priv->html_view));
/* Add the tree and html view to the paned */
gtk_paned_add1 (GTK_PANED (view), priv->tree_sw);
@@ -338,8 +343,7 @@ yelp_view_content_show_uri (YelpViewContent *content,
content_url = (char *) url;
}
- yelp_html_open_uri (YELP_HTML (priv->html_view),
- content_url, NULL);
+ yelp_html_open_uri (priv->html_view, content_url, NULL);
if (content_url != url) {
g_free (content_url);
@@ -351,6 +355,5 @@ yelp_view_content_stop (YelpViewContent *content)
{
g_return_if_fail (YELP_IS_VIEW_CONTENT (content));
- yelp_html_cancel_loading (YELP_HTML (content->priv->html_view));
+ yelp_html_cancel_loading (content->priv->html_view);
}
-
diff --git a/src/yelp-view-index.c b/src/yelp-view-index.c
index 14e5116e..d7eb5885 100644
--- a/src/yelp-view-index.c
+++ b/src/yelp-view-index.c
@@ -24,8 +24,18 @@
#include <config.h>
#endif
-#include <libgnome/gnome-i18n.h>
+#include <atk/atk.h>
+#include <gtk/gtkaccessible.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <gtk/gtkentry.h>
+#include <gtk/gtkframe.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtkvbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtktreeview.h>
+#include <gtk/gtktreeselection.h>
+#include <libgnome/gnome-i18n.h>
#include <string.h>
#include "yelp-index-model.h"
@@ -388,7 +398,8 @@ yelp_view_index_new (GList *index)
gtk_container_add (GTK_CONTAINER (frame), html_sw);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
- gtk_container_add (GTK_CONTAINER (html_sw), priv->html_view);
+ gtk_container_add (GTK_CONTAINER (html_sw),
+ yelp_html_get_widget (YELP_HTML (priv->html_view)));
/* Add the tree and html view to the paned */
gtk_paned_add1 (GTK_PANED (view), box);
diff --git a/src/yelp-window.c b/src/yelp-window.c
index fc71f14f..aedc80ed 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -329,10 +329,10 @@ yw_handle_url (YelpWindow *window, const gchar *url)
strncmp (url, "info:", 5) == 0 ||
strncmp (url, "ghelp:", 6) == 0 ||
strncmp (url, "path:", 5) == 0) {
- yelp_view_content_show_uri (YELP_VIEW_CONTENT (priv->content_view),
- url);
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
PAGE_CONTENT_VIEW);
+ yelp_view_content_show_uri (YELP_VIEW_CONTENT (priv->content_view),
+ url);
return TRUE;
} else if (strncmp (url, "index:", 6) == 0) {
gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),