[yelp/yelp-3-0] [libyelp/yelp-view] Adding page title/desc to view, hooks in document
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp/yelp-3-0] [libyelp/yelp-view] Adding page title/desc to view, hooks in document
- Date: Fri, 12 Mar 2010 22:25:51 +0000 (UTC)
commit c869dc0ffee5a410963784ffa78d6e0d1a876eba
Author: Shaun McCance <shaunm gnome org>
Date: Fri Mar 12 11:27:25 2010 -0600
[libyelp/yelp-view] Adding page title/desc to view, hooks in document
libyelp/yelp-docbook-document.c | 7 +++++-
libyelp/yelp-document.c | 45 +++++++++++++++++++++++++++++++++----
libyelp/yelp-document.h | 10 ++++++-
libyelp/yelp-view.c | 46 +++++++++++++++++++++++++++++++++++++-
tests/test-view.c | 13 +++++++++++
5 files changed, 111 insertions(+), 10 deletions(-)
---
diff --git a/libyelp/yelp-docbook-document.c b/libyelp/yelp-docbook-document.c
index 028646e..669fb62 100644
--- a/libyelp/yelp-docbook-document.c
+++ b/libyelp/yelp-docbook-document.c
@@ -481,7 +481,7 @@ docbook_walk (YelpDocbookDocument *docbook)
debug_print (DB_DEBUG, " id: \"%s\"\n", id);
debug_print (DB_DEBUG, " title: \"%s\"\n", title);
- yelp_document_set_title (document, (gchar *) id, (gchar *) title);
+ yelp_document_set_page_title (document, (gchar *) id, (gchar *) title);
gdk_threads_enter ();
gtk_tree_store_append (GTK_TREE_STORE (priv->sections),
@@ -516,6 +516,11 @@ docbook_walk (YelpDocbookDocument *docbook)
if (id)
yelp_document_set_page_id (document, (gchar *) id, priv->cur_page_id);
+ yelp_document_signal (YELP_DOCUMENT (docbook),
+ priv->cur_page_id,
+ YELP_DOCUMENT_SIGNAL_INFO,
+ NULL);
+
for (cur = priv->xmlcur->children; cur; cur = cur->next) {
if (cur->type == XML_ELEMENT_NODE) {
priv->xmlcur = cur;
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index 899aae6..7427552 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -65,6 +65,7 @@ struct _YelpDocumentPriv {
*/
Hash *page_ids; /* Mapping of fragment IDs to real page IDs */
Hash *titles; /* Mapping of page IDs to titles */
+ Hash *descs; /* Mapping of page IDs to descs */
Hash *mime_types; /* Mapping of page IDs to mime types */
Hash *contents; /* Mapping of page IDs to string content */
@@ -223,6 +224,7 @@ yelp_document_init (YelpDocument *document)
priv->page_ids = hash_new (g_free );
priv->titles = hash_new (g_free);
+ priv->descs = hash_new (g_free);
priv->mime_types = hash_new (g_free);
priv->contents = hash_new ((GDestroyNotify) str_unref);
@@ -258,6 +260,7 @@ yelp_document_finalize (GObject *object)
hash_free (document->priv->page_ids);
hash_free (document->priv->titles);
+ hash_free (document->priv->descs);
hash_free (document->priv->mime_types);
hash_free (document->priv->contents);
@@ -450,8 +453,8 @@ yelp_document_set_up_id (YelpDocument *document,
}
gchar *
-yelp_document_get_title (YelpDocument *document,
- const gchar *page_id)
+yelp_document_get_page_title (YelpDocument *document,
+ const gchar *page_id)
{
gchar *real, *ret = NULL;
@@ -470,9 +473,9 @@ yelp_document_get_title (YelpDocument *document,
}
void
-yelp_document_set_title (YelpDocument *document,
- const gchar *page_id,
- const gchar *title)
+yelp_document_set_page_title (YelpDocument *document,
+ const gchar *page_id,
+ const gchar *title)
{
g_assert (document != NULL && YELP_IS_DOCUMENT (document));
@@ -481,6 +484,38 @@ yelp_document_set_title (YelpDocument *document,
g_mutex_unlock (document->priv->mutex);
}
+gchar *
+yelp_document_get_page_desc (YelpDocument *document,
+ const gchar *page_id)
+{
+ gchar *real, *ret = NULL;
+
+ g_assert (document != NULL && YELP_IS_DOCUMENT (document));
+
+ g_mutex_lock (document->priv->mutex);
+ real = hash_lookup (document->priv->page_ids, page_id);
+ if (real) {
+ ret = hash_lookup (document->priv->descs, real);
+ if (ret)
+ ret = g_strdup (ret);
+ }
+ g_mutex_unlock (document->priv->mutex);
+
+ return ret;
+}
+
+void
+yelp_document_set_page_desc (YelpDocument *document,
+ const gchar *page_id,
+ const gchar *desc)
+{
+ g_assert (document != NULL && YELP_IS_DOCUMENT (document));
+
+ g_mutex_lock (document->priv->mutex);
+ hash_replace (document->priv->descs, page_id, g_strdup (desc));
+ g_mutex_unlock (document->priv->mutex);
+}
+
/******************************************************************************/
gboolean
diff --git a/libyelp/yelp-document.h b/libyelp/yelp-document.h
index 8a6feae..e71e673 100644
--- a/libyelp/yelp-document.h
+++ b/libyelp/yelp-document.h
@@ -126,12 +126,18 @@ void yelp_document_set_up_id (YelpDocument *document,
const gchar *page_id,
const gchar *up_id);
-gchar * yelp_document_get_title (YelpDocument *document,
+gchar * yelp_document_get_page_title (YelpDocument *document,
const gchar *page_id);
-void yelp_document_set_title (YelpDocument *document,
+void yelp_document_set_page_title (YelpDocument *document,
const gchar *page_id,
const gchar *title);
+gchar * yelp_document_get_page_desc (YelpDocument *document,
+ const gchar *page_id);
+void yelp_document_set_page_desc (YelpDocument *document,
+ const gchar *page_id,
+ const gchar *desc);
+
gboolean yelp_document_has_page (YelpDocument *document,
const gchar *page_id);
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index e3c8501..7059ba0 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -81,7 +81,9 @@ static void document_callback (YelpDocument *document,
enum {
PROP_0,
- PROP_STATE
+ PROP_STATE,
+ PROP_PAGE_TITLE,
+ PROP_PAGE_DESC
};
enum {
@@ -103,6 +105,9 @@ struct _YelpViewPrivate {
YelpViewState state;
+ gchar *page_title;
+ gchar *page_desc;
+
gint navigation_requested;
};
@@ -162,6 +167,9 @@ yelp_view_finalize (GObject *object)
{
YelpViewPrivate *priv = GET_PRIV (object);
+ g_free (priv->page_title);
+ g_free (priv->page_desc);
+
g_free (priv->bogus_uri);
G_OBJECT_CLASS (yelp_view_parent_class)->finalize (object);
@@ -196,6 +204,24 @@ yelp_view_class_init (YelpViewClass *klass)
YELP_VIEW_STATE_BLANK,
G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_PAGE_TITLE,
+ g_param_spec_string ("page-title",
+ N_("Page Title"),
+ N_("The title of the page being viewew"),
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+ g_object_class_install_property (object_class,
+ PROP_PAGE_DESC,
+ g_param_spec_string ("page-desc",
+ N_("Page Description"),
+ N_("The description of the page being viewew"),
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
}
static void
@@ -208,6 +234,12 @@ yelp_view_get_property (GObject *object,
switch (prop_id)
{
+ case PROP_PAGE_TITLE:
+ g_value_set_string (value, priv->page_title);
+ break;
+ case PROP_PAGE_DESC:
+ g_value_set_string (value, priv->page_desc);
+ break;
case PROP_STATE:
g_value_set_enum (value, priv->state);
break;
@@ -536,7 +568,17 @@ document_callback (YelpDocument *document,
debug_print (DB_FUNCTION, "entering\n");
if (signal == YELP_DOCUMENT_SIGNAL_INFO) {
- /* FIXME */
+ gchar *page_id;
+ page_id = yelp_uri_get_page_id (priv->uri);
+
+ g_free (priv->page_title);
+ g_free (priv->page_desc);
+
+ priv->page_title = yelp_document_get_page_title (document, page_id);
+ priv->page_desc = NULL;
+
+ g_signal_emit_by_name (view, "notify::page-title", 0);
+ g_signal_emit_by_name (view, "notify::page-desc", 0);
}
else if (signal == YELP_DOCUMENT_SIGNAL_CONTENTS) {
const gchar *contents;
diff --git a/tests/test-view.c b/tests/test-view.c
index 984546c..211144c 100644
--- a/tests/test-view.c
+++ b/tests/test-view.c
@@ -49,6 +49,17 @@ state_cb (YelpView *view,
printf ("STATE: %i\n", state);
}
+static void
+title_cb (YelpView *view,
+ GParamSpec *spec,
+ GtkWindow *window)
+{
+ gchar *title;
+ g_object_get (view, "page-title", &title, NULL);
+ gtk_window_set_title (window, title);
+ g_free (title);
+}
+
int
main (int argc, char **argv)
{
@@ -81,6 +92,8 @@ main (int argc, char **argv)
view = yelp_view_new ();
g_signal_connect (view, "notify::state",
G_CALLBACK (state_cb), window);
+ g_signal_connect (view, "notify::title",
+ G_CALLBACK (title_cb), window);
gtk_container_add (GTK_CONTAINER (scroll), view);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]