summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@src.gnome.org>2003-11-23 20:58:02 +0000
committerShaun McCance <shaunm@src.gnome.org>2003-11-23 20:58:02 +0000
commitcbf8860d93b960920733a98a5bc230952a0da1c3 (patch)
tree8a670992ea22cdda404f565f09faee684787b086
parent20f553af8f108491ce4a694b4a2d46b0eef60c39 (diff)
downloadyelp-cbf8860d93b960920733a98a5bc230952a0da1c3.tar.gz
- Add yelp-error.[ch] to SOURCES for test-pager.
* src/Makefile.am: - Add yelp-error.[ch] to SOURCES for test-pager. * src/yelp-error.h: - Add YELP_ERROR_FAILED_TOC. * src/yelp-pager.c: - Don't free memory you're not supposed to, dummy. * src/yelp-toc-pager.c: - More work on the toc generation. * src/yelp-window.c: - Make sidebar selection work. - Remove huge block of commented-out code.
-rw-r--r--ChangeLog18
-rw-r--r--src/Makefile.am4
-rw-r--r--src/yelp-error.h1
-rw-r--r--src/yelp-pager.c2
-rw-r--r--src/yelp-toc-pager.c115
-rw-r--r--src/yelp-window.c286
6 files changed, 149 insertions, 277 deletions
diff --git a/ChangeLog b/ChangeLog
index d62455ab..5773f185 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2003-11-12 Shaun McCance <shaunm@gnome.org>
+
+ * src/Makefile.am:
+ - Add yelp-error.[ch] to SOURCES for test-pager.
+
+ * src/yelp-error.h:
+ - Add YELP_ERROR_FAILED_TOC.
+
+ * src/yelp-pager.c:
+ - Don't free memory you're not supposed to, dummy.
+
+ * src/yelp-toc-pager.c:
+ - More work on the toc generation.
+
+ * src/yelp-window.c:
+ - Make sidebar selection work.
+ - Remove huge block of commented-out code.
+
2003-11-19 Shaun McCance <shaunm@gnome.org>
* src/yelp-toc-pager.c:
diff --git a/src/Makefile.am b/src/Makefile.am
index 95489bd7..782eb329 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,12 +27,12 @@ test_uri_LDADD = \
@YELP_LIBS@
test_pager_SOURCES = \
- test-pager.c \
+ yelp-error.c yelp-error.h \
yelp-pager.c yelp-pager.h \
yelp-db-pager.c yelp-db-pager.h \
yelp-toc-pager.c yelp-toc-pager.h \
yelp-uri.c yelp-uri.h \
- yelp-marshal-main.c
+ yelp-marshal-main.c test-pager.c
test_pager_LDADD = \
@DB2HTML_LIBS@ @YELP_LIBS@ -lexslt
diff --git a/src/yelp-error.h b/src/yelp-error.h
index afa7147e..13181598 100644
--- a/src/yelp-error.h
+++ b/src/yelp-error.h
@@ -29,6 +29,7 @@ typedef enum {
YELP_ERROR_URI_NOT_EXIST,
YELP_ERROR_DOCBOOK_2_HTML,
YELP_ERROR_FAILED_OPEN,
+ YELP_ERROR_FAILED_TOC,
YELP_ERROR_NO_SGML
} YelpError;
diff --git a/src/yelp-pager.c b/src/yelp-pager.c
index 3a0aee82..79433bed 100644
--- a/src/yelp-pager.c
+++ b/src/yelp-pager.c
@@ -349,6 +349,8 @@ yelp_pager_lookup_page (YelpPager *pager, YelpURI *uri)
if (!page_id)
page_id = yelp_uri_get_fragment (uri);
+ else
+ page_id = g_strdup (page_id);
page = (YelpPage *) yelp_pager_get_page (pager, page_id);
diff --git a/src/yelp-toc-pager.c b/src/yelp-toc-pager.c
index 8d36b17b..9ee5e228 100644
--- a/src/yelp-toc-pager.c
+++ b/src/yelp-toc-pager.c
@@ -31,6 +31,7 @@
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
+#include "yelp-error.h"
#include "yelp-toc-pager.h"
#define d(x)
@@ -40,7 +41,7 @@ typedef struct _OMF OMF;
struct _YelpTocPagerPriv {
GSList *omf_pending;
- GSList *menu_pending;
+ GSList *toc_pending;
GHashTable *unique_hash_omf;
GHashTable *category_hash_omf;
@@ -67,28 +68,28 @@ struct _OMF {
xmlChar *xml_file;
};
-static void toc_pager_class_init (YelpTocPagerClass *klass);
-static void toc_pager_init (YelpTocPager *pager);
-static void toc_pager_dispose (GObject *gobject);
+static void toc_pager_class_init (YelpTocPagerClass *klass);
+static void toc_pager_init (YelpTocPager *pager);
+static void toc_pager_dispose (GObject *gobject);
-gboolean toc_pager_process (YelpPager *pager);
-void toc_pager_cancel (YelpPager *pager);
-gchar * toc_pager_resolve_uri (YelpPager *pager,
- YelpURI *uri);
-const GtkTreeModel * toc_pager_get_sections (YelpPager *pager);
+gboolean toc_pager_process (YelpPager *pager);
+void toc_pager_cancel (YelpPager *pager);
+gchar * toc_pager_resolve_uri (YelpPager *pager,
+ YelpURI *uri);
+const GtkTreeModel * toc_pager_get_sections (YelpPager *pager);
-static void toc_read_omf_dir (YelpTocPager *pager,
- const gchar *dirstr);
-static gboolean toc_process_pending (YelpPager *pager);
-static void toc_hash_omf (YelpTocPager *pager,
- OMF *omf);
-static void toc_unhash_omf (YelpTocPager *pager,
- OMF *omf);
+static void toc_read_omf_dir (YelpTocPager *pager,
+ const gchar *dirstr);
+static gboolean toc_process_omf_pending (YelpPager *pager);
+static void toc_hash_omf (YelpTocPager *pager,
+ OMF *omf);
+static void toc_unhash_omf (YelpTocPager *pager,
+ OMF *omf);
-static gboolean toc_process_menu (YelpTocPager *pager);
-static gboolean toc_process_page (YelpTocPager *pager);
+static gboolean toc_process_toc (YelpTocPager *pager);
+static gboolean toc_process_toc_pending (YelpTocPager *pager);
-static void omf_free (OMF *omf);
+static void omf_free (OMF *omf);
static YelpPagerClass *parent_class;
@@ -209,7 +210,7 @@ toc_pager_process (YelpPager *pager)
toc_read_omf_dir (YELP_TOC_PAGER (pager), DATADIR"/omf");
gtk_idle_add_priority (G_PRIORITY_LOW,
- (GtkFunction) toc_process_pending,
+ (GtkFunction) toc_process_omf_pending,
pager);
return FALSE;
}
@@ -280,7 +281,7 @@ toc_read_omf_dir (YelpTocPager *pager, const gchar *dirstr)
}
static gboolean
-toc_process_pending (YelpPager *pager)
+toc_process_omf_pending (YelpPager *pager)
{
GSList *first;
gchar *file;
@@ -430,15 +431,15 @@ toc_process_pending (YelpPager *pager)
if (!priv->omf_pending) {
if (priv->pause_count > 0)
- priv->unpause_func = (GtkFunction) toc_process_menu;
+ priv->unpause_func = (GtkFunction) toc_process_toc;
else
gtk_idle_add_priority (G_PRIORITY_LOW,
- (GtkFunction) toc_process_menu,
+ (GtkFunction) toc_process_toc,
pager);
return FALSE;
}
if (priv->pause_count > 0) {
- priv->unpause_func = (GtkFunction) toc_process_pending;
+ priv->unpause_func = (GtkFunction) toc_process_omf_pending;
return FALSE;
}
else
@@ -446,28 +447,80 @@ toc_process_pending (YelpPager *pager)
}
static gboolean
-toc_process_menu (YelpTocPager *pager)
+toc_process_toc (YelpTocPager *pager)
{
- printf ("toc_process_menu\n");
+ 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);
+
+ if (!toc_doc) {
+ g_set_error (&error,
+ YELP_ERROR,
+ YELP_ERROR_FAILED_TOC,
+ _("The table of contents could not be read."));
+ yelp_pager_error (YELP_PAGER (pager), error);
+ return FALSE;
+ }
+
+ toc_node = xmlDocGetRootElement (toc_doc);
+
+ if (!xmlStrcmp (toc_node->name, "toc")) {
+ g_set_error (&error,
+ YELP_ERROR,
+ YELP_ERROR_FAILED_TOC,
+ _("The table of contents could not be read."));
+ yelp_pager_error (YELP_PAGER (pager), error);
+ return FALSE;
+ }
+
+ priv->toc_pending = g_slist_append (priv->toc_pending, toc_node);
gtk_idle_add_priority (G_PRIORITY_LOW,
- (GtkFunction) toc_process_page,
+ (GtkFunction) toc_process_toc_pending,
pager);
+
+ xmlFreeDoc (toc_doc);
return FALSE;
}
static gboolean
-toc_process_page (YelpTocPager *pager)
+toc_process_toc_pending (YelpTocPager *pager)
{
+ GSList *first;
+ xmlNodePtr node;
+ xmlNodePtr cur;
+ xmlChar *id;
+ gchar *url;
+
YelpTocPagerPriv *priv = pager->priv;
- printf ("toc_process_page\n");
+ first = priv->toc_pending;
+ priv->toc_pending = g_slist_remove_link (priv->toc_pending, first);
+
+ node = first->data;
+
+ id = xmlGetProp (node, (const xmlChar *) "id");
+ url = g_strconcat ("toc:", (gchar *) id, NULL);
+ xmlFree (id);
+
+ for (cur = node->children; cur; cur = cur->next) {
+ printf ("cur: %s\n", cur->name);
+ }
+
+ g_slist_free_1 (first);
- if (!priv->menu_pending) {
+ if (!priv->toc_pending) {
return FALSE;
}
else if (priv->pause_count > 0) {
- priv->unpause_func = (GtkFunction) toc_process_page;
+ priv->unpause_func = (GtkFunction) toc_process_toc_pending;
return FALSE;
}
else
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 4fd38caf..ec55ac7d 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -88,6 +88,8 @@ static void html_uri_selected_cb (YelpHtml *html,
YelpURI *uri,
gboolean handled,
gpointer user_data);
+static void tree_selection_changed_cb (GtkTreeSelection *selection,
+ YelpWindow *window);
static void window_new_window_cb (gpointer data,
guint section,
@@ -360,11 +362,12 @@ window_error (YelpWindow *window, GError *error)
static void
window_populate (YelpWindow *window)
{
- YelpWindowPriv *priv;
- GtkWidget *main_box;
- GtkWidget *toolbar;
- GtkAccelGroup *accel_group;
- GtkWidget *menu_item;
+ YelpWindowPriv *priv;
+ GtkWidget *main_box;
+ GtkWidget *toolbar;
+ GtkAccelGroup *accel_group;
+ GtkWidget *menu_item;
+ GtkTreeSelection *selection;
priv = window->priv;
@@ -428,6 +431,12 @@ window_populate (YelpWindow *window)
"text", 1,
NULL);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->side_sects));
+
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (tree_selection_changed_cb),
+ window);
+
gtk_container_add (GTK_CONTAINER (priv->side_sw), priv->side_sects);
gtk_paned_add1 (GTK_PANED (priv->pane), priv->side_sw);
@@ -819,6 +828,34 @@ html_uri_selected_cb (YelpHtml *html,
yelp_window_open_uri (window, uri);
}
+static void
+tree_selection_changed_cb (GtkTreeSelection *selection,
+ YelpWindow *window)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gchar *id, *frag;
+ YelpURI *uri;
+
+ YelpWindowPriv *priv = window->priv;
+
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->side_sects));
+
+ gtk_tree_model_get (model, &iter,
+ 0, &id,
+ -1);
+
+ frag = g_strconcat ("#", id, NULL);
+ uri = yelp_uri_new_relative
+ (yelp_window_get_current_uri (window), frag);
+
+ yelp_window_open_uri (window, uri);
+
+ g_free (frag);
+ }
+}
+
/******************************************************************************/
@@ -998,242 +1035,3 @@ window_history_action (YelpWindow *window,
}
}
-/***************************** FIXME below
-
-static void
-window_uri_selected_cb (gpointer view,
- YelpURI *uri,
- gboolean handled,
- YelpWindow *window)
-{
- YelpWindowPriv *priv;
-
- g_return_if_fail (YELP_IS_WINDOW (window));
-
- d(g_print ("uri_selected: %s, handled: %d\n",
- yelp_uri_to_string (uri), handled));
-
- priv = window->priv;
-
- yelp_uri_ref (uri);
-
- if (handled) {
- yelp_history_goto (priv->history, uri);
- } else {
- if (window_handle_uri (window, uri)) {
- yelp_history_goto (priv->history, uri);
- }
- }
-
- yelp_uri_unref (uri);
-}
-
-static void
-window_title_changed_cb (gpointer view, const gchar *title, YelpWindow *window)
-{
- gchar *new_title;
-
- g_return_if_fail (title != NULL);
- g_return_if_fail (YELP_IS_WINDOW (window));
-
- new_title = g_strconcat (title, " - ", _("Help Browser"), NULL);
-
- gtk_window_set_title (GTK_WINDOW (window), new_title);
-
- g_free (new_title);
-}
-
-
-
-
-
-static void
-window_index_button_clicked (GtkWidget *button, YelpWindow *window)
-{
- YelpURI *uri;
-
- g_return_if_fail (YELP_IS_WINDOW (window));
-
- uri = yelp_uri_new ("index:");
- yelp_history_goto (window->priv->history, uri);
- yelp_uri_unref (uri);
-
- gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
- PAGE_INDEX_VIEW);
-}
-
-
-static void
-window_find_cb (gpointer data, guint section, GtkWidget *widget)
-{
- YelpWindow *window = data;
- YelpWindowPriv *priv;
- GladeXML *glade;
-
- g_return_if_fail (YELP_IS_WINDOW (data));
-
- window = YELP_WINDOW (data);
-
- priv = window->priv;
-
- if (!priv->find_dialog) {
- glade = glade_xml_new (DATADIR "/yelp/ui/yelp.glade", "find_dialog", NULL);
- if (!glade) {
- g_warning ("Couldn't find necessary glade file " DATADIR "/yelp/ui/yelp.glade");
- return;
- }
-
- priv->find_dialog = glade_xml_get_widget (glade, "find_dialog");
-
- priv->find_entry = glade_xml_get_widget (glade, "find_entry");
- priv->case_checkbutton = glade_xml_get_widget (glade, "case_check");
- priv->wrap_checkbutton = glade_xml_get_widget (glade, "wrap_check");
-
- g_signal_connect (priv->find_dialog,
- "delete_event",
- G_CALLBACK (window_find_delete_event_cb),
- NULL);
-
- g_signal_connect (priv->find_dialog,
- "response",
- G_CALLBACK (window_find_response_cb),
- window);
-
- g_object_unref (glade);
- }
-
- gtk_window_present (GTK_WINDOW (priv->find_dialog));
-}
-
-static void
-window_find_again_cb (gpointer data, guint section, GtkWidget *widget)
-{
- YelpWindow *window = data;
- YelpWindowPriv *priv;
- YelpView *view;
- YelpHtml *html;
-
- g_return_if_fail (YELP_IS_WINDOW (data));
-
- window = YELP_WINDOW (data);
-
- priv = window->priv;
-
- if (priv->find_string) {
- view = window_get_active_view (window);
- html = yelp_view_get_html (view);
-
- yelp_html_find (html,
- priv->find_string,
- priv->match_case,
- priv->wrap,
- TRUE);
- }
-}
-
-static void
-window_history_go_cb (gpointer data, guint section, GtkWidget *widget)
-{
- window_history_action (data, section);
-}
-
-static void
-window_go_home_cb (gpointer data, guint section, GtkWidget *widget)
-{
- window_home_button_clicked (NULL, YELP_WINDOW (data));
-}
-
-static void
-window_go_index_cb (gpointer data, guint section, GtkWidget *widget)
-{
- window_index_button_clicked (NULL, YELP_WINDOW (data));
-}
-
-
-static gboolean
-window_find_delete_event_cb (GtkWidget *widget, gpointer user_data)
-{
- gtk_widget_hide (widget);
-
- return TRUE;
-}
-
-static void
-window_find_response_cb (GtkWidget *dialog ,
- gint response,
- YelpWindow *window)
-{
- YelpWindowPriv *priv;
- YelpView *view;
- YelpHtml *html;
- const gchar *tmp;
-
- priv = window->priv;
-
- view = window_get_active_view (window);
- html = yelp_view_get_html (view);
-
- switch (response) {
- case GTK_RESPONSE_CLOSE:
- gtk_widget_hide (dialog);
- break;
-
- case RESPONSE_PREV:
- case RESPONSE_NEXT:
- tmp = gtk_entry_get_text (GTK_ENTRY (priv->find_entry));
-
- priv->match_case = gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (priv->case_checkbutton));
-
- priv->wrap = gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (priv->wrap_checkbutton));
-
- g_free (priv->find_string);
-
- if (!priv->match_case) {
- priv->find_string = g_utf8_casefold (tmp, -1);
- } else {
- priv->find_string = g_strdup (tmp);
- }
-
- yelp_html_find (html,
- priv->find_string,
- priv->match_case,
- priv->wrap,
- response == RESPONSE_NEXT);
- break;
-
- default:
- break;
- }
-
-}
-
-static YelpView *
-window_get_active_view (YelpWindow *window)
-{
- YelpWindowPriv *priv;
-
- priv = window->priv;
-
- switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook))) {
- case PAGE_TOC_VIEW:
- return priv->toc_view;
- case PAGE_CONTENT_VIEW:
- return priv->content_view;
- case PAGE_INDEX_VIEW:
- return priv->index_view;
- break;
- default:
- g_assert_not_reached ();
- }
-
- return NULL;
-}
-
-
-
-
-
-
-**************************/