Initial import of ephy (rev# 7126) from svn
[ephy-soc.git] / src / bookmarks / ephy-bookmark-action-group.c
blob023b96617204bec5168989d43435b710d9be4eca
1 /*
2 * Copyright © 2005 Peter Harvey
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * $Id: ephy-bookmark-action-group.c 6952 2007-03-11 19:42:02Z chpe $
21 #include "config.h"
23 #include "ephy-shell.h"
24 #include "ephy-bookmark-action-group.h"
25 #include "ephy-bookmark-action.h"
26 #include "ephy-bookmarks.h"
27 #include "ephy-bookmarks-ui.h"
28 #include "ephy-link.h"
29 #include "ephy-node.h"
30 #include "ephy-node-common.h"
31 #include "ephy-debug.h"
33 #include <gtk/gtkaction.h>
34 #include <gtk/gtkactiongroup.h>
35 #include <string.h>
37 static void
38 smart_added_cb (EphyNode *parent,
39 EphyNode *child,
40 GtkActionGroup *action_group)
42 GtkAction *action;
43 char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
45 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
47 action = gtk_action_group_get_action (action_group, name);
49 if (action != NULL)
51 ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
55 static void
56 smart_removed_cb (EphyNode *parent,
57 EphyNode *child,
58 guint index,
59 GtkActionGroup *action_group)
61 GtkAction *action;
62 char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
64 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
66 action = gtk_action_group_get_action (action_group, name);
68 if (action != NULL)
70 ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
74 static void
75 node_changed_cb (EphyNode *parent,
76 EphyNode *child,
77 guint property_id,
78 GtkActionGroup *action_group)
80 GtkAction *action;
81 char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
83 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
85 action = gtk_action_group_get_action (action_group, name);
87 if (action != NULL)
89 ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
93 static void
94 node_added_cb (EphyNode *parent,
95 EphyNode *child,
96 GtkActionGroup *action_group)
98 GtkAction *action;
99 char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
100 char accel[256];
102 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
104 action = ephy_bookmark_action_new (child, name);
106 g_snprintf (accel, sizeof (accel), "<Actions>/%s/%s",
107 gtk_action_group_get_name (action_group),
108 name);
109 gtk_action_set_accel_path (action, accel);
110 gtk_action_group_add_action (action_group, action);
111 g_object_unref (action);
113 ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
115 g_signal_connect_swapped (action, "open-link",
116 G_CALLBACK (ephy_link_open), action_group);
119 static void
120 node_removed_cb (EphyNode *parent,
121 EphyNode *child,
122 guint index,
123 GtkActionGroup *action_group)
125 GtkAction *action;
126 char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
128 EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
130 action = gtk_action_group_get_action (action_group, name);
132 if (action != NULL)
134 gtk_action_group_remove_action (action_group, action);
138 GtkActionGroup *
139 ephy_bookmark_group_new (EphyNode *node)
141 EphyBookmarks *bookmarks;
142 EphyNode *smart;
143 GPtrArray *children;
144 GtkActionGroup *action_group;
145 guint i;
147 bookmarks = ephy_shell_get_bookmarks (ephy_shell);
148 smart = ephy_bookmarks_get_smart_bookmarks (bookmarks);
150 action_group = (GtkActionGroup *) ephy_link_action_group_new ("BA");
152 children = ephy_node_get_children (node);
153 for (i = 0; i < children->len; i++)
155 node_added_cb (node, g_ptr_array_index (children, i),
156 action_group);
159 ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_ADDED,
160 (EphyNodeCallback) node_added_cb,
161 (GObject *) action_group);
162 ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_REMOVED,
163 (EphyNodeCallback) node_removed_cb,
164 (GObject *) action_group);
165 ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_CHANGED,
166 (EphyNodeCallback) node_changed_cb,
167 (GObject *) action_group);
169 ephy_node_signal_connect_object (smart, EPHY_NODE_CHILD_ADDED,
170 (EphyNodeCallback) smart_added_cb,
171 (GObject *) action_group);
172 ephy_node_signal_connect_object (smart, EPHY_NODE_CHILD_REMOVED,
173 (EphyNodeCallback) smart_removed_cb,
174 (GObject *) action_group);
176 return action_group;