summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2003-11-16 00:24:49 +0000
committerShaun McCance <shaunm@src.gnome.org>2003-11-16 00:24:49 +0000
commit52842e4bb5ec0208157cd8ff7e4b65f7e41fcc18 (patch)
tree192f133fef4b63e135ca2838f4f95ecf082148ee
parentf173dcb666ca8500199f5bf81bced3ce322f3ee9 (diff)
downloadyelp-52842e4bb5ec0208157cd8ff7e4b65f7e41fcc18.tar.gz
- Use a YelpPage struct rather than just a gchar, so a page can hold the
* src/yelp-db-pager.c: * src/yelp-pager.c: * src/yelp-pager.h: - Use a YelpPage struct rather than just a gchar, so a page can hold the id and title and well as the contents. * src/yelp-error.h: - Add an error code for no-longer-supported SGML. * src/yelp-window.c: - Prepare to work TOC back in. - Use YelpPage. - Some more error-handling. - Make "Loading..." actually work. - Set window title.
-rw-r--r--ChangeLog18
-rw-r--r--src/yelp-db-pager.c33
-rw-r--r--src/yelp-error.h3
-rw-r--r--src/yelp-pager.c76
-rw-r--r--src/yelp-pager.h17
-rw-r--r--src/yelp-window.c130
6 files changed, 196 insertions, 81 deletions
diff --git a/ChangeLog b/ChangeLog
index e5f8218c..feb6e8ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
2003-11-15 Shaun McCance <shaunm@gnome.org>
+ * src/yelp-db-pager.c:
+ * src/yelp-pager.c:
+ * src/yelp-pager.h:
+ - Use a YelpPage struct rather than just a gchar, so a page can
+ hold the id and title and well as the contents.
+
+ * src/yelp-error.h:
+ - Add an error code for no-longer-supported SGML.
+
+ * src/yelp-window.c:
+ - Prepare to work TOC back in.
+ - Use YelpPage.
+ - Some more error-handling.
+ - Make "Loading..." actually work.
+ - Set window title.
+
+2003-11-15 Shaun McCance <shaunm@gnome.org>
+
* src/Makefile.am:
* src/yelp-cache.c:
* src/yelp-cache.h:
diff --git a/src/yelp-db-pager.c b/src/yelp-db-pager.c
index b9f1b1f8..52968a22 100644
--- a/src/yelp-db-pager.c
+++ b/src/yelp-db-pager.c
@@ -55,7 +55,7 @@ struct _YelpDBPagerPriv {
typedef struct _DBWalker DBWalker;
struct _DBWalker {
YelpDBPager *pager;
- gchar *chunk_id;
+ gchar *page_id;
xmlDocPtr doc;
xmlNodePtr cur;
@@ -294,7 +294,7 @@ db_pager_resolve_uri (YelpPager *pager, YelpURI *uri)
{
YelpDBPager *db_pager;
gchar *frag_id;
- const gchar *chunk_id;
+ const gchar *page_id;
g_return_val_if_fail (pager != NULL, NULL);
g_return_val_if_fail (YELP_IS_DB_PAGER (pager), NULL);
@@ -303,12 +303,12 @@ db_pager_resolve_uri (YelpPager *pager, YelpURI *uri)
frag_id = yelp_uri_get_fragment (uri);
- chunk_id =
+ page_id =
(const gchar *) g_hash_table_lookup (db_pager->priv->frags_hash,
frag_id);
g_free (frag_id);
- return chunk_id;
+ return page_id;
}
const GtkTreeModel *
@@ -327,8 +327,8 @@ xslt_yelp_document (xsltTransformContextPtr ctxt,
xsltStylePreCompPtr comp)
{
GError *error;
- xmlChar *chunk_id = NULL;
- xmlChar *chunk_buf;
+ xmlChar *page_id = NULL;
+ xmlChar *page_buf;
gint buf_size;
YelpPager *pager;
xsltStylesheetPtr style = NULL;
@@ -344,10 +344,10 @@ xslt_yelp_document (xsltTransformContextPtr ctxt,
pager = (YelpPager *) ctxt->_private;
- chunk_id = xsltEvalAttrValueTemplate (ctxt, inst,
+ page_id = xsltEvalAttrValueTemplate (ctxt, inst,
(const xmlChar *) "href",
NULL);
- if (chunk_id == NULL) {
+ if (page_id == NULL) {
xsltTransformError (ctxt, NULL, inst,
_("No href attribute found on yelp:document"));
error = NULL;
@@ -359,7 +359,7 @@ xslt_yelp_document (xsltTransformContextPtr ctxt,
old_outfile = ctxt->outputFile;
old_doc = ctxt->output;
old_insert = ctxt->insert;
- ctxt->outputFile = (const char *) chunk_id;
+ ctxt->outputFile = (const char *) page_id;
style = xsltNewStylesheet ();
if (style == NULL) {
@@ -380,14 +380,15 @@ xslt_yelp_document (xsltTransformContextPtr ctxt,
xsltApplyOneTemplate (ctxt, node, inst->children, NULL, NULL);
- xmlDocDumpFormatMemory (new_doc, &chunk_buf, &buf_size, 0);
+ xmlDocDumpFormatMemory (new_doc, &page_buf, &buf_size, 0);
ctxt->outputFile = old_outfile;
ctxt->output = old_doc;
ctxt->insert = old_insert;
- yelp_pager_add_chunk (pager, chunk_id, chunk_buf);
- g_signal_emit_by_name (pager, "chunk", chunk_id);
+ // FIXME
+ yelp_pager_add_page (pager, page_id, g_strdup ("FIXME"), page_buf);
+ g_signal_emit_by_name (pager, "page", page_id);
while (gtk_events_pending ())
gtk_main_iteration ();
@@ -435,8 +436,8 @@ walker_walk_xml (DBWalker *walker)
1, g_strdup (title),
-1);
- old_id = walker->chunk_id;
- walker->chunk_id = id;
+ old_id = walker->page_id;
+ walker->page_id = id;
old_iter = walker->iter;
walker->iter = &iter;
@@ -449,7 +450,7 @@ walker_walk_xml (DBWalker *walker)
if (id) {
g_hash_table_insert (priv->frags_hash,
g_strdup (id),
- g_strdup (walker->chunk_id));
+ g_strdup (walker->page_id));
}
cur = walker->cur->children;
@@ -466,7 +467,7 @@ walker_walk_xml (DBWalker *walker)
if (walker_is_chunk (walker) && id) {
walker->iter = old_iter;
- walker->chunk_id = old_id;
+ walker->page_id = old_id;
}
xmlFree (id);
diff --git a/src/yelp-error.h b/src/yelp-error.h
index 0a537029..afa7147e 100644
--- a/src/yelp-error.h
+++ b/src/yelp-error.h
@@ -28,7 +28,8 @@
typedef enum {
YELP_ERROR_URI_NOT_EXIST,
YELP_ERROR_DOCBOOK_2_HTML,
- YELP_ERROR_FAILED_OPEN
+ YELP_ERROR_FAILED_OPEN,
+ YELP_ERROR_NO_SGML
} YelpError;
GQuark yelp_error_quark (void) G_GNUC_CONST;
diff --git a/src/yelp-pager.c b/src/yelp-pager.c
index ea8b63e1..7b22ddcd 100644
--- a/src/yelp-pager.c
+++ b/src/yelp-pager.c
@@ -40,7 +40,7 @@ struct _YelpPagerPriv {
GError *error;
- GHashTable *chunk_hash;
+ GHashTable *page_hash;
};
enum {
@@ -51,7 +51,7 @@ enum {
enum {
START,
SECTIONS,
- CHUNK,
+ PAGE,
FINISH,
CANCEL,
ERROR,
@@ -134,8 +134,8 @@ pager_class_init (YelpPagerClass *klass)
yelp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- signals[CHUNK] = g_signal_new
- ("chunk",
+ signals[PAGE] = g_signal_new
+ ("page",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST, 0,
NULL, NULL,
@@ -180,8 +180,11 @@ pager_init (YelpPager *pager)
pager->priv->state = YELP_PAGER_STATE_NEW;
pager->priv->error = NULL;
- pager->priv->chunk_hash =
- g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ pager->priv->page_hash =
+ g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) yelp_page_free);
}
static void
@@ -231,7 +234,7 @@ pager_dispose (GObject *object)
if (pager->priv->error)
g_error_free (pager->priv->error);
- g_hash_table_destroy (pager->priv->chunk_hash);
+ g_hash_table_destroy (pager->priv->page_hash);
g_free (pager->priv);
@@ -243,8 +246,6 @@ pager_dispose (GObject *object)
gboolean
yelp_pager_start (YelpPager *pager)
{
- GError *error = NULL;
-
g_return_val_if_fail (pager != NULL, FALSE);
g_return_val_if_fail (YELP_IS_PAGER (pager), FALSE);
@@ -341,47 +342,68 @@ yelp_pager_get_sections (YelpPager *pager)
return YELP_PAGER_GET_CLASS (pager)->get_sections (pager);
}
-const gchar *
-yelp_pager_lookup_chunk (YelpPager *pager, YelpURI *uri)
+const YelpPage *
+yelp_pager_lookup_page (YelpPager *pager, YelpURI *uri)
{
- gchar *chunk_id = NULL;
- gchar *chunk;
+ gchar *page_id = NULL;
+ YelpPage *page;
g_return_val_if_fail (pager != NULL, NULL);
g_return_val_if_fail (YELP_IS_PAGER (pager), NULL);
- chunk_id = (gchar *) (YELP_PAGER_GET_CLASS (pager)->resolve_uri (pager, uri));
+ page_id = (gchar *) (YELP_PAGER_GET_CLASS (pager)->resolve_uri (pager, uri));
- if (chunk_id)
- chunk_id = g_strdup (chunk_id);
+ if (page_id)
+ page_id = g_strdup (page_id);
else
- chunk_id = yelp_uri_get_fragment (uri);
+ page_id = yelp_uri_get_fragment (uri);
- chunk = (gchar *) yelp_pager_get_chunk (pager, chunk_id);
+ page = (YelpPage *) yelp_pager_get_page (pager, page_id);
- g_free (chunk_id);
+ g_free (page_id);
- return (const gchar *) chunk;
+ return (const YelpPage *) page;
}
-const gchar *
-yelp_pager_get_chunk (YelpPager *pager, gchar *id)
+const YelpPage *
+yelp_pager_get_page (YelpPager *pager, gchar *id)
{
- gchar *chunk;
+ YelpPage *page;
g_return_val_if_fail (pager != NULL, NULL);
g_return_val_if_fail (YELP_IS_PAGER (pager), NULL);
- chunk = (gchar *) g_hash_table_lookup (pager->priv->chunk_hash, id);
+ page = (YelpPage *) g_hash_table_lookup (pager->priv->page_hash, id);
- return (const gchar *) chunk;
+ return (const YelpPage *) page;
}
void
-yelp_pager_add_chunk (YelpPager *pager, gchar *id, gchar *chunk)
+yelp_pager_add_page (YelpPager *pager,
+ gchar *id,
+ gchar *title,
+ gchar *chunk)
{
+ YelpPage *page;
+
g_return_if_fail (pager != NULL);
g_return_if_fail (YELP_IS_PAGER (pager));
- g_hash_table_insert (pager->priv->chunk_hash, id, chunk);
+ page = g_new0 (YelpPage, 1);
+
+ page->id = id;
+ page->title = title;
+ page->chunk = chunk;
+
+ g_hash_table_insert (pager->priv->page_hash, id, page);
+}
+
+void
+yelp_page_free (YelpPage *page)
+{
+ g_free (page->id);
+ g_free (page->title);
+ g_free (page->chunk);
+
+ g_free (page);
}
diff --git a/src/yelp-pager.h b/src/yelp-pager.h
index 0b647c3a..6e67ea56 100644
--- a/src/yelp-pager.h
+++ b/src/yelp-pager.h
@@ -37,6 +37,7 @@
typedef struct _YelpPager YelpPager;
typedef struct _YelpPagerClass YelpPagerClass;
typedef struct _YelpPagerPriv YelpPagerPriv;
+typedef struct _YelpPage YelpPage;
typedef enum {
YELP_PAGER_STATE_NEW,
@@ -61,7 +62,12 @@ struct _YelpPagerClass {
const gchar * (*resolve_uri) (YelpPager *pager,
YelpURI *uri);
const GtkTreeModel * (*get_sections) (YelpPager *pager);
-
+};
+
+struct _YelpPage {
+ gchar *id;
+ gchar *title;
+ gchar *chunk;
};
GType yelp_pager_get_type (void);
@@ -81,12 +87,15 @@ void yelp_pager_error (YelpPager *pager,
const GtkTreeModel * yelp_pager_get_sections (YelpPager *pager);
-const gchar * yelp_pager_lookup_chunk (YelpPager *pager,
+const YelpPage * yelp_pager_lookup_page (YelpPager *pager,
YelpURI *uri);
-const gchar * yelp_pager_get_chunk (YelpPager *pager,
+const YelpPage * yelp_pager_get_page (YelpPager *pager,
gchar *id);
-void yelp_pager_add_chunk (YelpPager *pager,
+void yelp_pager_add_page (YelpPager *pager,
gchar *id,
+ gchar *title,
gchar *chunk);
+void yelp_page_free (YelpPage *page);
+
#endif /* __YELP_PAGER_H__ */
diff --git a/src/yelp-window.c b/src/yelp-window.c
index c7a32422..52bfbf26 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -76,9 +76,11 @@ 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,
+ YelpURI *uri);
-static void pager_chunk_cb (YelpPager *pager,
- gchar *chunk_id,
+static void pager_page_cb (YelpPager *pager,
+ gchar *page_id,
gpointer user_data);
static void pager_sections_cb (YelpPager *pager,
gpointer user_data);
@@ -170,7 +172,7 @@ struct _YelpWindowPriv {
YelpHistory *history;
YelpPager *pager;
- gulong chunk_handler;
+ gulong page_handler;
gulong sections_handler;
GtkItemFactory *item_factory;
@@ -571,12 +573,19 @@ window_handle_uri (YelpWindow *window,
handled = window_handle_pager_uri (window, uri);
break;
case YELP_URI_TYPE_DOCBOOK_SGML:
- // FIXME: Error out
+ g_set_error (&error,
+ YELP_ERROR,
+ YELP_ERROR_NO_SGML,
+ _("DocBook SGML documents are no longer supported."));
+
+ window_error (window, error);
+ return FALSE;
+ case YELP_URI_TYPE_TOC:
+ handled = window_handle_toc_uri (window, uri);
break;
case YELP_URI_TYPE_HTML:
case YELP_URI_TYPE_GHELP:
case YELP_URI_TYPE_GHELP_OTHER:
- case YELP_URI_TYPE_TOC:
case YELP_URI_TYPE_INDEX:
case YELP_URI_TYPE_PATH:
case YELP_URI_TYPE_FILE:
@@ -601,16 +610,16 @@ window_handle_pager_uri (YelpWindow *window,
gboolean loadnow = FALSE;
gboolean startnow = TRUE;
gchar *path;
- gchar *chunk = NULL;
+ YelpPage *page = NULL;
YelpPager *pager;
priv = window->priv;
// Disconnect signal handlers
- if (priv->chunk_handler) {
+ if (priv->page_handler) {
g_signal_handler_disconnect (priv->pager,
- priv->chunk_handler);
- priv->chunk_handler = 0;
+ priv->page_handler);
+ priv->page_handler = 0;
}
if (priv->sections_handler) {
g_signal_handler_disconnect (priv->pager,
@@ -650,8 +659,8 @@ window_handle_pager_uri (YelpWindow *window,
switch (yelp_pager_get_state (pager)) {
case YELP_PAGER_STATE_START:
- chunk = (gchar *) yelp_pager_lookup_chunk (pager, uri);
- loadnow = (chunk ? TRUE : FALSE);
+ page = (YelpPage *) yelp_pager_lookup_page (pager, uri);
+ loadnow = (page ? TRUE : FALSE);
startnow = FALSE;
break;
case YELP_PAGER_STATE_NEW:
@@ -660,7 +669,7 @@ window_handle_pager_uri (YelpWindow *window,
startnow = TRUE;
break;
case YELP_PAGER_STATE_FINISH:
- chunk = (gchar *) yelp_pager_lookup_chunk (pager, uri);
+ page = (YelpPage *) yelp_pager_lookup_page (pager, uri);
loadnow = TRUE;
break;
case YELP_PAGER_STATE_ERROR:
@@ -673,10 +682,29 @@ window_handle_pager_uri (YelpWindow *window,
}
if (!loadnow) {
- priv->chunk_handler =
+ gchar *loading = _("Loading...");
+ yelp_html_clear (priv->html_view);
+
+ gtk_window_set_title (GTK_WINDOW (window),
+ (const gchar *) loading);
+
+ yelp_html_printf
+ (priv->html_view,
+ "<html><head><meta http-equiv='Content-Type'"
+ " content='text/html=; charset=utf-8'>"
+ "<title>%s</title></head>"
+ "<body><center>%s</center></body>"
+ "</html>",
+ loading, loading);
+ yelp_html_close (priv->html_view);
+
+ while (gtk_events_pending ())
+ gtk_main_iteration ();
+
+ priv->page_handler =
g_signal_connect (pager,
- "chunk",
- G_CALLBACK (pager_chunk_cb),
+ "page",
+ G_CALLBACK (pager_page_cb),
window);
priv->sections_handler =
g_signal_connect (pager,
@@ -687,7 +715,7 @@ window_handle_pager_uri (YelpWindow *window,
if (startnow)
yelp_pager_start (pager);
} else {
- if (!chunk) {
+ if (!page) {
gchar *str_uri = yelp_uri_to_string (uri);
g_set_error (&error,
YELP_ERROR,
@@ -702,45 +730,81 @@ window_handle_pager_uri (YelpWindow *window,
window_set_sections (window,
GTK_TREE_MODEL (yelp_pager_get_sections (pager)));
- yelp_html_clear (window->priv->html_view);
- yelp_html_set_base_uri (window->priv->html_view, uri);
- yelp_html_write (window->priv->html_view,
- chunk, strlen (chunk));
+ yelp_html_clear (priv->html_view);
+ yelp_html_set_base_uri (priv->html_view, uri);
+
+ gtk_window_set_title (GTK_WINDOW (window),
+ (const gchar *) page->title);
+
+ yelp_html_write (priv->html_view,
+ page->chunk,
+ strlen (page->chunk));
}
return TRUE;
}
+static gboolean
+window_handle_toc_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;
+ }
+ if (priv->sections_handler) {
+ g_signal_handler_disconnect (priv->pager,
+ priv->sections_handler);
+ priv->sections_handler = 0;
+ }
+
+ gchar *str_uri = yelp_uri_to_string (uri);
+ printf ("::: %s\n", str_uri);
+ g_free (str_uri);
+ return FALSE;
+}
+
static void
-pager_chunk_cb (YelpPager *pager,
- gchar *chunk_id,
- gpointer user_data)
+pager_page_cb (YelpPager *pager,
+ gchar *page_id,
+ gpointer user_data)
{
YelpWindow *window = YELP_WINDOW (user_data);
YelpURI *uri;
gchar *frag;
- gchar *chunk;
+ 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 (chunk_id, "index")) ||
- (!strcmp (frag, chunk_id)) )) {
+ ( (frag == NULL && !strcmp (page_id, "index")) ||
+ (!strcmp (frag, page_id)) )) {
- if (window->priv->chunk_handler) {
+ if (window->priv->page_handler) {
g_signal_handler_disconnect (window->priv->pager,
- window->priv->chunk_handler);
- window->priv->chunk_handler = 0;
+ window->priv->page_handler);
+ window->priv->page_handler = 0;
}
- chunk = (gchar *) yelp_pager_get_chunk (pager, chunk_id);
- yelp_html_clear (window->priv->html_view);
+ page = (YelpPage *) yelp_pager_get_page (pager, page_id);
+ yelp_html_clear (window->priv->html_view);
yelp_html_set_base_uri (window->priv->html_view, uri);
+ gtk_window_set_title (GTK_WINDOW (window),
+ (const gchar *) page->title);
+
yelp_html_write (window->priv->html_view,
- chunk, strlen (chunk));
+ page->chunk,
+ strlen (page->chunk));
}
g_free (frag);
@@ -748,7 +812,7 @@ pager_chunk_cb (YelpPager *pager,
static void
pager_sections_cb (YelpPager *pager,
- gpointer user_data)
+ gpointer user_data)
{
YelpWindow *window = YELP_WINDOW (user_data);
YelpURI *uri;