[yelp/yelp-3-0] [yelp-window] Hooking up the location entry in YelpWindow



commit 0d9e5d5d2ebd28e00cec79aeac0f07accfe41558
Author: Shaun McCance <shaunm gnome org>
Date:   Fri Mar 12 16:25:22 2010 -0600

    [yelp-window] Hooking up the location entry in YelpWindow

 libyelp/yelp-view.c |   28 ++++++++
 src/yelp-window.c   |  189 ++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 206 insertions(+), 11 deletions(-)
---
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 9f3edfb..9f2dbe0 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -81,6 +81,7 @@ static void        document_callback              (YelpDocument       *document,
 
 enum {
     PROP_0,
+    PROP_URI,
     PROP_STATE,
     PROP_PAGE_TITLE,
     PROP_PAGE_DESC
@@ -196,6 +197,15 @@ yelp_view_class_init (YelpViewClass *klass)
     g_type_class_add_private (klass, sizeof (YelpViewPrivate));
 
     g_object_class_install_property (object_class,
+                                     PROP_URI,
+                                     g_param_spec_object ("yelp-uri",
+							  _("Yelp URI"),
+							  _("A YelpUri with the current location"),
+                                                          YELP_TYPE_URI,
+							  G_PARAM_READWRITE | G_PARAM_STATIC_NAME |
+							  G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+    g_object_class_install_property (object_class,
                                      PROP_STATE,
                                      g_param_spec_enum ("state",
                                                         N_("Loading State"),
@@ -234,6 +244,9 @@ yelp_view_get_property (GObject    *object,
 
     switch (prop_id)
         {
+        case PROP_URI:
+            g_value_set_object (value, priv->uri);
+            break;
         case PROP_PAGE_TITLE:
             g_value_set_string (value, priv->page_title);
             break;
@@ -255,10 +268,16 @@ yelp_view_set_property (GObject      *object,
                         const GValue *value,
                         GParamSpec   *pspec)
 {
+    YelpUri *uri;
     YelpViewPrivate *priv = GET_PRIV (object);
 
     switch (prop_id)
         {
+        case PROP_URI:
+            uri = g_value_get_object (value);
+            yelp_view_load_uri (YELP_VIEW (object), uri);
+            g_object_unref (uri);
+            break;
         case PROP_STATE:
             priv->state = g_value_get_enum (value);
             break;
@@ -294,6 +313,13 @@ yelp_view_load_uri (YelpView *view,
     view_clear_load (view);
     g_object_set (view, "state", YELP_VIEW_STATE_LOADING, NULL);
 
+    g_free (priv->page_title);
+    g_free (priv->page_desc);
+    priv->page_title = NULL;
+    priv->page_desc = NULL;
+    g_signal_emit_by_name (view, "notify::page-title", 0);
+    g_signal_emit_by_name (view, "notify::page-desc", 0);
+
     priv->uri = g_object_ref (uri);
     if (!yelp_uri_is_resolved (uri)) {
         priv->uri_resolved = g_signal_connect (uri, "resolved",
@@ -554,6 +580,8 @@ uri_resolved (YelpUri  *uri,
         g_object_unref (priv->document);
     priv->document = document;
 
+    g_signal_emit_by_name (view, "notify::yelp-uri", 0);
+
     view_load_page (view);
 }
 
diff --git a/src/yelp-window.c b/src/yelp-window.c
index 995c0db..e67c674 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -24,46 +24,102 @@
 #include <config.h>
 #endif
 
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#include "yelp-location-entry.h"
 #include "yelp-uri.h"
 #include "yelp-view.h"
 
 #include "yelp-application.h"
 #include "yelp-window.h"
 
-static void          yelp_window_init             (YelpWindow       *window);
-static void          yelp_window_class_init       (YelpWindowClass  *klass);
-static void          yelp_window_dispose          (GObject          *object);
-static void          yelp_window_finalize         (GObject          *object);
+static void          yelp_window_init             (YelpWindow         *window);
+static void          yelp_window_class_init       (YelpWindowClass    *klass);
+static void          yelp_window_dispose          (GObject            *object);
+static void          yelp_window_finalize         (GObject            *object);
+
+static void          entry_location_selected      (YelpLocationEntry  *entry,
+                                                   YelpWindow         *window);
+
+static void          view_uri_selected            (YelpView           *view,
+                                                   GParamSpec         *pspec,
+                                                   YelpWindow         *window);
+static void          view_page_title              (YelpView           *view,
+                                                   GParamSpec         *pspec,
+                                                   YelpWindow         *window);
+static void          view_page_desc               (YelpView           *view,
+                                                   GParamSpec         *pspec,
+                                                   YelpWindow         *window);
 
 G_DEFINE_TYPE (YelpWindow, yelp_window, GTK_TYPE_WINDOW);
 #define GET_PRIV(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_WINDOW, YelpWindowPrivate))
 
+enum {
+  COL_TITLE,
+  COL_DESC,
+  COL_ICON,
+  COL_FLAGS,
+  COL_URI,
+  COL_TERMS
+};
+
 typedef struct _YelpWindowPrivate YelpWindowPrivate;
 struct _YelpWindowPrivate {
-    YelpView *view; /* no ref */
+    GtkListStore *history;
+
+    /* no refs on these, owned by containers */
+    YelpView *view;
+    YelpLocationEntry *entry;
+
+    gulong entry_location_selected;
 };
 
 static void
 yelp_window_init (YelpWindow *window)
 {
-    GtkWidget *scroll, *view;
+    GtkWidget *vbox, *hbox, *scroll;
     YelpWindowPrivate *priv = GET_PRIV (window);
 
     gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_UTILITY);
     gtk_window_set_default_size (GTK_WINDOW (window), 520, 580);
+
+    vbox = gtk_vbox_new (FALSE, 0);
+    gtk_container_add (GTK_CONTAINER (window), vbox);
+
+    hbox = gtk_vbox_new (FALSE, 6);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
     
+    priv->history = gtk_list_store_new (6,
+                                        G_TYPE_STRING,  /* title */
+                                        G_TYPE_STRING,  /* desc */
+                                        G_TYPE_STRING,  /* icon */
+                                        G_TYPE_INT,     /* flags */
+                                        G_TYPE_STRING,  /* uri */
+                                        G_TYPE_STRING   /* search terms */
+                                        );
+    priv->entry = (YelpLocationEntry *)
+        yelp_location_entry_new_with_model (GTK_TREE_MODEL (priv->history),
+                                            COL_TITLE,
+                                            COL_DESC,
+                                            COL_ICON,
+                                            COL_FLAGS);
+    priv->entry_location_selected = g_signal_connect (priv->entry, "location-selected",
+                                                      G_CALLBACK (entry_location_selected), window);
+    gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->entry), TRUE, TRUE, 0);
+
     scroll = gtk_scrolled_window_new (NULL, NULL);
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC);
-    gtk_container_add (GTK_CONTAINER (window), scroll);
+    gtk_box_pack_end (GTK_BOX (vbox), scroll, TRUE, TRUE, 0);
 
-    view = yelp_view_new ();
-    gtk_container_add (GTK_CONTAINER (scroll), view);
-
-    priv->view = (YelpView *) view;
+    priv->view = (YelpView *) yelp_view_new ();
+    g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), 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));
+    gtk_widget_grab_focus (GTK_WIDGET (priv->view));
 }
 
 static void
@@ -110,3 +166,114 @@ yelp_window_load_uri (YelpWindow  *window,
 
     yelp_view_load_uri (priv->view, uri);
 }
+
+/******************************************************************************/
+
+static void
+entry_location_selected (YelpLocationEntry  *entry,
+                         YelpWindow         *window)
+{
+    GtkTreeIter iter;
+    gchar *uri;
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->entry), &iter);
+    gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter,
+                        COL_URI, &uri,
+                        -1);
+    yelp_view_load (priv->view, uri);
+    g_free (uri);
+}
+
+static void
+view_uri_selected (YelpView     *view,
+                   GParamSpec   *pspec,
+                   YelpWindow   *window)
+{
+    GtkTreeIter iter;
+    gchar *iter_uri;
+    gboolean cont;
+    YelpUri *uri;
+    gchar *struri;
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    g_object_get (G_OBJECT (view), "yelp-uri", &uri, NULL);
+    if (uri == NULL)
+        return;
+
+    struri = yelp_uri_get_canonical_uri (uri);
+
+    cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &iter);
+    while (cont) {
+        gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter,
+                            COL_URI, &iter_uri,
+                            -1);
+        if (iter_uri && g_str_equal (struri, iter_uri)) {
+            g_free (iter_uri);
+            break;
+        }
+        else {
+            g_free (iter_uri);
+            cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->history), &iter);
+        }
+    }
+    if (cont) {
+        GtkTreeIter first;
+        gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first);
+        gtk_list_store_move_before (priv->history, &iter, &first);
+    }
+    else {
+        gtk_list_store_prepend (priv->history, &iter);
+        gtk_list_store_set (priv->history, &iter,
+                            COL_TITLE, _("Loading"),
+                            COL_ICON, "help-browser",
+                            COL_URI, struri,
+                            -1);
+    }
+    g_signal_handler_block (priv->entry,
+                            priv->entry_location_selected);
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->entry), &iter);
+    g_signal_handler_unblock (priv->entry,
+                              priv->entry_location_selected);
+
+    g_free (struri);
+    g_object_unref (uri);
+}
+
+static void
+view_page_title (YelpView    *view,
+                 GParamSpec  *pspec,
+                 YelpWindow  *window)
+{
+    GtkTreeIter first;
+    gchar *title;
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    g_object_get (view, "page-title", &title, NULL);
+    if (title == NULL)
+        return;
+
+    gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first);
+    gtk_list_store_set (priv->history, &first,
+                        COL_TITLE, title,
+                        -1);
+}
+
+static void
+view_page_desc (YelpView    *view,
+                 GParamSpec  *pspec,
+                 YelpWindow  *window)
+{
+    GtkTreeIter first;
+    gchar *desc;
+    YelpWindowPrivate *priv = GET_PRIV (window);
+
+    g_object_get (view, "page-desc", &desc, NULL);
+    if (desc == NULL)
+        return;
+
+    gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->history), &first);
+    gtk_list_store_set (priv->history, &first,
+                        COL_DESC, desc,
+                        -1);
+}



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