summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2003-11-29 05:09:57 +0000
committerShaun McCance <shaunm@src.gnome.org>2003-11-29 05:09:57 +0000
commit0e05623b8ec5ea1f39980edeb947294a5c55b416 (patch)
treebb8b0e18682d91a2dfb16f269c1fa0d0e7034f7e
parentcbf8860d93b960920733a98a5bc230952a0da1c3 (diff)
downloadyelp-0e05623b8ec5ea1f39980edeb947294a5c55b416.tar.gz
- Switched to a different bit of the libxml2 API to parse the document. -
* src/yelp-db-pager.c: - Switched to a different bit of the libxml2 API to parse the document. - Made page_id default to "index" when frag_id == NULL. * src/yelp-pager.c: * src/yelp-pager.h: - Implemented yelp_uri_is_page. * src/yelp-toc-pager.c: - Implemented resolve_uri. - Finished parsing of TOC, just need to write the pages. - Began work on indexing stuff. * src/yelp-uri.c: - Fixed memory corruption. * src/yelp-window.c: - Added callbacks for error and finish signals. - Made the TOC go through window_handle_pager_uri. - Switched to yelp_pager_uri_is_page in page callback.
-rw-r--r--ChangeLog23
-rw-r--r--src/yelp-db-pager.c21
-rw-r--r--src/yelp-pager.c27
-rw-r--r--src/yelp-pager.h3
-rw-r--r--src/yelp-toc-pager.c195
-rw-r--r--src/yelp-uri.c2
-rw-r--r--src/yelp-window.c201
7 files changed, 373 insertions, 99 deletions
diff --git a/ChangeLog b/ChangeLog
index 5773f185..02797be1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2003-11-28 Shaun McCance <shaunm@gnome.org>
+
+ * src/yelp-db-pager.c:
+ - Switched to a different bit of the libxml2 API to parse the document.
+ - Made page_id default to "index" when frag_id == NULL.
+
+ * src/yelp-pager.c:
+ * src/yelp-pager.h:
+ - Implemented yelp_uri_is_page.
+
+ * src/yelp-toc-pager.c:
+ - Implemented resolve_uri.
+ - Finished parsing of TOC, just need to write the pages.
+ - Began work on indexing stuff.
+
+ * src/yelp-uri.c:
+ - Fixed memory corruption.
+
+ * src/yelp-window.c:
+ - Added callbacks for error and finish signals.
+ - Made the TOC go through window_handle_pager_uri.
+ - Switched to yelp_pager_uri_is_page in page callback.
+
2003-11-12 Shaun McCance <shaunm@gnome.org>
* src/Makefile.am:
diff --git a/src/yelp-db-pager.c b/src/yelp-db-pager.c
index aa4f69a4..df036941 100644
--- a/src/yelp-db-pager.c
+++ b/src/yelp-db-pager.c
@@ -195,6 +195,7 @@ db_pager_process (YelpPager *pager)
DBWalker *walker;
GError *error;
+ xmlDocPtr doc;
xmlParserCtxtPtr ctxt;
xsltStylesheetPtr stylesheet;
xsltTransformContextPtr tctxt;
@@ -211,13 +212,13 @@ db_pager_process (YelpPager *pager)
yelp_toc_pager_pause (yelp_toc_pager_get ());
- ctxt = xmlCreateFileParserCtxt (uri_str);
+ ctxt = xmlNewParserCtxt ();
ctxt->replaceEntities = TRUE;
ctxt->validate = FALSE;
ctxt->loadsubset = TRUE;
- xmlParseDocument (ctxt);
+ doc = xmlCtxtReadFile (ctxt, (const char *) uri_str, NULL, 0);
- if (ctxt->myDoc == NULL) {
+ if (doc == NULL) {
error = NULL;
yelp_pager_error (pager, error);
@@ -226,7 +227,7 @@ db_pager_process (YelpPager *pager)
walker = g_new0 (DBWalker, 1);
walker->pager = YELP_DB_PAGER (pager);
- walker->doc = ctxt->myDoc;
+ walker->doc = doc;
walker->cur = xmlDocGetRootElement (walker->doc);
while (gtk_events_pending ())
@@ -259,7 +260,7 @@ db_pager_process (YelpPager *pager)
stylesheet = xsltParseStylesheetFile (DB_STYLESHEET);
tctxt = xsltNewTransformContext (stylesheet,
- ctxt->myDoc);
+ doc);
tctxt->_private = pager;
xsltRegisterExtElement (tctxt,
"document",
@@ -274,11 +275,12 @@ db_pager_process (YelpPager *pager)
gtk_main_iteration ();
xsltApplyStylesheetUser (stylesheet,
- ctxt->myDoc,
+ doc,
params,
NULL, NULL,
tctxt);
+ xmlFreeDoc (doc);
xsltFreeStylesheet (stylesheet);
xmlFreeParserCtxt (ctxt);
@@ -326,8 +328,11 @@ db_pager_resolve_uri (YelpPager *pager, YelpURI *uri)
frag_id = yelp_uri_get_fragment (uri);
- page_id = g_hash_table_lookup (db_pager->priv->frags_hash,
- frag_id);
+ if (frag_id)
+ page_id = g_hash_table_lookup (db_pager->priv->frags_hash,
+ frag_id);
+ else
+ page_id = g_strdup ("index");
g_free (frag_id);
return page_id;
diff --git a/src/yelp-pager.c b/src/yelp-pager.c
index 79433bed..e8f17768 100644
--- a/src/yelp-pager.c
+++ b/src/yelp-pager.c
@@ -31,6 +31,8 @@
#include "yelp-marshal.h"
#include "yelp-uri.h"
+#include <string.h>
+
#define d(x)
struct _YelpPagerPriv {
@@ -336,6 +338,31 @@ yelp_pager_get_sections (YelpPager *pager)
return YELP_PAGER_GET_CLASS (pager)->get_sections (pager);
}
+gboolean
+yelp_pager_uri_is_page (YelpPager *pager, gchar *page_id, YelpURI *uri)
+{
+ gchar *frag_id = NULL;
+ gboolean equal;
+
+ frag_id = (gchar *) (YELP_PAGER_GET_CLASS (pager)->resolve_uri (pager, uri));
+
+ if (!frag_id || !strcmp (frag_id, ""))
+ equal = FALSE;
+ else if (!page_id || !strcmp (page_id, "") || !strcmp (page_id, "index")) {
+ if (!strcmp (frag_id, "index"))
+ equal = TRUE;
+ else
+ equal = FALSE;
+ }
+ else if (!strcmp (page_id, frag_id))
+ equal = TRUE;
+ else
+ equal = FALSE;
+
+ g_free (frag_id);
+ return equal;
+}
+
const YelpPage *
yelp_pager_lookup_page (YelpPager *pager, YelpURI *uri)
{
diff --git a/src/yelp-pager.h b/src/yelp-pager.h
index 6da01e0f..39826085 100644
--- a/src/yelp-pager.h
+++ b/src/yelp-pager.h
@@ -90,6 +90,9 @@ void yelp_pager_error (YelpPager *pager,
const GtkTreeModel * yelp_pager_get_sections (YelpPager *pager);
+gboolean yelp_pager_uri_is_page (YelpPager *pager,
+ gchar *page_id,
+ YelpURI *uri);
const YelpPage * yelp_pager_lookup_page (YelpPager *pager,
YelpURI *uri);
const YelpPage * yelp_pager_get_page (YelpPager *pager,
diff --git a/src/yelp-toc-pager.c b/src/yelp-toc-pager.c
index 9ee5e228..4f6cc609 100644
--- a/src/yelp-toc-pager.c
+++ b/src/yelp-toc-pager.c
@@ -41,8 +41,11 @@ typedef struct _OMF OMF;
struct _YelpTocPagerPriv {
GSList *omf_pending;
+ xmlDocPtr toc_doc;
GSList *toc_pending;
+ GSList *idx_pending;
+
GHashTable *unique_hash_omf;
GHashTable *category_hash_omf;
@@ -89,6 +92,11 @@ static void toc_unhash_omf (YelpTocPager *pager,
static gboolean toc_process_toc (YelpTocPager *pager);
static gboolean toc_process_toc_pending (YelpTocPager *pager);
+static gboolean toc_process_idx (YelpTocPager *pager);
+static gboolean toc_process_idx_pending (YelpTocPager *pager);
+
+static xmlChar * node_get_title (xmlNodePtr node);
+
static void omf_free (OMF *omf);
static YelpPagerClass *parent_class;
@@ -224,8 +232,16 @@ toc_pager_cancel (YelpPager *pager)
gchar *
toc_pager_resolve_uri (YelpPager *pager, YelpURI *uri)
{
- // FIXME
- return NULL;
+ gchar *path = yelp_uri_get_path (uri);
+
+ if (!strcmp (path, "")) {
+ g_free (path);
+ return g_strdup ("index");
+ }
+ else if (!path)
+ return g_strdup ("index");
+ else
+ return path;
}
const GtkTreeModel *
@@ -414,7 +430,6 @@ toc_process_omf_pending (YelpPager *pager)
omf_free (omf);
goto done;
} else {
- printf (":: %s %s\n", omf_old->omf_file, omf->omf_file);
toc_unhash_omf (YELP_TOC_PAGER (pager), omf_old);
omf_free (omf_old);
@@ -449,18 +464,16 @@ toc_process_omf_pending (YelpPager *pager)
static gboolean
toc_process_toc (YelpTocPager *pager)
{
- xmlDocPtr toc_doc;
xmlNodePtr toc_node;
GError *error = NULL;
YelpTocPagerPriv *priv = pager->priv;
- printf ("toc_process_toc\n");
- toc_doc = xmlCtxtReadFile (priv->parser,
- DATADIR "/yelp/toc.xml",
- NULL, 0);
+ priv->toc_doc = xmlCtxtReadFile (priv->parser,
+ DATADIR "/yelp/toc.xml",
+ NULL, 0);
- if (!toc_doc) {
+ if (!priv->toc_doc) {
g_set_error (&error,
YELP_ERROR,
YELP_ERROR_FAILED_TOC,
@@ -469,9 +482,9 @@ toc_process_toc (YelpTocPager *pager)
return FALSE;
}
- toc_node = xmlDocGetRootElement (toc_doc);
+ toc_node = xmlDocGetRootElement (priv->toc_doc);
- if (!xmlStrcmp (toc_node->name, "toc")) {
+ if (xmlStrcmp (toc_node->name, (const xmlChar *) "toc")) {
g_set_error (&error,
YELP_ERROR,
YELP_ERROR_FAILED_TOC,
@@ -486,7 +499,6 @@ toc_process_toc (YelpTocPager *pager)
(GtkFunction) toc_process_toc_pending,
pager);
- xmlFreeDoc (toc_doc);
return FALSE;
}
@@ -496,8 +508,10 @@ toc_process_toc_pending (YelpTocPager *pager)
GSList *first;
xmlNodePtr node;
xmlNodePtr cur;
- xmlChar *id;
- gchar *url;
+ xmlChar *id = NULL;
+ xmlChar *title;
+ GSList *subcats = NULL;
+ GSList *subomfs = NULL;
YelpTocPagerPriv *priv = pager->priv;
@@ -507,51 +521,188 @@ toc_process_toc_pending (YelpTocPager *pager)
node = first->data;
id = xmlGetProp (node, (const xmlChar *) "id");
- url = g_strconcat ("toc:", (gchar *) id, NULL);
- xmlFree (id);
+
+ title = node_get_title (node);
for (cur = node->children; cur; cur = cur->next) {
- printf ("cur: %s\n", cur->name);
+ if (cur->type == XML_ELEMENT_NODE) {
+ if (!xmlStrcmp (cur->name, "toc")) {
+ priv->toc_pending = g_slist_append (priv->toc_pending, cur);
+ subcats = g_slist_prepend (subcats, cur);
+ }
+ else if (!xmlStrcmp (cur->name, "category")) {
+ GSList *omf;
+ xmlChar *cat;
+
+ cat = xmlNodeGetContent (cur);
+ omf = g_hash_table_lookup (priv->category_hash_omf, cat);
+
+ for ( ; omf; omf = omf->next)
+ subomfs = g_slist_prepend (subomfs, omf->data);
+
+ xmlFree (cat);
+ }
+ }
}
+ if (id) {
+ yelp_pager_add_page (YELP_PAGER (pager),
+ id, title,
+ g_strdup ("<html><body>FIXME</body></html"));
+ g_signal_emit_by_name (pager, "page", id);
+ } else {
+ g_warning (_("YelpTocPager: TOC entry has no id."));
+ g_free (title);
+ }
+
+ g_slist_free (subcats);
+ g_slist_free (subomfs);
g_slist_free_1 (first);
if (!priv->toc_pending) {
+ xmlFreeDoc (priv->toc_doc);
+ g_signal_emit_by_name (pager, "finish");
+
+ if (priv->pause_count > 0)
+ priv->unpause_func = (GtkFunction) toc_process_idx;
+ else
+ gtk_idle_add_priority (G_PRIORITY_LOW,
+ (GtkFunction) toc_process_idx,
+ pager);
return FALSE;
}
else if (priv->pause_count > 0) {
priv->unpause_func = (GtkFunction) toc_process_toc_pending;
return FALSE;
}
- else
+ else {
+ return TRUE;
+ }
+}
+
+static gboolean
+toc_process_idx (YelpTocPager *pager)
+{
+ gtk_idle_add_priority (G_PRIORITY_LOW,
+ (GtkFunction) toc_process_idx_pending,
+ pager);
+ return FALSE;
+}
+
+static gboolean
+toc_process_idx_pending (YelpTocPager *pager)
+{
+ GSList *first;
+ OMF *omf;
+ YelpURI *uri;
+ gchar *path;
+ xmlDocPtr doc;
+
+ YelpTocPagerPriv *priv = pager->priv;
+
+ first = priv->idx_pending;
+ priv->idx_pending = g_slist_remove_link (priv->idx_pending, first);
+
+ omf = first->data;
+
+ printf ("OMF: %s\n", omf->xml_file);
+
+ uri = yelp_uri_new (omf->xml_file);
+ path = yelp_uri_get_path (uri);
+
+ /*
+ doc = xmlCtxtReadFile (priv->parser,
+ path,
+ NULL, 0);
+
+ xmlFreeDoc (doc);
+ */
+
+ g_free (path);
+ g_object_unref (uri);
+ g_slist_free_1 (first);
+
+ if (!priv->idx_pending) {
+ return FALSE;
+ }
+ else if (priv->pause_count > 0) {
+ priv->unpause_func = (GtkFunction) toc_process_idx_pending;
+ return FALSE;
+ }
+ else {
return TRUE;
+ }
+}
+
+static xmlChar *
+node_get_title (xmlNodePtr node)
+{
+ xmlNodePtr cur;
+ xmlChar *title = NULL;
+ xmlChar *language = NULL;
+ gint priority = 0;
+
+ for (cur = node->children; cur; cur = cur->next) {
+ if (!xmlStrcmp (cur->name, (const xmlChar *) "title")) {
+ gint pri = 0;
+ xmlChar *tlang = xmlNodeGetLang (cur);
+ GList *langs = (GList *) gnome_i18n_get_language_list ("LC_MESSAGES");
+
+ for ( ; langs != NULL; langs = langs->next) {
+ gchar *lang = langs->data;
+ pri++;
+
+ if (lang == NULL || strchr (lang, '.') != NULL)
+ continue;
+
+ if (!xmlStrcmp ((xmlChar *) lang, tlang))
+ break;
+ }
+ if (priority == 0 || pri < priority) {
+ if (title)
+ xmlFree (title);
+ if (language)
+ xmlFree (language);
+ title = xmlNodeGetContent (cur);
+ language = tlang;
+ priority = pri;
+ } else {
+ xmlFree (tlang);
+ }
+ }
+ }
+ return title;
}
static void
toc_hash_omf (YelpTocPager *pager, OMF *omf)
{
GSList *category;
+ YelpTocPagerPriv *priv = pager->priv;
- g_hash_table_insert (pager->priv->unique_hash_omf,
+ g_hash_table_insert (priv->unique_hash_omf,
omf->uniqueid,
omf);
for (category = omf->categories; category; category = category->next) {
gchar *catstr = (gchar *) category->data;
GSList *omfs =
- (GSList *) g_hash_table_lookup (pager->priv->category_hash_omf,
+ (GSList *) g_hash_table_lookup (priv->category_hash_omf,
catstr);
omfs = g_slist_prepend (omfs, omf);
- g_hash_table_insert (pager->priv->category_hash_omf,
+ g_hash_table_insert (priv->category_hash_omf,
catstr, omfs);
}
+
+ priv->idx_pending = g_slist_prepend (priv->idx_pending, omf);
}
static void
toc_unhash_omf (YelpTocPager *pager, OMF *omf)
{
GSList *category;
+ YelpTocPagerPriv *priv = pager->priv;
g_hash_table_remove (pager->priv->unique_hash_omf,
omf->uniqueid);
@@ -567,6 +718,8 @@ toc_unhash_omf (YelpTocPager *pager, OMF *omf)
catstr, omfs);
}
}
+
+ priv->idx_pending = g_slist_remove (priv->idx_pending, omf);
}
static void
diff --git a/src/yelp-uri.c b/src/yelp-uri.c
index 6967226c..0819bca7 100644
--- a/src/yelp-uri.c
+++ b/src/yelp-uri.c
@@ -346,7 +346,7 @@ uri_parse_uri (YelpURI *uri, const gchar *uri_str)
scheme = g_strndup (path, c - path);
} else {
priv->type = YELP_URI_TYPE_RELATIVE;
- priv->path = path;
+ priv->path = g_strdup (path);
return;
}
diff --git a/src/yelp-window.c b/src/yelp-window.c
index ec55ac7d..f0dbe219 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -77,12 +77,16 @@ static gboolean window_handle_uri (YelpWindow *window,
YelpURI *uri);
static gboolean window_handle_pager_uri (YelpWindow *window,
YelpURI *uri);
-static gboolean window_handle_toc_uri (YelpWindow *window,
+static gboolean window_handle_html_uri (YelpWindow *window,
YelpURI *uri);
static void pager_page_cb (YelpPager *pager,
gchar *page_id,
gpointer user_data);
+static void pager_error_cb (YelpPager *pager,
+ gpointer user_data);
+static void pager_finish_cb (YelpPager *pager,
+ gpointer user_data);
static void html_uri_selected_cb (YelpHtml *html,
YelpURI *uri,
@@ -104,9 +108,9 @@ static gboolean window_configure_cb (GtkWidget *widget,
GdkEventConfigure *event,
gpointer data);
-static void window_back_button_clicked (GtkWidget *button,
+static void window_back_clicked (GtkWidget *button,
YelpWindow *window);
-static void window_forward_button_clicked (GtkWidget *button,
+static void window_forward_clicked (GtkWidget *button,
YelpWindow *window);
static void window_home_button_clicked (GtkWidget *button,
YelpWindow *window);
@@ -177,6 +181,8 @@ struct _YelpWindowPriv {
YelpPager *pager;
gulong page_handler;
+ gulong error_handler;
+ gulong finish_handler;
GtkItemFactory *item_factory;
@@ -485,7 +491,7 @@ window_create_toolbar (YelpWindow *window)
_("Back"),
_("Show previous page in history"),
NULL, icon,
- G_CALLBACK (window_back_button_clicked),
+ G_CALLBACK (window_back_clicked),
window);
gtk_widget_set_sensitive (priv->back_button, FALSE);
@@ -496,7 +502,7 @@ window_create_toolbar (YelpWindow *window)
_("Forward"),
_("Show next page in history"),
NULL, icon,
- G_CALLBACK (window_forward_button_clicked),
+ G_CALLBACK (window_forward_clicked),
window);
gtk_widget_set_sensitive (priv->forward_button, FALSE);
@@ -551,6 +557,7 @@ window_set_sections (YelpWindow *window,
if (sections == NULL) {
// FIXME: remove the sidebar.
+ gtk_tree_view_set_model (GTK_TREE_VIEW (priv->side_sects), sections);
} else {
// FIXME: add the sidebar.
gtk_tree_view_set_model (GTK_TREE_VIEW (priv->side_sects), sections);
@@ -588,6 +595,7 @@ window_handle_uri (YelpWindow *window,
case YELP_URI_TYPE_DOCBOOK_XML:
case YELP_URI_TYPE_MAN:
case YELP_URI_TYPE_INFO:
+ case YELP_URI_TYPE_TOC:
handled = window_handle_pager_uri (window, uri);
break;
case YELP_URI_TYPE_DOCBOOK_SGML:
@@ -598,10 +606,9 @@ window_handle_uri (YelpWindow *window,
window_error (window, error);
return FALSE;
- case YELP_URI_TYPE_TOC:
- handled = window_handle_toc_uri (window, uri);
- break;
case YELP_URI_TYPE_HTML:
+ handled = window_handle_html_uri (window, uri);
+ break;
case YELP_URI_TYPE_GHELP:
case YELP_URI_TYPE_GHELP_OTHER:
case YELP_URI_TYPE_INDEX:
@@ -627,6 +634,7 @@ window_handle_pager_uri (YelpWindow *window,
GError *error = NULL;
gboolean loadnow = FALSE;
gboolean startnow = TRUE;
+ gchar *str_uri;
gchar *path;
YelpPage *page = NULL;
YelpPager *pager;
@@ -639,30 +647,53 @@ window_handle_pager_uri (YelpWindow *window,
priv->page_handler);
priv->page_handler = 0;
}
+ if (priv->error_handler) {
+ g_signal_handler_disconnect (priv->pager,
+ priv->error_handler);
+ priv->error_handler = 0;
+ }
+ if (priv->finish_handler) {
+ g_signal_handler_disconnect (priv->pager,
+ priv->finish_handler);
+ priv->finish_handler = 0;
+ }
// Grab the appropriate pager from the cache
- path = yelp_uri_get_path (uri);
- pager = (YelpPager *) yelp_cache_lookup (path);
-
- // Create a new pager if one doesn't exist in the cache
- if (!pager) {
- switch (yelp_uri_get_resource_type (uri)) {
- case YELP_URI_TYPE_DOCBOOK_XML:
- pager = yelp_db_pager_new (uri);
- break;
- case YELP_URI_TYPE_INFO:
- // FIXME
- break;
- case YELP_URI_TYPE_MAN:
- // FIXME
- break;
- default:
- // FIXME: Error
- break;
+ if (yelp_uri_get_resource_type (uri) == YELP_URI_TYPE_TOC) {
+ pager = YELP_PAGER (yelp_toc_pager_get ());
+ } else {
+ path = yelp_uri_get_path (uri);
+ pager = (YelpPager *) yelp_cache_lookup (path);
+
+ // Create a new pager if one doesn't exist in the cache
+ if (!pager) {
+ switch (yelp_uri_get_resource_type (uri)) {
+ case YELP_URI_TYPE_DOCBOOK_XML:
+ pager = yelp_db_pager_new (uri);
+ break;
+ case YELP_URI_TYPE_INFO:
+ // FIXME: yelp_info_pager_new (uri);
+ break;
+ case YELP_URI_TYPE_MAN:
+ // FIXME: yelp_man_pager_new (uri);
+ break;
+ default:
+ break;
+ }
+
+ if (pager)
+ yelp_cache_add (path, (GObject *) pager);
}
+ }
- if (pager)
- yelp_cache_add (path, (GObject *) pager);
+ if (!pager) {
+ str_uri = yelp_uri_to_string (uri);
+ g_set_error (&error,
+ YELP_ERROR,
+ YELP_ERROR_FAILED_OPEN,
+ _("The document '%s' could not be opened"), str_uri);
+ g_free (str_uri);
+ window_error (window, error);
}
g_object_ref (pager);
@@ -686,8 +717,8 @@ window_handle_pager_uri (YelpWindow *window,
loadnow = TRUE;
break;
case YELP_PAGER_STATE_ERROR:
- printf ("ERROR\n");
- // FIXME: show error
+ error = yelp_pager_get_error (pager);
+ window_error (window, error);
return FALSE;
default:
g_assert_not_reached ();
@@ -724,6 +755,16 @@ window_handle_pager_uri (YelpWindow *window,
"page",
G_CALLBACK (pager_page_cb),
window);
+ priv->error_handler =
+ g_signal_connect (pager,
+ "error",
+ G_CALLBACK (pager_error_cb),
+ window);
+ priv->finish_handler =
+ g_signal_connect (pager,
+ "finish",
+ G_CALLBACK (pager_finish_cb),
+ window);
if (startnow)
yelp_pager_start (pager);
@@ -758,24 +799,9 @@ window_handle_pager_uri (YelpWindow *window,
}
static gboolean
-window_handle_toc_uri (YelpWindow *window,
- YelpURI *uri)
+window_handle_html_uri (YelpWindow *window,
+ YelpURI *uri)
{
- YelpWindowPriv *priv;
- GError *error = NULL;
-
- priv = window->priv;
-
- // Disconnect signal handlers
- if (priv->page_handler) {
- g_signal_handler_disconnect (priv->pager,
- priv->page_handler);
- priv->page_handler = 0;
- }
-
- gchar *str_uri = yelp_uri_to_string (uri);
- printf ("::: %s\n", str_uri);
- g_free (str_uri);
return FALSE;
}
@@ -786,21 +812,26 @@ pager_page_cb (YelpPager *pager,
{
YelpWindow *window = YELP_WINDOW (user_data);
YelpURI *uri;
- gchar *frag;
YelpPage *page;
uri = yelp_window_get_current_uri (window);
- frag = yelp_uri_get_fragment (uri);
-
- if ( (yelp_uri_equal_path (uri, yelp_pager_get_uri (pager))) &&
- ( (frag == NULL && !strcmp (page_id, "index")) ||
- (!strcmp (frag, page_id)) )) {
+ if (yelp_pager_uri_is_page (pager, page_id, uri)) {
if (window->priv->page_handler) {
g_signal_handler_disconnect (window->priv->pager,
window->priv->page_handler);
window->priv->page_handler = 0;
}
+ if (window->priv->error_handler) {
+ g_signal_handler_disconnect (window->priv->pager,
+ window->priv->error_handler);
+ window->priv->error_handler = 0;
+ }
+ if (window->priv->finish_handler) {
+ g_signal_handler_disconnect (window->priv->pager,
+ window->priv->finish_handler);
+ window->priv->finish_handler = 0;
+ }
page = (YelpPage *) yelp_pager_get_page (pager, page_id);
@@ -814,8 +845,49 @@ pager_page_cb (YelpPager *pager,
page->chunk,
strlen (page->chunk));
}
+}
- g_free (frag);
+static void
+pager_error_cb (YelpPager *pager,
+ gpointer user_data)
+{
+ // FIXME
+}
+
+static void
+pager_finish_cb (YelpPager *pager,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ YelpWindow *window = YELP_WINDOW (user_data);
+ YelpURI *uri;
+ gchar *str_uri;
+
+ uri = yelp_window_get_current_uri (window);
+ str_uri = yelp_uri_to_string (uri);
+
+ if (window->priv->page_handler) {
+ g_signal_handler_disconnect (window->priv->pager,
+ window->priv->page_handler);
+ window->priv->page_handler = 0;
+ }
+ if (window->priv->error_handler) {
+ g_signal_handler_disconnect (window->priv->pager,
+ window->priv->error_handler);
+ window->priv->error_handler = 0;
+ }
+ if (window->priv->finish_handler) {
+ g_signal_handler_disconnect (window->priv->pager,
+ window->priv->finish_handler);
+ window->priv->finish_handler = 0;
+ }
+
+ g_set_error (&error,
+ YELP_ERROR,
+ YELP_ERROR_FAILED_OPEN,
+ _("The document '%s' could not be opened"), str_uri);
+ g_free (str_uri);
+ window_error (window, error);
}
static void
@@ -925,20 +997,18 @@ window_configure_cb (GtkWidget *widget,
}
static void
-window_back_button_clicked (GtkWidget *button,
- YelpWindow *window)
+window_back_clicked (GtkWidget *button,
+ YelpWindow *window)
{
- g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (YELP_IS_WINDOW (window));
window_history_action (window, YELP_WINDOW_ACTION_BACK);
}
static void
-window_forward_button_clicked (GtkWidget *button,
- YelpWindow *window)
+window_forward_clicked (GtkWidget *button,
+ YelpWindow *window)
{
- g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (YELP_IS_WINDOW (window));
window_history_action (window, YELP_WINDOW_ACTION_FORWARD);
@@ -954,16 +1024,9 @@ window_home_button_clicked (GtkWidget *button,
uri = yelp_uri_new ("toc:");
- // FIXME
- /*
- yelp_history_goto (window->priv->history, uri);
- yelp_view_show_uri (window->priv->toc_view, uri, NULL);
-
- yelp_uri_unref (uri);
+ yelp_window_open_uri (window, uri);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
- PAGE_TOC_VIEW);
- */
+ g_object_unref (uri);
}
static void