aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-02-11 06:49:29 +0800
committerChristian Persch <chpe@src.gnome.org>2006-02-11 06:49:29 +0800
commit927100b2cb4b488d2581d63f764b74db976db69c (patch)
tree5bc83bbf59b42b3ac55d934716b53186a4d98664 /src
parentf71767923318f72934fcd30be4dd47adb9f5b4de (diff)
downloadgsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar.gz
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar.bz2
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar.lz
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar.xz
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.tar.zst
gsoc2013-epiphany-927100b2cb4b488d2581d63f764b74db976db69c.zip
Remove *_action_name functions, and use static buffers instead. Minor
2006-02-10 Christian Persch <chpe@cvs.gnome.org> * src/bookmarks/ephy-bookmark-action-group.c: (smart_added_cb), (smart_removed_cb), (node_changed_cb), (node_added_cb), (node_removed_cb): * src/bookmarks/ephy-bookmark-action.c: (ephy_bookmark_action_new): * src/bookmarks/ephy-bookmark-action.h: * src/bookmarks/ephy-bookmark-factory-action.c: (build_menu_for_topic): * src/bookmarks/ephy-bookmarks-editor.c: (cmd_toolbar), (ephy_bookmarks_editor_update_menu): * src/bookmarks/ephy-bookmarks-menu.c: (append_bookmarks), (append_menu), (ephy_bookmarks_menu_build): * src/bookmarks/ephy-bookmarks-ui.c: (ephy_bookmarks_ui_attach_window), (topic_has_data), (topic_get_data), (topic_get_name), (bookmark_has_data), (bookmark_get_data), (bookmark_get_name), (bookmark_new_name), (toolbar_node_removed_cb): * src/bookmarks/ephy-bookmarks-ui.h: * src/bookmarks/ephy-open-tabs-action.c: (node_added_cb), (node_removed_cb), (ephy_open_tabs_group_new): * src/bookmarks/ephy-open-tabs-action.h: * src/bookmarks/ephy-topic-action-group.c: (node_changed_cb), (node_added_cb), (node_removed_cb), (ephy_topic_action_group_new): * src/bookmarks/ephy-topic-action-group.h: * src/bookmarks/ephy-topic-action.c: (ephy_topic_action_new): * src/bookmarks/ephy-topic-action.h: * src/bookmarks/ephy-topic-factory-action.c: (build_menu): Remove *_action_name functions, and use static buffers instead. Minor cleanups.
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/ephy-bookmark-action-group.c80
-rw-r--r--src/bookmarks/ephy-bookmark-action.c24
-rw-r--r--src/bookmarks/ephy-bookmark-action.h24
-rw-r--r--src/bookmarks/ephy-bookmark-factory-action.c9
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c38
-rw-r--r--src/bookmarks/ephy-bookmarks-menu.c50
-rw-r--r--src/bookmarks/ephy-bookmarks-ui.c101
-rw-r--r--src/bookmarks/ephy-bookmarks-ui.h42
-rw-r--r--src/bookmarks/ephy-open-tabs-action.c40
-rw-r--r--src/bookmarks/ephy-open-tabs-action.h4
-rw-r--r--src/bookmarks/ephy-topic-action-group.c90
-rw-r--r--src/bookmarks/ephy-topic-action-group.h3
-rw-r--r--src/bookmarks/ephy-topic-action.c10
-rw-r--r--src/bookmarks/ephy-topic-action.h16
-rw-r--r--src/bookmarks/ephy-topic-factory-action.c11
15 files changed, 278 insertions, 264 deletions
diff --git a/src/bookmarks/ephy-bookmark-action-group.c b/src/bookmarks/ephy-bookmark-action-group.c
index 05630bd85..522d9bc0a 100644
--- a/src/bookmarks/ephy-bookmark-action-group.c
+++ b/src/bookmarks/ephy-bookmark-action-group.c
@@ -24,6 +24,7 @@
#include "ephy-bookmark-action-group.h"
#include "ephy-bookmark-action.h"
#include "ephy-bookmarks.h"
+#include "ephy-bookmarks-ui.h"
#include "ephy-link.h"
#include "ephy-node.h"
#include "ephy-node-common.h"
@@ -36,68 +37,57 @@
static void
smart_added_cb (EphyNode *parent,
EphyNode *child,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
-
- name = ephy_bookmark_action_name (child);
- g_return_if_fail (name);
- action = gtk_action_group_get_action (actions, name);
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+
+ action = gtk_action_group_get_action (action_group, name);
- if (action)
+ if (action != NULL)
{
- ephy_bookmark_action_updated
- (EPHY_BOOKMARK_ACTION (action));
+ ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
}
-
- g_free (name);
}
-
static void
smart_removed_cb (EphyNode *parent,
EphyNode *child,
guint index,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
-
- name = ephy_bookmark_action_name (child);
- g_return_if_fail (name);
- action = gtk_action_group_get_action (actions, name);
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+
+ action = gtk_action_group_get_action (action_group, name);
- if (action)
+ if (action != NULL)
{
- ephy_bookmark_action_updated
- (EPHY_BOOKMARK_ACTION (action));
+ ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
}
-
- g_free (name);
}
static void
node_changed_cb (EphyNode *parent,
EphyNode *child,
guint property_id,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
-
- name = ephy_bookmark_action_name (child);
- g_assert (name != NULL);
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
- action = gtk_action_group_get_action (actions, name);
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+
+ action = gtk_action_group_get_action (action_group, name);
- if (action)
+ if (action != NULL)
{
- ephy_bookmark_action_updated
- (EPHY_BOOKMARK_ACTION (action));
+ ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
}
-
- g_free (name);
}
static void
@@ -106,22 +96,22 @@ node_added_cb (EphyNode *parent,
GtkActionGroup *action_group)
{
GtkAction *action;
- char *name, *accel;
-
- name = ephy_bookmark_action_name (child);
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+ char accel[256];
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+
action = ephy_bookmark_action_new (child, name);
- accel = g_strjoin ("/", "<Actions>",
- gtk_action_group_get_name (action_group),
- name, NULL);
+
+ g_snprintf (accel, sizeof (accel), "<Actions>/%s/%s",
+ gtk_action_group_get_name (action_group),
+ name);
gtk_action_set_accel_path (action, accel);
gtk_action_group_add_action (action_group, action);
g_object_unref (action);
- g_free (accel);
- g_free (name);
+ ephy_bookmark_action_updated ((EphyBookmarkAction *) action);
- ephy_bookmark_action_updated (EPHY_BOOKMARK_ACTION (action));
-
g_signal_connect_swapped (action, "open-link",
G_CALLBACK (ephy_link_open), action_group);
}
@@ -139,7 +129,7 @@ node_removed_cb (EphyNode *parent,
action = gtk_action_group_get_action (action_group, name);
- if (action)
+ if (action != NULL)
{
gtk_action_group_remove_action (action_group, action);
}
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c
index 9f4f6ea6d..4fc541e96 100644
--- a/src/bookmarks/ephy-bookmark-action.c
+++ b/src/bookmarks/ephy-bookmark-action.c
@@ -689,24 +689,14 @@ ephy_bookmark_action_get_type (void)
return type;
}
-char *
-ephy_bookmark_action_name (EphyNode *node)
-{
- return g_strdup_printf("Bmk%u", ephy_node_get_id (node));
-}
-
GtkAction *
-ephy_bookmark_action_new (EphyNode *node, char *name)
+ephy_bookmark_action_new (EphyNode *node,
+ const char *name)
{
- GtkAction *action;
-
- if(!name) name = ephy_bookmark_action_name (node);
- g_return_val_if_fail (name, NULL);
-
- action = GTK_ACTION (g_object_new (EPHY_TYPE_BOOKMARK_ACTION,
- "name", name,
- "bookmark", node,
- NULL));
+ g_assert (name != NULL);
- return action;
+ return GTK_ACTION (g_object_new (EPHY_TYPE_BOOKMARK_ACTION,
+ "name", name,
+ "bookmark", node,
+ NULL));
}
diff --git a/src/bookmarks/ephy-bookmark-action.h b/src/bookmarks/ephy-bookmark-action.h
index ec77a353b..cb770f0b4 100644
--- a/src/bookmarks/ephy-bookmark-action.h
+++ b/src/bookmarks/ephy-bookmark-action.h
@@ -37,9 +37,6 @@ G_BEGIN_DECLS
#define EPHY_IS_BOOKMARK_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EPHY_TYPE_BOOKMARK_ACTION))
#define EPHY_BOOKMARK_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_BOOKMARK_ACTION, EphyBookmarkActionClass))
-#define EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE 32 /* >= strlen ("Bmk") + max size of gulong + 1 */
-#define EPHY_BOOKMARK_ACTION_NAME_PRINTF(buffer,node) (g_snprintf (buffer, sizeof (buffer), "Bmk%u", ephy_node_get_id (node)))
-
typedef struct _EphyBookmarkAction EphyBookmarkAction;
typedef struct _EphyBookmarkActionPrivate EphyBookmarkActionPrivate;
typedef struct _EphyBookmarkActionClass EphyBookmarkActionClass;
@@ -58,22 +55,21 @@ struct _EphyBookmarkActionClass
};
-GType ephy_bookmark_action_get_type (void);
-
-char * ephy_bookmark_action_name (EphyNode *node);
-
-GtkAction * ephy_bookmark_action_new (EphyNode *node, char *name);
+GType ephy_bookmark_action_get_type (void);
+GtkAction *ephy_bookmark_action_new (EphyNode *node,
+ const char *name);
-void ephy_bookmark_action_set_bookmark (EphyBookmarkAction *action, EphyNode *node);
+void ephy_bookmark_action_set_bookmark (EphyBookmarkAction *action,
+ EphyNode *node);
-EphyNode * ephy_bookmark_action_get_bookmark (EphyBookmarkAction *action);
+EphyNode *ephy_bookmark_action_get_bookmark (EphyBookmarkAction *action);
-void ephy_bookmark_action_updated (EphyBookmarkAction *action);
+void ephy_bookmark_action_updated (EphyBookmarkAction *action);
-void ephy_bookmark_action_activate (EphyBookmarkAction *action,
- GtkWidget *widget,
- EphyLinkFlags flags);
+void ephy_bookmark_action_activate (EphyBookmarkAction *action,
+ GtkWidget *widget,
+ EphyLinkFlags flags);
G_END_DECLS
diff --git a/src/bookmarks/ephy-bookmark-factory-action.c b/src/bookmarks/ephy-bookmark-factory-action.c
index 2547c8b8f..43c4683a0 100644
--- a/src/bookmarks/ephy-bookmark-factory-action.c
+++ b/src/bookmarks/ephy-bookmark-factory-action.c
@@ -25,6 +25,7 @@
#include "ephy-bookmark-factory-action.h"
#include "ephy-bookmark-action.h"
+#include "ephy-bookmarks-ui.h"
#include "ephy-node-common.h"
#include "ephy-shell.h"
#include "ephy-stock-icons.h"
@@ -97,7 +98,8 @@ build_menu_for_topic (GtkWidget *placeholder, EggToolbarsModel *model, EphyNode
GtkWidget *menu, *item;
EphyNode *node;
GPtrArray *children, *bookmarks;
- const char *name, *action;
+ const char *name;
+ char action[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
gint i, flags;
children = ephy_node_get_children (topic);
@@ -112,10 +114,11 @@ build_menu_for_topic (GtkWidget *placeholder, EggToolbarsModel *model, EphyNode
{
node = g_ptr_array_index (bookmarks, i);
- action = ephy_bookmark_action_name (node);
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (action, node);
+
flags = egg_toolbars_model_get_name_flags (model, action);
if (flags & EGG_TB_MODEL_NAME_USED)
- continue;
+ continue;
name = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_TITLE);
item = gtk_menu_item_new_with_label (name);
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index c031a4cd0..1a2ac5f2b 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -434,7 +434,6 @@ cmd_toolbar (GtkAction *action,
EphyNode *node;
gboolean show;
const char *tname;
- char *name;
gint flags, tpos;
GList *selection;
GList *l;
@@ -455,18 +454,23 @@ cmd_toolbar (GtkAction *action,
if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->bm_view)))
{
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+
selection = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->bm_view));
node = selection->data;
- name = ephy_bookmark_action_name (node);
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, node);
+
flags = egg_toolbars_model_get_name_flags (model, name);
show = ((flags & EGG_TB_MODEL_NAME_USED) == 0);
- g_free (name);
for (l = selection; l; l = l->next)
{
node = l->data;
- name = ephy_bookmark_action_name (node);
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, node);
+
flags = egg_toolbars_model_get_name_flags (model, name);
if(show && ((flags & EGG_TB_MODEL_NAME_USED) == 0))
{
@@ -476,25 +480,29 @@ cmd_toolbar (GtkAction *action,
{
egg_toolbars_model_delete_item (model, name);
}
- g_free (name);
}
g_list_free (selection);
}
else if (ephy_node_view_is_target (EPHY_NODE_VIEW (editor->priv->key_view)))
{
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+
selection = ephy_node_view_get_selection (EPHY_NODE_VIEW (editor->priv->key_view));
node = selection->data;
- name = ephy_topic_action_name (node);
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, node);
+
flags = egg_toolbars_model_get_name_flags (model, name);
show = ((flags & EGG_TB_MODEL_NAME_USED) == 0);
- g_free (name);
for (l = selection; l; l = l->next)
{
node = l->data;
- name = ephy_topic_action_name (node);
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, node);
+
flags = egg_toolbars_model_get_name_flags (model, name);
if(show && ((flags & EGG_TB_MODEL_NAME_USED) == 0))
{
@@ -504,7 +512,6 @@ cmd_toolbar (GtkAction *action,
{
egg_toolbars_model_delete_item (model, name);
}
- g_free (name);
}
g_list_free (selection);
@@ -1250,7 +1257,6 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
GList *selected;
GtkWidget *focus_widget;
int num_bmk_selected;
- char *name;
LOG ("Update menu sensitivity");
@@ -1296,16 +1302,17 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
{
EphyNode *node = selected->data;
EphyNodePriority priority;
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
priority = ephy_node_get_property_int
(node, EPHY_NODE_KEYWORD_PROP_PRIORITY);
if (priority == -1) priority = EPHY_NODE_NORMAL_PRIORITY;
key_normal = (priority == EPHY_NODE_NORMAL_PRIORITY);
- name = ephy_topic_action_name (node);
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, node);
+
ontoolbar = ((egg_toolbars_model_get_name_flags (model, name)
& EGG_TB_MODEL_NAME_USED) != 0);
- g_free (name);
g_list_free (selected);
}
@@ -1314,17 +1321,16 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor)
if (bmk_focus && selected)
{
EphyNode *node = selected->data;
- guint id;
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
g_return_if_fail (node != NULL);
- id = ephy_node_get_id (node);
mutable = !ephy_node_get_property_boolean (node, EPHY_NODE_BMK_PROP_IMMUTABLE);
- name = ephy_bookmark_action_name (node);
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, node);
+
ontoolbar = ((egg_toolbars_model_get_name_flags (model, name)
& EGG_TB_MODEL_NAME_USED) != 0);
- g_free (name);
g_list_free (selected);
}
diff --git a/src/bookmarks/ephy-bookmarks-menu.c b/src/bookmarks/ephy-bookmarks-menu.c
index bf1673925..db19cf01c 100644
--- a/src/bookmarks/ephy-bookmarks-menu.c
+++ b/src/bookmarks/ephy-bookmarks-menu.c
@@ -51,20 +51,23 @@ enum
/* Construct a block of bookmark actions, postfixing the names with a topic id
* to allow different. */
static void
-append_bookmarks (GString *string, const GPtrArray *bookmarks, gint instance)
+append_bookmarks (GString *string,
+ const GPtrArray *bookmarks,
+ int instance)
{
- char *name;
+ EphyNode *child;
+ char name[EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE];
+
long i;
for (i = 0; i < bookmarks->len; i++)
{
- name = ephy_bookmark_action_name (g_ptr_array_index (bookmarks, i));
- if (name)
- {
- g_string_append_printf (string, "<menuitem action=\"%s\" name=\"%s-%d\"/>",
- name, name, instance);
- g_free (name);
- }
+ child = g_ptr_array_index (bookmarks, i);
+
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
+
+ g_string_append_printf (string, "<menuitem action=\"%s\" name=\"%s-%d\"/>",
+ name, name, instance);
}
}
@@ -86,7 +89,7 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
EphyNode *topic;
gint size, total;
gboolean separate = FALSE;
- char *name;
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
/* Get the subtopics, uncovered bookmarks, and subtopic sizes. */
sizes = g_array_sized_new (FALSE, FALSE, sizeof(int), topics->len);
@@ -133,17 +136,14 @@ append_menu (GString *string, const GPtrArray *topics, const GPtrArray *bookmark
{
topic = g_ptr_array_index (submenus, i);
ephy_nodes_get_covered (topic, bookmarks, subset);
-
- name = ephy_topic_action_name (topic);
- if (name)
- {
- g_string_append_printf (string, "<menu name=\"%s\" action=\"%s\">",
- name, name);
- append_menu (string, topics, subset, flags);
- g_string_append (string, "</menu>");
- separate = TRUE;
- g_free (name);
- }
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, topic);
+
+ g_string_append_printf (string, "<menu name=\"%s\" action=\"%s\">",
+ name, name);
+ append_menu (string, topics, subset, flags);
+ g_string_append (string, "</menu>");
+ separate = TRUE;
}
/* Build a list of bookmarks which don't appear in any subdivision yet. */
@@ -252,17 +252,17 @@ ephy_bookmarks_menu_build (GString *string, EphyNode *parent)
/* Otherwise, build the menu with "Open in tabs". */
else
{
- char *name;
+ char name[EPHY_OPEN_TABS_ACTION_NAME_BUFFER_SIZE];
append_menu (string, topics, children, flags);
g_ptr_array_free (topics, TRUE);
if (children->len > 1)
{
- name = ephy_open_tabs_action_name (node);
+ EPHY_OPEN_TABS_ACTION_NAME_PRINTF (name, node);
+
g_string_append_printf
- (string, "<separator/><menuitem action=\"%s\" name=\"OpenTabs\"/>", name);
- g_free (name);
+ (string, "<separator/><menuitem action=\"%s\" name=\"OpenTabs\"/>", name);
}
}
}
diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c
index acf9a0b0c..e3a9f8ebc 100644
--- a/src/bookmarks/ephy-bookmarks-ui.c
+++ b/src/bookmarks/ephy-bookmarks-ui.c
@@ -256,7 +256,7 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window)
G_CONNECT_SWAPPED | G_CONNECT_AFTER);
g_object_unref (actions);
- actions = ephy_topic_group_new (topics, manager);
+ actions = ephy_topic_action_group_new (topics, manager);
gtk_ui_manager_insert_action_group (manager, actions, -1);
g_object_unref (actions);
@@ -496,11 +496,14 @@ topic_has_data (EggToolbarsItemType *type,
EphyNode *node, *topics;
guint node_id;
- if (sscanf (name, "OpenTopic%u", &node_id) != 1 &&
- sscanf (name, "Tpc%u", &node_id) != 1) return FALSE;
+ if (sscanf (name, "OpenTopic%u" /* FIXME!! */, &node_id) != 1 &&
+ sscanf (name, EPHY_TOPIC_ACTION_NAME_FORMAT, &node_id) != 1) return FALSE;
+
node = ephy_bookmarks_get_from_id (eb, node_id);
- if (!node) return FALSE;
+ if (node == NULL) return FALSE;
+
topics = ephy_bookmarks_get_keywords (eb);
+
return ephy_node_has_child (topics, node);
}
@@ -511,22 +514,26 @@ topic_get_data (EggToolbarsItemType *type,
EphyNode *node;
guint node_id;
- if (sscanf (name, "OpenTopic%u", &node_id) != 1 &&
- sscanf (name, "Tpc%u", &node_id) != 1) return NULL;
+ if (sscanf (name, "OpenTopic%u" /* FIXME!! */, &node_id) != 1 &&
+ sscanf (name, EPHY_TOPIC_ACTION_NAME_FORMAT, &node_id) != 1) return NULL;
+
node = ephy_bookmarks_get_from_id (eb, node_id);
- if (!node) return NULL;
+ if (node == NULL) return NULL;
+
return ephy_bookmarks_get_topic_uri (eb, node);
}
static char *
topic_get_name (EggToolbarsItemType *type,
- const char *name)
+ const char *data)
{
- EphyNode *topic = ephy_bookmarks_find_keyword (eb, name, FALSE);
+ EphyNode *topic;
+
+ topic = ephy_bookmarks_find_keyword (eb, data, FALSE);
if (topic == NULL) return NULL;
- return ephy_topic_action_name (topic);
-}
+ return EPHY_TOPIC_ACTION_NAME_STRDUP_PRINTF (topic);
+}
static gboolean
bookmark_has_data (EggToolbarsItemType *type,
@@ -534,12 +541,13 @@ bookmark_has_data (EggToolbarsItemType *type,
{
EphyNode *node;
guint node_id;
-
- if (sscanf (name, "OpenBmk%u", &node_id) != 1 &&
- sscanf (name, "Bmk%u", &node_id) != 1) return FALSE;
+
+ if (sscanf (name, "OpenBmk%u" /* FIXME!! */, &node_id) != 1 &&
+ sscanf (name, EPHY_BOOKMARK_ACTION_NAME_FORMAT, &node_id) != 1) return FALSE;
+
node = ephy_bookmarks_get_from_id (eb, node_id);
- if (!node) return FALSE;
-
+ if (node == NULL) return FALSE;
+
return (ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION) != NULL);
}
@@ -549,12 +557,13 @@ bookmark_get_data (EggToolbarsItemType *type,
{
EphyNode *node;
guint node_id;
-
- if (sscanf (name, "OpenBmk%u", &node_id) != 1 &&
- sscanf (name, "Bmk%u", &node_id) != 1) return NULL;
+
+ if (sscanf (name, "OpenBmk%u" /* FIXME!! */, &node_id) != 1 &&
+ sscanf (name, EPHY_BOOKMARK_ACTION_NAME_FORMAT, &node_id) != 1) return NULL;
+
node = ephy_bookmarks_get_from_id (eb, node_id);
- if (!node) return NULL;
-
+ if (node == NULL) return NULL;
+
return g_strdup (ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION));
}
@@ -566,17 +575,19 @@ bookmark_get_name (EggToolbarsItemType *type,
gchar **netscape_url;
netscape_url = g_strsplit (data, "\n", 2);
- if (!netscape_url || !netscape_url[0])
+ if (netscape_url == NULL || netscape_url[0] == '\0')
{
g_strfreev (netscape_url);
+
return NULL;
}
node = ephy_bookmarks_find_bookmark (eb, netscape_url[0]);
g_strfreev (netscape_url);
- if (!node) return NULL;
- return ephy_bookmark_action_name (node);
+ if (node == NULL) return NULL;
+
+ return EPHY_BOOKMARK_ACTION_NAME_STRDUP_PRINTF (node);
}
static char *
@@ -587,49 +598,53 @@ bookmark_new_name (EggToolbarsItemType *type,
gchar **netscape_url;
netscape_url = g_strsplit (data, "\n", 2);
- if (!netscape_url || !netscape_url[0])
+ if (netscape_url == NULL || netscape_url[0] == '\0' || g_strv_length (netscape_url) < 2)
{
g_strfreev (netscape_url);
+
return NULL;
}
node = ephy_bookmarks_add (eb, netscape_url[1], netscape_url[0]);
-
g_strfreev (netscape_url);
- return ephy_bookmark_action_name (node);
+ return EPHY_BOOKMARK_ACTION_NAME_STRDUP_PRINTF (node);
}
static void
-toolbar_node_removed_cb (EphyNode *parent, EphyNode *child, guint index, EggToolbarsModel *model)
+toolbar_node_removed_cb (EphyNode *parent,
+ EphyNode *child,
+ guint index,
+ EggToolbarsModel *model)
{
- gint i, j;
- char *nid = NULL;
+ char name[EPHY_BOOKMARKS_UI_ACTION_NAME_BUFFER_SIZE];
const char *id;
+ int i, j;
switch (ephy_node_get_id (parent))
{
case BOOKMARKS_NODE_ID:
- nid = ephy_bookmark_action_name (child);
+ EPHY_BOOKMARK_ACTION_NAME_PRINTF (name, child);
break;
case KEYWORDS_NODE_ID:
- nid = ephy_topic_action_name (child);
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
break;
default:
return;
}
- for (i=egg_toolbars_model_n_toolbars(model)-1; i>=0; i--)
- for (j=egg_toolbars_model_n_items(model, i)-1; j>=0; j--)
- {
- id = egg_toolbars_model_item_nth (model, i, j);
- if (!strcmp (id, nid))
- {
- egg_toolbars_model_remove_item (model, i, j);
- }
- }
-
- free (nid);
+ for (i = (int) egg_toolbars_model_n_toolbars(model) - 1; i >= 0; --i)
+ {
+ for (j = (int) egg_toolbars_model_n_items (model, i) - 1; j >= 0; --j)
+ {
+ id = egg_toolbars_model_item_nth (model, i, j);
+
+ if (strcmp (id, name) == 0)
+ {
+ egg_toolbars_model_remove_item (model, i, j);
+ }
+ }
+ }
}
void
diff --git a/src/bookmarks/ephy-bookmarks-ui.h b/src/bookmarks/ephy-bookmarks-ui.h
index 5a2e33ee6..9feedae8b 100644
--- a/src/bookmarks/ephy-bookmarks-ui.h
+++ b/src/bookmarks/ephy-bookmarks-ui.h
@@ -26,16 +26,42 @@
#include <gtk/gtk.h>
-void ephy_bookmarks_ui_attach_window (EphyWindow *window);
-void ephy_bookmarks_ui_detach_window (EphyWindow *window);
+G_BEGIN_DECLS
-void ephy_bookmarks_ui_attach_toolbar_model (EggToolbarsModel *model);
-void ephy_bookmarks_ui_detach_toolbar_model (EggToolbarsModel *model);
+#define EPHY_BOOKMARKS_UI_ACTION_NAME_BUFFER_SIZE 32
-void ephy_bookmarks_ui_add_bookmark (GtkWindow *parent,
- const char *location,
- const char *title);
+#define EPHY_BOOKMARK_ACTION_NAME_BUFFER_SIZE EPHY_BOOKMARKS_UI_ACTION_NAME_BUFFER_SIZE
+#define EPHY_BOOKMARK_ACTION_NAME_FORMAT "Bmk%u"
+#define EPHY_BOOKMARK_ACTION_NAME_FORMAT_ARG(node) (ephy_node_get_id (node))
+#define EPHY_BOOKMARK_ACTION_NAME_PRINTF(buffer,node) (g_snprintf (buffer, sizeof (buffer), EPHY_BOOKMARK_ACTION_NAME_FORMAT, EPHY_BOOKMARK_ACTION_NAME_FORMAT_ARG (node)))
+#define EPHY_BOOKMARK_ACTION_NAME_STRDUP_PRINTF(node) (g_strdup_printf (EPHY_BOOKMARK_ACTION_NAME_FORMAT, EPHY_BOOKMARK_ACTION_NAME_FORMAT_ARG (node)))
-void ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark);
+#define EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE EPHY_BOOKMARKS_UI_ACTION_NAME_BUFFER_SIZE
+#define EPHY_TOPIC_ACTION_NAME_FORMAT "Tp%u"
+#define EPHY_TOPIC_ACTION_NAME_FORMAT_ARG(node) (ephy_node_get_id (node))
+#define EPHY_TOPIC_ACTION_NAME_PRINTF(buffer,node) (g_snprintf (buffer, sizeof (buffer), EPHY_TOPIC_ACTION_NAME_FORMAT, EPHY_TOPIC_ACTION_NAME_FORMAT_ARG (node)))
+#define EPHY_TOPIC_ACTION_NAME_STRDUP_PRINTF(node) (g_strdup_printf (EPHY_TOPIC_ACTION_NAME_FORMAT, EPHY_TOPIC_ACTION_NAME_FORMAT_ARG (node)))
+
+#define EPHY_OPEN_TABS_ACTION_NAME_BUFFER_SIZE EPHY_BOOKMARKS_UI_ACTION_NAME_BUFFER_SIZE
+#define EPHY_OPEN_TABS_ACTION_NAME_FORMAT "OpTb%u"
+#define EPHY_OPEN_TABS_ACTION_NAME_FORMAT_ARG(node) (ephy_node_get_id (node))
+#define EPHY_OPEN_TABS_ACTION_NAME_PRINTF(buffer,node) (g_snprintf (buffer, sizeof (buffer), EPHY_OPEN_TABS_ACTION_NAME_FORMAT, EPHY_OPEN_TABS_ACTION_NAME_FORMAT_ARG (node)))
+#define EPHY_OPEN_TABS_ACTION_NAME_STRDUP_PRINTF(node) (g_strdup_printf (EPHY_OPEN_TABS_ACTION_NAME_FORMAT, EPHY_OPEN_TABS_ACTION_NAME_FORMAT_ARG (node)))
+
+void ephy_bookmarks_ui_attach_window (EphyWindow *window);
+
+void ephy_bookmarks_ui_detach_window (EphyWindow *window);
+
+void ephy_bookmarks_ui_attach_toolbar_model (EggToolbarsModel *model);
+
+void ephy_bookmarks_ui_detach_toolbar_model (EggToolbarsModel *model);
+
+void ephy_bookmarks_ui_add_bookmark (GtkWindow *parent,
+ const char *location,
+ const char *title);
+
+void ephy_bookmarks_ui_show_bookmark (EphyNode *bookmark);
+
+G_END_DECLS
#endif
diff --git a/src/bookmarks/ephy-open-tabs-action.c b/src/bookmarks/ephy-open-tabs-action.c
index eb0955446..7b54f5365 100644
--- a/src/bookmarks/ephy-open-tabs-action.c
+++ b/src/bookmarks/ephy-open-tabs-action.c
@@ -23,6 +23,7 @@
#include "ephy-open-tabs-action.h"
#include "ephy-bookmarks.h"
+#include "ephy-bookmarks-ui.h"
#include "ephy-node-common.h"
#include "ephy-link-action.h"
#include "ephy-link.h"
@@ -67,14 +68,14 @@ node_added_cb (EphyNode *parent,
{
GObject *action_object;
GtkAction *action;
- char *name, *accel;
-
- name = ephy_open_tabs_action_name (child);
- g_assert (name != NULL);
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+ char accel[256];
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
+
/* FIXME !!!! */
action = gtk_action_new (name, _("Open in New _Tabs"), "Open this topic in tabs", NULL);
- action_object = G_OBJECT (action);
+ action_object = (GObject *) action;
g_object_set_data (action_object, "ephy-node", child);
g_object_set_data (action_object, "ephy-link", EPHY_LINK (action_group));
@@ -82,17 +83,13 @@ node_added_cb (EphyNode *parent,
g_signal_connect (action, "activate",
G_CALLBACK (activate_cb), NULL);
- accel = g_strjoin ("/", "<Actions>",
- gtk_action_group_get_name (action_group),
- name,
- NULL);
+ g_snprintf (accel, sizeof (accel), "<Actions>/%s/%s",
+ gtk_action_group_get_name (action_group),
+ name);
gtk_action_set_accel_path (action, accel);
gtk_action_group_add_action (action_group, action);
g_object_unref (action);
-
- g_free (accel);
- g_free (name);
}
static void
@@ -102,16 +99,15 @@ node_removed_cb (EphyNode *parent,
GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
- name = ephy_open_tabs_action_name (child);
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
+
+ action = gtk_action_group_get_action (action_group, name);
- // FIXME can this really ever be NULL ??
- if (name)
+ if (action != NULL)
{
- action = gtk_action_group_get_action (action_group, name);
- if (action) gtk_action_group_remove_action (action_group, action);
- g_free (name);
+ gtk_action_group_remove_action (action_group, action);
}
}
@@ -140,9 +136,3 @@ ephy_open_tabs_group_new (EphyNode *node)
return action_group;
}
-
-char *
-ephy_open_tabs_action_name (EphyNode *node)
-{
- return g_strdup_printf("OpTb%u", ephy_node_get_id (node));
-}
diff --git a/src/bookmarks/ephy-open-tabs-action.h b/src/bookmarks/ephy-open-tabs-action.h
index 5e67c94d7..31e8a48ec 100644
--- a/src/bookmarks/ephy-open-tabs-action.h
+++ b/src/bookmarks/ephy-open-tabs-action.h
@@ -25,8 +25,6 @@
#include "ephy-node.h"
-char * ephy_open_tabs_action_name (EphyNode *node);
-
-GtkActionGroup * ephy_open_tabs_group_new (EphyNode *node);
+GtkActionGroup *ephy_open_tabs_group_new (EphyNode *node);
#endif
diff --git a/src/bookmarks/ephy-topic-action-group.c b/src/bookmarks/ephy-topic-action-group.c
index 29c0668ff..d94e2897f 100644
--- a/src/bookmarks/ephy-topic-action-group.c
+++ b/src/bookmarks/ephy-topic-action-group.c
@@ -25,102 +25,104 @@
#include "ephy-node.h"
#include "ephy-node-common.h"
#include "ephy-bookmarks.h"
+#include "ephy-bookmarks-ui.h"
#include "ephy-debug.h"
#include <gtk/gtkaction.h>
#include <gtk/gtkactiongroup.h>
-#include <string.h>
-
static void
node_changed_cb (EphyNode *parent,
EphyNode *child,
guint property_id,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
-
- name = ephy_topic_action_name (child);
- g_return_if_fail (name != NULL);
- action = gtk_action_group_get_action (actions, name);
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
+
+ action = gtk_action_group_get_action (action_group, name);
if (property_id == EPHY_NODE_KEYWORD_PROP_NAME)
{
ephy_topic_action_updated (EPHY_TOPIC_ACTION (action));
}
-
- g_free (name);
}
static void
node_added_cb (EphyNode *parent,
EphyNode *child,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkUIManager *manager;
GtkAction *action;
- char *name, *accel;
-
- manager = g_object_get_data ((GObject *)actions, "ui-manager");
- name = ephy_topic_action_name (child);
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+ char accel[256];
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
+
+ manager = g_object_get_data ((GObject *) action_group, "ui-manager");
+
action = ephy_topic_action_new (child, manager, name);
- accel = g_strjoin ("/", "<Actions>",
- gtk_action_group_get_name (actions),
- name, NULL);
+
+ g_snprintf (accel, sizeof (accel), "<Actions>/%s/%s",
+ gtk_action_group_get_name (action_group),
+ name);
gtk_action_set_accel_path (action, accel);
- gtk_action_group_add_action (actions, action);
+
+ gtk_action_group_add_action (action_group, action);
g_object_unref (action);
- g_free (accel);
- g_free (name);
- ephy_topic_action_updated (EPHY_TOPIC_ACTION (action));
+ ephy_topic_action_updated ((EphyTopicAction *) action);
}
static void
node_removed_cb (EphyNode *parent,
EphyNode *child, guint index,
- GtkActionGroup *actions)
+ GtkActionGroup *action_group)
{
GtkAction *action;
- char *name;
+ char name[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (name, child);
- name = ephy_topic_action_name (child);
- g_return_if_fail (name != NULL);
- action = gtk_action_group_get_action (actions, name);
+ action = gtk_action_group_get_action (action_group, name);
if (action)
{
- gtk_action_group_remove_action (actions, action);
+ gtk_action_group_remove_action (action_group, action);
}
-
- g_free (name);
}
GtkActionGroup *
-ephy_topic_group_new (EphyNode *node,
- GtkUIManager *manager)
+ephy_topic_action_group_new (EphyNode *node,
+ GtkUIManager *manager)
{
- GPtrArray *children = ephy_node_get_children (node);
- GObject *actions = (GObject *) gtk_action_group_new ("TopicActions");
- gint i;
+ GPtrArray *children;
+ GtkActionGroup *action_group;
+ int i;
- g_object_set_data (G_OBJECT (actions), "ui-manager", manager);
+ children = ephy_node_get_children (node);
+ action_group = gtk_action_group_new ("TpAc");
+
+ g_object_set_data ((GObject *) action_group, "ui-manager", manager);
for (i = 0; i < children->len; i++)
{
- node_added_cb (node, g_ptr_array_index (children, i), (GtkActionGroup *)actions);
+ node_added_cb (node, g_ptr_array_index (children, i),
+ action_group);
}
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_ADDED,
- (EphyNodeCallback)node_added_cb,
- actions);
+ (EphyNodeCallback) node_added_cb,
+ (GObject *) action_group);
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_REMOVED,
- (EphyNodeCallback)node_removed_cb,
- actions);
+ (EphyNodeCallback) node_removed_cb,
+ (GObject *) action_group);
ephy_node_signal_connect_object (node, EPHY_NODE_CHILD_CHANGED,
- (EphyNodeCallback)node_changed_cb,
- actions);
+ (EphyNodeCallback) node_changed_cb,
+ (GObject *) action_group);
- return GTK_ACTION_GROUP (actions);
+ return (GtkActionGroup *) action_group;
}
diff --git a/src/bookmarks/ephy-topic-action-group.h b/src/bookmarks/ephy-topic-action-group.h
index a37fc4500..9c17b6714 100644
--- a/src/bookmarks/ephy-topic-action-group.h
+++ b/src/bookmarks/ephy-topic-action-group.h
@@ -29,7 +29,8 @@
G_BEGIN_DECLS
-GtkActionGroup * ephy_topic_group_new (EphyNode *node, GtkUIManager *manager);
+GtkActionGroup *ephy_topic_action_group_new (EphyNode *node,
+ GtkUIManager *manager);
G_END_DECLS
diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c
index 2ce6b5f7f..3923ef793 100644
--- a/src/bookmarks/ephy-topic-action.c
+++ b/src/bookmarks/ephy-topic-action.c
@@ -583,18 +583,12 @@ ephy_topic_action_get_type (void)
return type;
}
-char *
-ephy_topic_action_name (EphyNode *node)
-{
- return g_strdup_printf("Tpc%u", ephy_node_get_id (node));
-}
-
GtkAction *
ephy_topic_action_new (EphyNode *node,
GtkUIManager *manager,
- char *name)
+ const char *name)
{
- g_return_val_if_fail (name, NULL);
+ g_assert (name != NULL);
return GTK_ACTION (g_object_new (EPHY_TYPE_TOPIC_ACTION,
"name", name,
diff --git a/src/bookmarks/ephy-topic-action.h b/src/bookmarks/ephy-topic-action.h
index f6be79b4c..05c9accb7 100644
--- a/src/bookmarks/ephy-topic-action.h
+++ b/src/bookmarks/ephy-topic-action.h
@@ -55,18 +55,18 @@ struct _EphyTopicActionClass
};
-GType ephy_topic_action_get_type (void);
+GType ephy_topic_action_get_type (void);
-char * ephy_topic_action_name (EphyNode *node);
+GtkAction *ephy_topic_action_new (EphyNode *node,
+ GtkUIManager *manager,
+ const char *name);
-GtkAction * ephy_topic_action_new (EphyNode *node, GtkUIManager *manager, char *name);
+void ephy_topic_action_set_topic (EphyTopicAction *action,
+ EphyNode *node);
+EphyNode *ephy_topic_action_get_topic (EphyTopicAction *action);
-void ephy_topic_action_set_topic (EphyTopicAction *action, EphyNode *node);
-
-EphyNode * ephy_topic_action_get_topic (EphyTopicAction *action);
-
-void ephy_topic_action_updated (EphyTopicAction *action);
+void ephy_topic_action_updated (EphyTopicAction *action);
G_END_DECLS
diff --git a/src/bookmarks/ephy-topic-factory-action.c b/src/bookmarks/ephy-topic-factory-action.c
index 44e9e0dd9..cb202c65c 100644
--- a/src/bookmarks/ephy-topic-factory-action.c
+++ b/src/bookmarks/ephy-topic-factory-action.c
@@ -27,6 +27,7 @@
#include "ephy-topic-factory-action.h"
#include "ephy-topic-action.h"
+#include "ephy-bookmarks-ui.h"
#include "ephy-shell.h"
#include "ephy-stock-icons.h"
#include "egg-editable-toolbar.h"
@@ -141,8 +142,9 @@ build_menu (GtkWidget *placeholder, EggToolbarsModel *model)
EphyBookmarks *eb;
EphyNode *node;
GPtrArray *children, *topics;
-
- const char *name, *action;
+
+ const char *name;
+ char action[EPHY_TOPIC_ACTION_NAME_BUFFER_SIZE];
gint i, priority = -1, ptmp, flags;
/* Get a sorted list of topics. */
@@ -158,8 +160,9 @@ build_menu (GtkWidget *placeholder, EggToolbarsModel *model)
for (i = 0; i < topics->len; i++)
{
node = g_ptr_array_index (topics, i);
-
- action = ephy_topic_action_name (node);
+
+ EPHY_TOPIC_ACTION_NAME_PRINTF (action, node);
+
flags = egg_toolbars_model_get_name_flags (model, action);
if (flags & EGG_TB_MODEL_NAME_USED)
continue;