[yelp] [libyelp] Move "bookmarks-changed" signal to YelpBookmarks, hook up to location entry



commit aedfdda78c26e18331163f084c0bb906fa7a6b2e
Author: Shaun McCance <shaunm gnome org>
Date:   Tue Aug 10 15:15:23 2010 -0400

    [libyelp] Move "bookmarks-changed" signal to YelpBookmarks, hook up to location entry

 libyelp/yelp-bookmarks.c      |    8 ++++++
 libyelp/yelp-location-entry.c |   52 +++++++++++++++++++++++++++++++++++++++-
 src/yelp-application.c        |   15 ++---------
 src/yelp-window.c             |   10 +++++++-
 4 files changed, 70 insertions(+), 15 deletions(-)
---
diff --git a/libyelp/yelp-bookmarks.c b/libyelp/yelp-bookmarks.c
index e68d8a8..670650d 100644
--- a/libyelp/yelp-bookmarks.c
+++ b/libyelp/yelp-bookmarks.c
@@ -26,12 +26,20 @@ enum {
     BOOKMARKS_CHANGED,
     LAST_SIGNAL
 };
+static gint signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_INTERFACE (YelpBookmarks, yelp_bookmarks, G_TYPE_OBJECT)
 
 static void
 yelp_bookmarks_default_init (YelpBookmarksInterface *iface)
 {
+    signals[BOOKMARKS_CHANGED] =
+        g_signal_new ("bookmarks-changed",
+                      G_TYPE_FROM_INTERFACE (iface),
+                      G_SIGNAL_RUN_LAST,
+                      0, NULL, NULL,
+                      g_cclosure_marshal_VOID__STRING,
+                      G_TYPE_NONE, 1, G_TYPE_STRING);
 }
 
 void
diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c
index 61fd456..27e3853 100644
--- a/libyelp/yelp-location-entry.c
+++ b/libyelp/yelp-location-entry.c
@@ -165,6 +165,10 @@ static void          view_page_desc                 (YelpView           *view,
 static void          view_page_icon                 (YelpView           *view,
                                                      GParamSpec         *pspec,
                                                      YelpLocationEntry  *entry);
+/* YelpBookmarks callbacks */
+static void          bookmarks_changed              (YelpBookmarks      *bookmarks,
+                                                     const gchar        *doc_uri,
+                                                     YelpLocationEntry  *entry);
 
 
 
@@ -183,11 +187,10 @@ struct _YelpLocationEntryPrivate
     GtkEntryCompletion *completion;
 
     gboolean   enable_search;
-
     gboolean   view_uri_selected;
-
     gboolean   search_mode;
     guint      pulse;
+    gulong bookmarks_changed;
 };
 
 enum {
@@ -482,6 +485,12 @@ location_entry_constructed (GObject *object)
     g_signal_connect (priv->text_entry, "activate",
                       G_CALLBACK (entry_activate_cb), object);
 
+    if (priv->bookmarks)
+        priv->bookmarks_changed = g_signal_connect (priv->bookmarks,
+                                                    "bookmarks-changed",
+                                                    G_CALLBACK (bookmarks_changed),
+                                                    object);
+
     g_signal_connect (priv->view, "loaded", G_CALLBACK (view_loaded), object);
     g_signal_connect (priv->view, "notify::yelp-uri", G_CALLBACK (view_uri_selected), object);
     g_signal_connect (priv->view, "notify::page-title", G_CALLBACK (view_page_title), object);
@@ -504,6 +513,11 @@ location_entry_dispose (GObject *object)
         priv->bookmarks = NULL;
     }
 
+    if (priv->bookmarks_changed) {
+        g_source_remove (priv->bookmarks_changed);
+        priv->bookmarks_changed = 0;
+    }
+
     if (priv->row) {
         gtk_tree_row_reference_free (priv->row);
         priv->row = NULL;
@@ -1404,6 +1418,40 @@ view_page_icon (YelpView          *view,
     g_free (icon);
 }
 
+static void
+bookmarks_changed (YelpBookmarks      *bookmarks,
+                   const gchar        *doc_uri,
+                   YelpLocationEntry  *entry)
+{
+    GtkTreePath *path;
+    YelpLocationEntryPrivate *priv = GET_PRIV (entry);
+
+    if (priv->row)
+        path = gtk_tree_row_reference_get_path (priv->row);
+
+    if (path) {
+        GtkTreeIter iter;
+        gchar *this_uri, *page_id;
+        gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->history), &iter, path);
+        gtk_tree_model_get (GTK_TREE_MODEL (priv->history), &iter,
+                            HISTORY_COL_DOC, &this_uri,
+                            HISTORY_COL_PAGE, &page_id,
+                            -1);
+        if (this_uri && g_str_equal (this_uri, doc_uri) && page_id) {
+            if (!yelp_bookmarks_is_bookmarked (priv->bookmarks, doc_uri, page_id)) {
+                gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry),
+                                                   GTK_ENTRY_ICON_SECONDARY,
+                                                   "bookmark-new");
+                gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->text_entry),
+                                                 GTK_ENTRY_ICON_SECONDARY,
+                                                 "Bookmark this page");
+            }
+        }
+        g_free (this_uri);
+        g_free (page_id);
+    }
+}
+
 /**
  * yelp_location_entry_new:
  * @view: A #YelpView.
diff --git a/src/yelp-application.c b/src/yelp-application.c
index a4635a1..a3d94cf 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -44,7 +44,6 @@
 static gboolean editor_mode = FALSE;
 
 enum {
-    BOOKMARKS_CHANGED,
     READ_LATER_CHANGED,
     LAST_SIGNAL
 };
@@ -158,14 +157,6 @@ yelp_application_class_init (YelpApplicationClass *klass)
     object_class->dispose = yelp_application_dispose;
     object_class->finalize = yelp_application_finalize;
 
-    signals[BOOKMARKS_CHANGED] =
-        g_signal_new ("bookmarks-changed",
-                      G_TYPE_FROM_CLASS (klass),
-                      G_SIGNAL_RUN_LAST,
-                      0, NULL, NULL,
-                      g_cclosure_marshal_VOID__STRING,
-                      G_TYPE_NONE, 1, G_TYPE_STRING);
-
     signals[READ_LATER_CHANGED] =
         g_signal_new ("read-later-changed",
                       G_TYPE_FROM_CLASS (klass),
@@ -659,7 +650,7 @@ yelp_application_add_bookmark (YelpApplication   *app,
             g_variant_builder_add (&builder, "(sss)", page_id, icon, title);
             value = g_variant_builder_end (&builder);
             g_settings_set_value (settings, "bookmarks", value);
-            g_signal_emit (app, signals[BOOKMARKS_CHANGED], 0, doc_uri);
+            g_signal_emit_by_name (app, "bookmarks-changed", doc_uri);
         }
     }
 }
@@ -686,7 +677,7 @@ yelp_application_remove_bookmark (YelpApplication   *app,
         g_variant_iter_free (iter);
 
         g_settings_set_value (settings, "bookmarks", g_variant_builder_end (&builder));
-        g_signal_emit (app, signals[BOOKMARKS_CHANGED], 0, doc_uri);
+        g_signal_emit_by_name (app, "bookmarks-changed", doc_uri);
     }
 }
 
@@ -758,7 +749,7 @@ yelp_application_update_bookmarks (YelpApplication   *app,
             GVariant *value;
             value = g_variant_builder_end (&builder);
             g_settings_set_value (settings, "bookmarks", value);
-            g_signal_emit (app, signals[BOOKMARKS_CHANGED], 0, doc_uri);
+            g_signal_emit_by_name (app, "bookmarks-changed", doc_uri);
         }
     }
 }
diff --git a/src/yelp-window.c b/src/yelp-window.c
index a082527..ca2e899 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -218,6 +218,7 @@ struct _YelpWindowPrivate {
     /* no ref */
     GtkWidget    *bookmarks_list;
     GtkListStore *bookmarks_store;
+    gulong        bookmarks_changed;
 
     /* no refs on these, owned by containers */
     YelpView *view;
@@ -366,6 +367,11 @@ yelp_window_dispose (GObject *object)
         priv->bookmark_actions = NULL;
     }
 
+    if (priv->bookmarks_changed) {
+        g_source_remove (priv->bookmarks_changed);
+        priv->bookmarks_changed = 0;
+    }
+
     if (priv->align_location) {
         g_object_unref (priv->align_location);
         priv->align_location = NULL;
@@ -492,7 +498,9 @@ window_construct (YelpWindow *window)
                         FALSE, FALSE, 0);
 
     priv->bookmarks_merge_id = gtk_ui_manager_new_merge_id (priv->ui_manager);
-    g_signal_connect (priv->application, "bookmarks-changed", G_CALLBACK (app_bookmarks_changed), window);
+    priv->bookmarks_changed =
+        g_signal_connect (priv->application, "bookmarks-changed",
+                          G_CALLBACK (app_bookmarks_changed), window);
 
     priv->hbox = gtk_hbox_new (FALSE, 0);
     g_object_set (priv->hbox, "border-width", 2, NULL);



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