[yelp] [yelp-application] Use GSettings::changed to emit bookmarks-changed
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp] [yelp-application] Use GSettings::changed to emit bookmarks-changed
- Date: Tue, 10 Aug 2010 19:58:50 +0000 (UTC)
commit b3718596e87a1ef76c6707feda907e7ff441fa62
Author: Shaun McCance <shaunm gnome org>
Date: Tue Aug 10 15:42:11 2010 -0400
[yelp-application] Use GSettings::changed to emit bookmarks-changed
libyelp/yelp-location-entry.c | 5 +++++
src/yelp-application.c | 25 +++++++++++++++++++------
src/yelp-window.c | 33 +++++++++++----------------------
3 files changed, 35 insertions(+), 28 deletions(-)
---
diff --git a/libyelp/yelp-location-entry.c b/libyelp/yelp-location-entry.c
index 27e3853..a61ed8d 100644
--- a/libyelp/yelp-location-entry.c
+++ b/libyelp/yelp-location-entry.c
@@ -1446,6 +1446,11 @@ bookmarks_changed (YelpBookmarks *bookmarks,
GTK_ENTRY_ICON_SECONDARY,
"Bookmark this page");
}
+ else {
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->text_entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ NULL);
+ }
}
g_free (this_uri);
g_free (page_id);
diff --git a/src/yelp-application.c b/src/yelp-application.c
index a3d94cf..8ffd35f 100644
--- a/src/yelp-application.c
+++ b/src/yelp-application.c
@@ -101,6 +101,9 @@ static void application_adjust_font (GtkAction *a
YelpApplication *app);
static void application_set_font_sensitivity (YelpApplication *app);
+static void bookmarks_changed (GSettings *settings,
+ const gchar *key,
+ YelpApplication *app);
static gboolean window_resized (YelpWindow *window,
YelpApplication *app);
@@ -567,8 +570,7 @@ application_get_doc_settings (YelpApplication *app, const gchar *doc_uri)
YelpApplicationPrivate *priv = GET_PRIV (app);
GSettings *settings = g_hash_table_lookup (priv->docsettings, doc_uri);
if (settings == NULL) {
- gchar *tmp;
- gchar *settings_path;
+ gchar *tmp, *key, *settings_path;
tmp = g_uri_escape_string (doc_uri, "", FALSE);
settings_path = g_strconcat ("/apps/yelp/documents/", tmp, "/", NULL);
g_free (tmp);
@@ -579,7 +581,11 @@ application_get_doc_settings (YelpApplication *app, const gchar *doc_uri)
else
settings = g_settings_new_with_path ("org.gnome.yelp.document",
settings_path);
- g_hash_table_insert (priv->docsettings, g_strdup (doc_uri), settings);
+ key = g_strdup (doc_uri);
+ g_hash_table_insert (priv->docsettings, key, settings);
+ g_object_set_data ((GObject *) settings, "doc_uri", key);
+ g_signal_connect (settings, "changed::bookmarks",
+ G_CALLBACK (bookmarks_changed), app);
g_free (settings_path);
}
return settings;
@@ -650,7 +656,6 @@ 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_by_name (app, "bookmarks-changed", doc_uri);
}
}
}
@@ -677,7 +682,6 @@ 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_by_name (app, "bookmarks-changed", doc_uri);
}
}
@@ -749,7 +753,6 @@ yelp_application_update_bookmarks (YelpApplication *app,
GVariant *value;
value = g_variant_builder_end (&builder);
g_settings_set_value (settings, "bookmarks", value);
- g_signal_emit_by_name (app, "bookmarks-changed", doc_uri);
}
}
}
@@ -886,6 +889,16 @@ yelp_application_install_package (YelpApplication *app,
g_variant_builder_unref (strv);
}
+static void
+bookmarks_changed (GSettings *settings,
+ const gchar *key,
+ YelpApplication *app)
+{
+ const gchar *doc_uri = g_object_get_data ((GObject *) settings, "doc_uri");
+ if (doc_uri)
+ g_signal_emit_by_name (app, "bookmarks-changed", doc_uri);
+}
+
static gboolean
window_resized (YelpWindow *window,
YelpApplication *app)
diff --git a/src/yelp-window.c b/src/yelp-window.c
index ca2e899..a977e9b 100644
--- a/src/yelp-window.c
+++ b/src/yelp-window.c
@@ -908,6 +908,8 @@ window_set_bookmarks (YelpWindow *window,
YelpWindowPrivate *priv = GET_PRIV (window);
GSList *entries = NULL;
+ window_set_bookmark_action (window);
+
gtk_ui_manager_remove_ui (priv->ui_manager, priv->bookmarks_merge_id);
value = yelp_application_get_bookmarks (priv->application, doc_uri);
@@ -967,11 +969,8 @@ window_set_bookmarks (YelpWindow *window,
static void
window_set_bookmark_action (YelpWindow *window)
{
- YelpUri *uri;
- gchar *doc_uri, *page_id;
- gchar *curpage;
- GVariant *value;
- GVariantIter *viter;
+ YelpUri *uri = NULL;
+ gchar *doc_uri = NULL, *page_id = NULL;
GtkAction *action;
YelpWindowPrivate *priv = GET_PRIV (window);
@@ -983,27 +982,17 @@ window_set_bookmark_action (YelpWindow *window)
NULL);
if (page_id == NULL) {
gtk_action_set_sensitive (action, FALSE);
- if (uri)
- g_object_unref (uri);
- return;
+ goto done;
}
- gtk_action_set_sensitive (action, TRUE);
-
doc_uri = yelp_uri_get_document_uri (uri);
- value = yelp_application_get_bookmarks (priv->application, doc_uri);
- g_variant_get (value, "a(sss)", &viter);
- while (g_variant_iter_loop (viter, "(&s&s&s)", &curpage, NULL, NULL)) {
- if (g_str_equal (page_id, curpage)) {
- gtk_action_set_sensitive (action, FALSE);
- break;
- }
- }
- g_variant_iter_free (viter);
- g_variant_unref (value);
-
+ gtk_action_set_sensitive (action,
+ !yelp_application_is_bookmarked (priv->application,
+ doc_uri, page_id));
+ done:
g_free (page_id);
g_free (doc_uri);
- g_object_unref (uri);
+ if (uri)
+ g_object_unref (uri);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]