[yelp/yelp-3-0] Set the window title based on the root page title



commit d3ecc826fea73ffcfe57bb30c0914616eb3fb97c
Author: Shaun McCance <shaunm gnome org>
Date:   Sun Mar 21 14:03:12 2010 -0500

    Set the window title based on the root page title

 libyelp/yelp-docbook-document.c |   10 +++++++++-
 libyelp/yelp-document.c         |   23 +++++++++++++++++++++++
 libyelp/yelp-document.h         |    3 +++
 libyelp/yelp-mallard-document.c |    2 ++
 libyelp/yelp-view.c             |   25 +++++++++++++++++++++++--
 src/yelp-window.c               |   21 +++++++++++++++++++++
 6 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/libyelp/yelp-docbook-document.c b/libyelp/yelp-docbook-document.c
index 669fb62..3849f53 100644
--- a/libyelp/yelp-docbook-document.c
+++ b/libyelp/yelp-docbook-document.c
@@ -115,6 +115,7 @@ struct _YelpDocbookDocumentPrivate {
     gint          cur_depth;
     gchar        *cur_page_id;
     gchar        *cur_prev_id;
+    gchar        *root_id;
 };
 
 /******************************************************************************/
@@ -168,6 +169,7 @@ yelp_docbook_document_finalize (GObject *object)
 
     g_free (priv->cur_page_id);
     g_free (priv->cur_prev_id);
+    g_free (priv->root_id);
 
     g_mutex_free (priv->mutex);
 
@@ -345,12 +347,14 @@ docbook_process (YelpDocbookDocument *docbook)
 
     id = xmlGetProp (priv->xmlcur, BAD_CAST "id");
     if (id) {
+        priv->root_id = g_strdup (id);
         yelp_document_set_page_id (document, NULL, (gchar *) id);
         yelp_document_set_page_id (document, "//index", (gchar *) id);
         yelp_document_set_prev_id (document, (gchar *) id, "//about");
         yelp_document_set_next_id (document, "//about", (gchar *) id);
     }
     else {
+        priv->root_id = g_strdup ("//index");
         yelp_document_set_page_id (document, NULL, "//index");
         yelp_document_set_prev_id (document, "//index", "//about");
         yelp_document_set_next_id (document, "//about", "//index");
@@ -358,6 +362,8 @@ docbook_process (YelpDocbookDocument *docbook)
          * so when we try to load the document later, it doesn't fail */
         xmlNewProp (priv->xmlcur, BAD_CAST "id", BAD_CAST "//index");
     }
+    yelp_document_set_root_id (document, priv->root_id, priv->root_id);
+    yelp_document_set_root_id (document, "//about", priv->root_id);
     g_mutex_unlock (priv->mutex);
 
     g_mutex_lock (priv->mutex);
@@ -513,8 +519,10 @@ docbook_walk (YelpDocbookDocument *docbook)
 
     old_cur = priv->xmlcur;
     priv->cur_depth++;
-    if (id)
+    if (id) {
+        yelp_document_set_root_id (document, (gchar *) id, priv->root_id);
         yelp_document_set_page_id (document, (gchar *) id, priv->cur_page_id);
+    }
 
     yelp_document_signal (YELP_DOCUMENT (docbook),
                           priv->cur_page_id,
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index 7427552..3c79dc9 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -453,6 +453,29 @@ yelp_document_set_up_id (YelpDocument *document,
 }
 
 gchar *
+yelp_document_get_root_title (YelpDocument *document,
+                              const gchar  *page_id)
+{
+    gchar *real, *root, *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) {
+	root = hash_lookup (document->priv->root_ids, real);
+        if (root) {
+            ret = hash_lookup (document->priv->titles, root);
+            if (ret)
+                ret = g_strdup (ret);
+        }
+    }
+    g_mutex_unlock (document->priv->mutex);
+
+    return ret;
+}
+
+gchar *
 yelp_document_get_page_title (YelpDocument *document,
                               const gchar  *page_id)
 {
diff --git a/libyelp/yelp-document.h b/libyelp/yelp-document.h
index e71e673..674da05 100644
--- a/libyelp/yelp-document.h
+++ b/libyelp/yelp-document.h
@@ -126,6 +126,9 @@ void              yelp_document_set_up_id      (YelpDocument         *document,
                                                 const gchar          *page_id,
                                                 const gchar          *up_id);
 
+gchar *           yelp_document_get_root_title (YelpDocument         *document,
+                                                const gchar          *page_id);
+
 gchar *           yelp_document_get_page_title (YelpDocument         *document,
                                                 const gchar          *page_id);
 void              yelp_document_set_page_title (YelpDocument         *document,
diff --git a/libyelp/yelp-mallard-document.c b/libyelp/yelp-mallard-document.c
index 5d08ad3..c6501ce 100644
--- a/libyelp/yelp-mallard-document.c
+++ b/libyelp/yelp-mallard-document.c
@@ -320,6 +320,8 @@ mallard_think (YelpMallardDocument *mallard)
             mallard_page_data_free (page_data);
         } else {
             g_mutex_lock (priv->mutex);
+            yelp_document_set_root_id ((YelpDocument *) mallard,
+                                       page_data->page_id, "index");
             yelp_document_set_page_id ((YelpDocument *) mallard,
                                        page_data->page_id, page_data->page_id);
             g_hash_table_insert (priv->pages_hash, page_data->page_id, page_data);
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index a497ef0..e269e60 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -83,6 +83,7 @@ enum {
     PROP_0,
     PROP_URI,
     PROP_STATE,
+    PROP_ROOT_TITLE,
     PROP_PAGE_TITLE,
     PROP_PAGE_DESC
 };
@@ -109,6 +110,7 @@ struct _YelpViewPrivate {
 
     YelpViewState  state;
 
+    gchar         *root_title;
     gchar         *page_title;
     gchar         *page_desc;
 
@@ -167,6 +169,7 @@ yelp_view_finalize (GObject *object)
 {
     YelpViewPrivate *priv = GET_PRIV (object);
 
+    g_free (priv->root_title);
     g_free (priv->page_title);
     g_free (priv->page_desc);
 
@@ -231,10 +234,19 @@ yelp_view_class_init (YelpViewClass *klass)
                                                         G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
 
     g_object_class_install_property (object_class,
+                                     PROP_ROOT_TITLE,
+                                     g_param_spec_string ("root-title",
+                                                          N_("Root Title"),
+                                                          N_("The title of the root page 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_TITLE,
                                      g_param_spec_string ("page-title",
                                                           N_("Page Title"),
-                                                          N_("The title of the page being viewew"),
+                                                          N_("The title of the page being viewed"),
                                                           NULL,
                                                           G_PARAM_READABLE |
                                                           G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
@@ -243,7 +255,7 @@ yelp_view_class_init (YelpViewClass *klass)
                                      PROP_PAGE_DESC,
                                      g_param_spec_string ("page-desc",
                                                           N_("Page Description"),
-                                                          N_("The description of the page being viewew"),
+                                                          N_("The description of the page being viewed"),
                                                           NULL,
                                                           G_PARAM_READABLE |
                                                           G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
@@ -262,6 +274,9 @@ yelp_view_get_property (GObject    *object,
         case PROP_URI:
             g_value_set_object (value, priv->uri);
             break;
+        case PROP_ROOT_TITLE:
+            g_value_set_string (value, priv->root_title);
+            break;
         case PROP_PAGE_TITLE:
             g_value_set_string (value, priv->page_title);
             break;
@@ -328,10 +343,13 @@ yelp_view_load_uri (YelpView *view,
     view_clear_load (view);
     g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL);
 
+    g_free (priv->root_title);
     g_free (priv->page_title);
     g_free (priv->page_desc);
+    priv->root_title = NULL;
     priv->page_title = NULL;
     priv->page_desc = NULL;
+    g_signal_emit_by_name (view, "notify::root-title", 0);
     g_signal_emit_by_name (view, "notify::page-title", 0);
     g_signal_emit_by_name (view, "notify::page-desc", 0);
 
@@ -635,12 +653,15 @@ document_callback (YelpDocument       *document,
         gchar *page_id;
         page_id = yelp_uri_get_page_id (priv->uri);
 
+        g_free (priv->root_title);
         g_free (priv->page_title);
         g_free (priv->page_desc);
 
+        priv->root_title = yelp_document_get_root_title (document, page_id);
         priv->page_title = yelp_document_get_page_title (document, page_id);
         priv->page_desc = yelp_document_get_page_desc (document, page_id);
 
+        g_signal_emit_by_name (view, "notify::root-title", 0);
         g_signal_emit_by_name (view, "notify::page-title", 0);
         g_signal_emit_by_name (view, "notify::page-desc", 0);
     }
diff --git a/src/yelp-window.c b/src/yelp-window.c
index a643d18..ca1dc7c 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -68,6 +68,9 @@ static void          view_external_uri            (YelpView           *view,
 static void          view_uri_selected            (YelpView           *view,
                                                    GParamSpec         *pspec,
                                                    YelpWindow         *window);
+static void          view_root_title              (YelpView           *view,
+                                                   GParamSpec         *pspec,
+                                                   YelpWindow         *window);
 static void          view_page_title              (YelpView           *view,
                                                    GParamSpec         *pspec,
                                                    YelpWindow         *window);
@@ -174,6 +177,7 @@ yelp_window_init (YelpWindow *window)
     GError *error = NULL;
     YelpWindowPrivate *priv = GET_PRIV (window);
 
+    gtk_window_set_icon_name (GTK_WINDOW (window), "help-browser");
     gtk_window_set_default_size (GTK_WINDOW (window), 520, 580);
 
     vbox = gtk_vbox_new (FALSE, 0);
@@ -255,6 +259,7 @@ yelp_window_init (YelpWindow *window)
     priv->view = (YelpView *) yelp_view_new ();
     g_signal_connect (priv->view, "external-uri", G_CALLBACK (view_external_uri), window);
     g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), window);
+    g_signal_connect (priv->view, "notify::root-title", G_CALLBACK (view_root_title), window);
     g_signal_connect (priv->view, "notify::page-title", G_CALLBACK (view_page_title), window);
     g_signal_connect (priv->view, "notify::page-desc", G_CALLBACK (view_page_desc), window);
     gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (priv->view));
@@ -583,6 +588,22 @@ view_uri_selected (YelpView     *view,
 }
 
 static void
+view_root_title (YelpView    *view,
+                 GParamSpec  *pspec,
+                 YelpWindow  *window)
+{
+    gchar *title;
+    g_object_get (view, "root-title", &title, NULL);
+
+    if (title) {
+        gtk_window_set_title (GTK_WINDOW (window), title);
+        g_free (title);
+    } else {
+        gtk_window_set_title (GTK_WINDOW (window), _("Help"));
+    }
+}
+
+static void
 view_page_title (YelpView    *view,
                  GParamSpec  *pspec,
                  YelpWindow  *window)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]