aboutsummaryrefslogtreecommitdiffstats
path: root/src/bookmarks/ephy-topic-action.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2004-10-25 02:18:23 +0800
committerChristian Persch <chpe@src.gnome.org>2004-10-25 02:18:23 +0800
commitebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9 (patch)
treeb78754814536f84e45bf147f06edcc7e2c2b7bce /src/bookmarks/ephy-topic-action.c
parentb215d12909f4fb3e27a146b03caa896a1f95d38c (diff)
downloadgsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar.gz
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar.bz2
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar.lz
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar.xz
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.tar.zst
gsoc2013-epiphany-ebe9e8c7f0333591c5120d9645f9a0c1d7ebd0a9.zip
Add EPHY_NODE_CHANGED signal. Patch by Peter Harvey.
2004-10-24 Christian Persch <chpe@cvs.gnome.org> * lib/ephy-node.c: (callback), (ephy_node_set_property), (ephy_node_signal_connect_object), (match_signal_data), (ephy_node_signal_disconnect_object): * lib/ephy-node.h: Add EPHY_NODE_CHANGED signal. Patch by Peter Harvey. * src/bookmarks/ephy-bookmark-action.c: (favicon_cache_changed_cb), (ephy_bookmark_action_sync_icon), (ephy_bookmark_action_sync_label), (open_in_tab_activate_cb), (open_in_window_activate_cb), (activate_cb), (drag_data_get_cb), (properties_activate_cb), (bookmark_changed_cb), (bookmark_destroy_cb), (ephy_bookmark_action_set_bookmark), (ephy_bookmark_action_set_property), (ephy_bookmark_action_get_property), (ephy_bookmark_action_finalize), (ephy_bookmark_action_class_init), (smart_child_added_cb), (smart_child_removed_cb), (ephy_bookmark_action_init), (ephy_bookmark_action_new): * src/bookmarks/ephy-bookmark-action.h: * src/bookmarks/ephy-bookmarks-menu.c: (add_action_for_bookmark): * src/bookmarks/ephy-bookmarksbar.c: (ephy_bookmarksbar_action_request): * src/bookmarks/ephy-favorites-menu.c: (ephy_favorites_menu_rebuild): * src/bookmarks/ephy-topic-action.c: (build_menu), (topic_changed_cb), (ephy_topic_action_set_topic), (ephy_topic_action_set_property), (ephy_topic_action_get_property), (ephy_topic_action_class_init), (ephy_topic_action_init), (ephy_topic_action_new): * src/bookmarks/ephy-topic-action.h: Changed ephy_[bookmark|topic]_action_new from node-id to node. Saves one round-trip node->node-id->node. Save lots of strdups by using the node's properties directly, instead of storing them again in the action. Listen to changes on the node itself, not for child-changed on the bookmarks node.
Diffstat (limited to 'src/bookmarks/ephy-topic-action.c')
-rw-r--r--src/bookmarks/ephy-topic-action.c162
1 files changed, 61 insertions, 101 deletions
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index c002377f5..f8efa869e 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -50,9 +50,8 @@ static GtkTargetEntry drag_targets[] =
};
static int n_drag_targets = G_N_ELEMENTS (drag_targets);
-struct EphyTopicActionPrivate
+struct _EphyTopicActionPrivate
{
- guint topic_id;
EphyNode *topic_node;
guint motion_handler;
@@ -64,7 +63,7 @@ struct EphyTopicActionPrivate
enum
{
PROP_0,
- PROP_TOPIC_ID
+ PROP_TOPIC
};
enum
@@ -574,7 +573,7 @@ build_topics_menu (EphyTopicAction *action)
static GtkWidget *
build_menu (EphyTopicAction *action)
{
- if (action->priv->topic_id == BOOKMARKS_NODE_ID)
+ if (ephy_node_get_id (action->priv->topic_node) == BOOKMARKS_NODE_ID)
{
return build_topics_menu (action);
}
@@ -863,17 +862,51 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
}
}
+
static void
-ephy_topic_action_set_topic_id (EphyTopicAction *action, guint id)
+topic_changed_cb (EphyNode *node,
+ guint property_id,
+ EphyTopicAction *action)
{
- EphyBookmarks *bookmarks;
- EphyNode *node;
+ if (property_id == EPHY_NODE_KEYWORD_PROP_NAME)
+ {
+ GValue value = { 0, };
+ const char *tmp;
+ char *title;
+ int priority;
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- node = ephy_bookmarks_get_from_id (bookmarks, id);
+ priority = ephy_node_get_property_int
+ (node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
+
+ if (priority == EPHY_NODE_ALL_PRIORITY)
+ {
+ tmp = _("Bookmarks");
+ }
+ else
+ {
+ tmp = ephy_node_get_property_string
+ (node, EPHY_NODE_KEYWORD_PROP_NAME);
+ }
+
+ title = ephy_string_double_underscores (tmp);
+
+ g_value_init(&value, G_TYPE_STRING);
+ g_value_take_string (&value, title);
+ g_object_set_property (G_OBJECT (action), "label", &value);
+ g_value_unset (&value);
+ }
+}
+static void
+ephy_topic_action_set_topic (EphyTopicAction *action,
+ EphyNode *node)
+{
action->priv->topic_node = node;
- action->priv->topic_id = id;
+
+ topic_changed_cb (node, EPHY_NODE_KEYWORD_PROP_NAME, action);
+ ephy_node_signal_connect_object (node, EPHY_NODE_CHANGED,
+ (EphyNodeCallback) topic_changed_cb,
+ G_OBJECT (action));
}
static void
@@ -888,8 +921,8 @@ ephy_topic_action_set_property (GObject *object,
switch (prop_id)
{
- case PROP_TOPIC_ID:
- ephy_topic_action_set_topic_id (topic, g_value_get_int (value));
+ case PROP_TOPIC:
+ ephy_topic_action_set_topic (topic, g_value_get_pointer (value));
break;
}
}
@@ -900,16 +933,8 @@ ephy_topic_action_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- EphyTopicAction *bmk;
-
- bmk = EPHY_TOPIC_ACTION (object);
-
- switch (prop_id)
- {
- case PROP_TOPIC_ID:
- g_value_set_boolean (value, bmk->priv->topic_id);
- break;
- }
+ /* no readable properties */
+ g_return_if_reached ();
}
static void
@@ -962,95 +987,30 @@ ephy_topic_action_class_init (EphyTopicActionClass *class)
1,
G_TYPE_POINTER);
- g_object_class_install_property (object_class,
- PROP_TOPIC_ID,
- g_param_spec_int ("topic_id",
- "topic_id",
- "topic_id",
- 0,
- G_MAXINT,
- 0,
- G_PARAM_READWRITE));
+ g_object_class_install_property
+ (object_class,
+ PROP_TOPIC,
+ g_param_spec_pointer ("topic",
+ "Topic",
+ "Topic",
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof(EphyTopicActionPrivate));
}
static void
-sync_topic_properties (GtkAction *action, EphyNode *bmk)
-{
- const char *tmp;
- char *title;
- int priority;
-
- priority = ephy_node_get_property_int
- (bmk, EPHY_NODE_KEYWORD_PROP_PRIORITY);
-
- if (priority == EPHY_NODE_ALL_PRIORITY)
- {
- tmp = _("Bookmarks");
- }
- else
- {
- tmp = ephy_node_get_property_string
- (bmk, EPHY_NODE_KEYWORD_PROP_NAME);
- }
-
- title = ephy_string_double_underscores (tmp);
-
- g_object_set (action, "label", title, NULL);
-
- g_free (title);
-}
-
-static void
-topic_child_changed_cb (EphyNode *node,
- EphyNode *child,
- guint property_id,
- GtkAction *action)
-{
- guint id;
-
- id = EPHY_TOPIC_ACTION (action)->priv->topic_id;
-
- if (id == ephy_node_get_id (child))
- {
- sync_topic_properties (action, child);
- }
-}
-
-static void
ephy_topic_action_init (EphyTopicAction *action)
{
- EphyBookmarks *bookmarks;
- EphyNode *node;
-
action->priv = EPHY_TOPIC_ACTION_GET_PRIVATE (action);
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- node = ephy_bookmarks_get_keywords (bookmarks);
- ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_CHANGED,
- (EphyNodeCallback) topic_child_changed_cb,
- G_OBJECT (action));
}
GtkAction *
-ephy_topic_action_new (const char *name, guint id)
+ephy_topic_action_new (const char *name,
+ EphyNode *node)
{
- EphyNode *bmk;
- EphyBookmarks *bookmarks;
- GtkAction *action;
-
- bookmarks = ephy_shell_get_bookmarks (ephy_shell);
-
- bmk = ephy_bookmarks_get_from_id (bookmarks, id);
- g_return_val_if_fail (bmk != NULL, NULL);
-
- action = GTK_ACTION (g_object_new (EPHY_TYPE_TOPIC_ACTION,
- "topic_id", id,
- "name", name,
- NULL));
-
- sync_topic_properties (action, bmk);
-
- return action;
+ return g_object_new (EPHY_TYPE_TOPIC_ACTION,
+ "name", name,
+ "topic", node,
+ NULL);
}