summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2003-11-19 01:25:38 +0000
committerShaun McCance <shaunm@src.gnome.org>2003-11-19 01:25:38 +0000
commit7f3c3a6111c2e5aba10a18c6f94758005c94558f (patch)
tree0cd8e708618810c871923a8eea22474484ab272f
parente94b13f502a61242a2e949b546d689ef1b18e6ac (diff)
downloadyelp-7f3c3a6111c2e5aba10a18c6f94758005c94558f.tar.gz
- Implement pausing of the TocPager. - Add default handlers for error,
* src/yelp-db-pager.c: * src/yelp-pager.c: * src/yelp-pager.h: - Implement pausing of the TocPager. - Add default handlers for error, cancel, and finish. * src/yelp-toc-pager.c: * src/yelp-toc-pager.h: - Implement pausing of the TocPager. - More work on reading OMF files. * src/yelp-window.c: - Implement pausing of the TocPager.
-rw-r--r--ChangeLog16
-rw-r--r--src/yelp-db-pager.c28
-rw-r--r--src/yelp-pager.c9
-rw-r--r--src/yelp-pager.h5
-rw-r--r--src/yelp-toc-pager.c99
-rw-r--r--src/yelp-toc-pager.h5
-rw-r--r--src/yelp-window.c3
7 files changed, 144 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 1b041c00..cf27e233 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2003-11-18 Shaun McCance <shaunm@gnome.org>
+
+ * src/yelp-db-pager.c:
+ * src/yelp-pager.c:
+ * src/yelp-pager.h:
+ - Implement pausing of the TocPager.
+ - Add default handlers for error, cancel, and finish.
+
+ * src/yelp-toc-pager.c:
+ * src/yelp-toc-pager.h:
+ - Implement pausing of the TocPager.
+ - More work on reading OMF files.
+
+ * src/yelp-window.c:
+ - Implement pausing of the TocPager.
+
2003-11-17 Shaun McCance <shaunm@gnome.org>
* src/yelp-toc-pager.c:
diff --git a/src/yelp-db-pager.c b/src/yelp-db-pager.c
index f06ae317..b10c3caf 100644
--- a/src/yelp-db-pager.c
+++ b/src/yelp-db-pager.c
@@ -36,6 +36,7 @@
#include <libxslt/xsltutils.h>
#include "yelp-db-pager.h"
+#include "yelp-toc-pager.h"
#define YELP_NAMESPACE "http://www.gnome.org/yelp/ns"
@@ -69,8 +70,11 @@ static void db_pager_class_init (YelpDBPagerClass *klass);
static void db_pager_init (YelpDBPager *pager);
static void db_pager_dispose (GObject *gobject);
-gboolean db_pager_process (YelpPager *pager);
+void db_pager_error (YelpPager *pager);
void db_pager_cancel (YelpPager *pager);
+void db_pager_finish (YelpPager *pager);
+
+gboolean db_pager_process (YelpPager *pager);
gchar * db_pager_resolve_uri (YelpPager *pager,
YelpURI *uri);
const GtkTreeModel * db_pager_get_sections (YelpPager *pager);
@@ -127,8 +131,11 @@ db_pager_class_init (YelpDBPagerClass *klass)
object_class->dispose = db_pager_dispose;
- pager_class->process = db_pager_process;
+ pager_class->error = db_pager_error;
pager_class->cancel = db_pager_cancel;
+ pager_class->finish = db_pager_finish;
+
+ pager_class->process = db_pager_process;
pager_class->resolve_uri = db_pager_resolve_uri;
pager_class->get_sections = db_pager_get_sections;
}
@@ -202,6 +209,8 @@ db_pager_process (YelpPager *pager)
g_object_ref (pager);
+ yelp_toc_pager_pause (yelp_toc_pager_get ());
+
ctxt = xmlCreateFileParserCtxt (uri_str);
ctxt->replaceEntities = TRUE;
ctxt->validate = FALSE;
@@ -283,9 +292,22 @@ db_pager_process (YelpPager *pager)
}
void
+db_pager_error (YelpPager *pager)
+{
+ yelp_toc_pager_unpause (yelp_toc_pager_get ());
+}
+
+void
db_pager_cancel (YelpPager *pager)
{
- // FIXME
+ yelp_toc_pager_unpause (yelp_toc_pager_get ());
+ // FIXME: actually cancel
+}
+
+void
+db_pager_finish (YelpPager *pager)
+{
+ yelp_toc_pager_unpause (yelp_toc_pager_get ());
}
gchar *
diff --git a/src/yelp-pager.c b/src/yelp-pager.c
index bbdb6b08..3a0aee82 100644
--- a/src/yelp-pager.c
+++ b/src/yelp-pager.c
@@ -137,7 +137,8 @@ pager_class_init (YelpPagerClass *klass)
signals[FINISH] = g_signal_new
("finish",
G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST, 0,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (YelpPagerClass, finish),
NULL, NULL,
yelp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -145,7 +146,8 @@ pager_class_init (YelpPagerClass *klass)
signals[CANCEL] = g_signal_new
("cancel",
G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST, 0,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (YelpPagerClass, cancel),
NULL, NULL,
yelp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
@@ -153,7 +155,8 @@ pager_class_init (YelpPagerClass *klass)
signals[ERROR] = g_signal_new
("error",
G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST, 0,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (YelpPagerClass, error),
NULL, NULL,
yelp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
diff --git a/src/yelp-pager.h b/src/yelp-pager.h
index d5a756ac..6da01e0f 100644
--- a/src/yelp-pager.h
+++ b/src/yelp-pager.h
@@ -56,9 +56,12 @@ struct _YelpPager {
struct _YelpPagerClass {
GObjectClass parent_class;
+ void (*error) (YelpPager *pager);
+ void (*cancel) (YelpPager *pager);
+ void (*finish) (YelpPager *pager);
+
/* Virtual Functions */
gboolean (*process) (YelpPager *pager);
- void (*cancel) (YelpPager *pager);
gchar * (*resolve_uri) (YelpPager *pager,
YelpURI *uri);
const GtkTreeModel * (*get_sections) (YelpPager *pager);
diff --git a/src/yelp-toc-pager.c b/src/yelp-toc-pager.c
index 97540a7a..be2f29db 100644
--- a/src/yelp-toc-pager.c
+++ b/src/yelp-toc-pager.c
@@ -45,14 +45,18 @@ struct _YelpTocPagerPriv {
GHashTable *category_hash;
xmlParserCtxtPtr parser;
+
+ gint pause_count;
+ GtkFunction unpause_func;
};
struct _OMF {
xmlChar *title;
xmlChar *description;
+ xmlChar *seriesid;
xmlChar *language;
- gint lang_priority;
+ gint lang_priority;
xmlChar *omf_file;
xmlChar *xml_file;
@@ -130,6 +134,9 @@ toc_pager_init (YelpTocPager *pager)
priv->seriesid_hash = g_hash_table_new (g_str_hash, g_str_equal);
priv->category_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ priv->pause_count = 0;
+ priv->unpause_func = NULL;
}
static void
@@ -152,10 +159,29 @@ yelp_toc_pager_init (void)
yelp_pager_start (YELP_PAGER (toc_pager));
}
-YelpPager *
+YelpTocPager *
yelp_toc_pager_get (void)
{
- return (YelpPager *) toc_pager;
+ return toc_pager;
+}
+
+void
+yelp_toc_pager_pause (YelpTocPager *pager)
+{
+ pager->priv->pause_count = pager->priv->pause_count + 1;
+}
+
+void
+yelp_toc_pager_unpause (YelpTocPager *pager)
+{
+ pager->priv->pause_count = pager->priv->pause_count - 1;
+
+ if (pager->priv->pause_count < 1 && pager->priv->unpause_func) {
+ gtk_idle_add_priority (G_PRIORITY_LOW,
+ pager->priv->unpause_func,
+ pager);
+ pager->priv->unpause_func = NULL;
+ }
}
/******************************************************************************/
@@ -165,8 +191,9 @@ toc_pager_process (YelpPager *pager)
{
toc_read_omf_dir (YELP_TOC_PAGER (pager), DATADIR"/omf");
- gtk_idle_add ((GtkFunction) toc_process_pending,
- pager);
+ gtk_idle_add_priority (G_PRIORITY_LOW,
+ (GtkFunction) toc_process_pending,
+ pager);
return FALSE;
}
@@ -243,9 +270,10 @@ toc_process_pending (YelpPager *pager)
xmlDocPtr omf_doc;
xmlNodePtr omf_cur;
gint lang_priority;
- OMF *omf = NULL;
+ OMF *omf = NULL;
+ OMF *omf_old = NULL;
+ GList *langs;
- const GList *langs = gnome_i18n_get_language_list ("LC_MESSAGES");
YelpTocPagerPriv *priv = YELP_TOC_PAGER (pager)->priv;
first = priv->omf_pending;
@@ -290,14 +318,27 @@ toc_process_pending (YelpPager *pager)
omf->description = xmlNodeGetContent (omf_cur);
continue;
}
+ if (!xmlStrcmp (omf_cur->name, (xmlChar *) "relation")) {
+ xmlChar *seriesid =
+ xmlGetProp (omf_cur, (const xmlChar *) "seriesid");
+
+ if (seriesid) {
+ if (omf->seriesid)
+ xmlFree (omf->seriesid);
+ omf->seriesid = seriesid;
+ }
+ }
if (!xmlStrcmp (omf_cur->name, (xmlChar *) "language")) {
if (omf->language)
xmlFree (omf->language);
omf->language = xmlGetProp (omf_cur, (const xmlChar *) "code");
+ /* The lang_priority of an OMF file is how early it appears in the
+ * list of preferred languages for the user. Low numbers are best.
+ */
lang_priority = 0;
-
- for (; langs != NULL; langs = langs->next) {
+ langs = (GList *) gnome_i18n_get_language_list ("LC_MESSAGES");
+ for ( ; langs != NULL; langs = langs->next) {
gchar *lang = langs->data;
lang_priority++;
@@ -311,7 +352,9 @@ toc_process_pending (YelpPager *pager)
}
if (!omf->lang_priority) {
- // Not a language we want to display
+ /* If the language didn't match a user-preferred language,
+ * omf->lang_priority doesn't get set, so is 0.
+ */
omf_free (omf);
goto done;
}
@@ -323,15 +366,45 @@ toc_process_pending (YelpPager *pager)
}
}
+ /* If we have one with the same seriesid, use the one with
+ * the lowest lang_priority.
+ */
+ omf_old = g_hash_table_lookup (priv->seriesid_hash, omf->seriesid);
+ if (omf_old) {
+ if (omf_old->lang_priority < omf->lang_priority) {
+ omf_free (omf);
+ goto done;
+ } else {
+ printf ("replacing %s with %s\n",
+ omf_old->omf_file,
+ omf->omf_file);
+ g_hash_table_insert (priv->seriesid_hash,
+ omf->seriesid,
+ omf);
+ omf_free (omf_old);
+ }
+ } else {
+ g_hash_table_insert (priv->seriesid_hash,
+ omf->seriesid,
+ omf);
+ }
+
+ // priv->seriesid_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ // priv->category_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
done:
xmlFreeDoc (omf_doc);
g_free (file);
g_slist_free_1 (first);
- if (priv->omf_pending)
- return TRUE;
- else
+ if (!priv->omf_pending)
+ return FALSE;
+ else if (priv->pause_count > 0) {
+ priv->unpause_func = (GtkFunction) toc_process_pending;
return FALSE;
+ }
+ else
+ return TRUE;
}
static void
diff --git a/src/yelp-toc-pager.h b/src/yelp-toc-pager.h
index 16130530..2bbe2b8a 100644
--- a/src/yelp-toc-pager.h
+++ b/src/yelp-toc-pager.h
@@ -51,6 +51,9 @@ struct _YelpTocPagerClass {
GType yelp_toc_pager_get_type (void);
void yelp_toc_pager_init (void);
-YelpPager * yelp_toc_pager_get (void);
+YelpTocPager * yelp_toc_pager_get (void);
+
+void yelp_toc_pager_pause (YelpTocPager *pager);
+void yelp_toc_pager_unpause (YelpTocPager *pager);
#endif /* __YELP_TOC_PAGER_H__ */
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 4a239430..4fd38caf 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -44,6 +44,7 @@
#include "yelp-html.h"
#include "yelp-pager.h"
#include "yelp-section.h"
+#include "yelp-toc-pager.h"
#include "yelp-util.h"
#include "yelp-window.h"
@@ -704,8 +705,10 @@ window_handle_pager_uri (YelpWindow *window,
loading, loading);
yelp_html_close (priv->html_view);
+ yelp_toc_pager_pause (yelp_toc_pager_get ());
while (gtk_events_pending ())
gtk_main_iteration ();
+ yelp_toc_pager_unpause (yelp_toc_pager_get ());
priv->page_handler =
g_signal_connect (pager,