diff options
author | Shaun McCance <shaunm@gnome.org> | 2010-05-10 14:35:55 -0500 |
---|---|---|
committer | Shaun McCance <shaunm@gnome.org> | 2010-05-10 14:35:55 -0500 |
commit | 549fd7559a68a6fe924be21b2b2e5feaf0f9d72a (patch) | |
tree | 3182757882f5f8a11e36d9704684cfc7b5d30d2a | |
parent | 27959c3d15e7dfa19612a4501fb73d88d4dcdc04 (diff) | |
download | yelp-549fd7559a68a6fe924be21b2b2e5feaf0f9d72a.tar.gz |
[yelp-application] Automatically update bookmark titles and icons
I'm doing this on the "loaded" callback, assuming we already have an icon
and a title. This assumption actually doesn't hold for HTML documents,
which reset the title property after the page is loaded. I fear doing
this in too many property notification callbacks, because updating the
bookmarks causes callbacks into all windows. Maybe add a timeout from
view_loaded instead.
-rw-r--r-- | src/yelp-application.c | 45 | ||||
-rw-r--r-- | src/yelp-application.h | 5 | ||||
-rw-r--r-- | src/yelp-window.c | 17 |
3 files changed, 63 insertions, 4 deletions
diff --git a/src/yelp-application.c b/src/yelp-application.c index b34a88c1..8f4573d1 100644 --- a/src/yelp-application.c +++ b/src/yelp-application.c @@ -595,7 +595,50 @@ 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_variant_unref (value); + g_signal_emit (app, signals[BOOKMARKS_CHANGED], 0, doc_uri); + } + } +} + +void +yelp_application_update_bookmarks (YelpApplication *app, + const gchar *doc_uri, + const gchar *page_id, + const gchar *icon, + const gchar *title) +{ + GSettings *settings; + + settings = application_get_doc_settings (app, doc_uri); + + if (settings) { + GVariantBuilder builder; + GVariantIter *iter; + gchar *this_id, *this_icon, *this_title; + gboolean updated = FALSE; + g_settings_get (settings, "bookmarks", "a(sss)", &iter); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(sss)")); + while (g_variant_iter_loop (iter, "(&s&s&s)", &this_id, &this_icon, &this_title)) { + if (g_str_equal (page_id, this_id)) { + if (icon && !g_str_equal (icon, this_icon)) { + this_icon = (gchar *) icon; + updated = TRUE; + } + if (title && !g_str_equal (title, this_title)) { + this_title = (gchar *) title; + updated = TRUE; + } + if (!updated) + break; + } + g_variant_builder_add (&builder, "(sss)", this_id, this_icon, this_title); + } + g_variant_iter_free (iter); + + if (updated) { + 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); } } diff --git a/src/yelp-application.h b/src/yelp-application.h index cda99697..5a3726cb 100644 --- a/src/yelp-application.h +++ b/src/yelp-application.h @@ -63,6 +63,11 @@ void yelp_application_add_bookmark (YelpApplication *app, const gchar *page_id, const gchar *icon, const gchar *title); +void yelp_application_update_bookmarks (YelpApplication *app, + const gchar *doc_uri, + const gchar *page_id, + const gchar *icon, + const gchar *title); GVariant * yelp_application_get_bookmarks (YelpApplication *app, const gchar *doc_uri); void yelp_application_install_package (YelpApplication *app, diff --git a/src/yelp-window.c b/src/yelp-window.c index b0eb5b69..20bc1724 100644 --- a/src/yelp-window.c +++ b/src/yelp-window.c @@ -1289,7 +1289,7 @@ view_loaded (YelpView *view, GtkTreeIter iter; gint flags; YelpUri *uri; - gchar *doc_uri, *page_id; + gchar *doc_uri, *page_id, *icon, *title; GtkTreeModel *completion; YelpWindowPrivate *priv = GET_PRIV (window); YelpDocument *document = yelp_view_get_document (view); @@ -1303,14 +1303,25 @@ view_loaded (YelpView *view, gtk_list_store_set (priv->history, &iter, HISTORY_COL_FLAGS, flags, -1); } - g_object_get (view, "yelp-uri", &uri, NULL); + g_object_get (view, + "yelp-uri", &uri, + "page-id", &page_id, + "page-icon", &icon, + "page-title", &title, + NULL); doc_uri = yelp_uri_get_document_uri (uri); - g_object_get (priv->view, "page-id", &page_id, NULL); gtk_list_store_set (priv->history, &iter, HISTORY_COL_DOC, doc_uri, HISTORY_COL_PAGE, page_id, -1); + yelp_application_update_bookmarks (priv->application, + doc_uri, + page_id, + icon, + title); g_free (page_id); + g_free (icon); + g_free (title); completion = (GtkTreeModel *) g_hash_table_lookup (completions, doc_uri); if (completion == NULL) { |