diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2006-02-09 21:52:45 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2006-02-09 21:52:45 +0800 |
commit | a6c15fb7c0718216ea3950324fd6465f334d16dc (patch) | |
tree | 14ac97b90d9fe663f1af63d0ab4e011a474b2975 /src | |
parent | 119a3c3c65eee95efaa155ba06635f693e79ecfc (diff) | |
download | gsoc2013-epiphany-a6c15fb7c0718216ea3950324fd6465f334d16dc.tar.gz gsoc2013-epiphany-a6c15fb7c0718216ea3950324fd6465f334d16dc.tar.zst gsoc2013-epiphany-a6c15fb7c0718216ea3950324fd6465f334d16dc.zip |
Misc code cleanups: fewer gobject casts, disconnect handlers, save a few
2006-02-09 Christian Persch <chpe@cvs.gnome.org>
* src/bookmarks/ephy-bookmark-action-group.c: (node_changed_cb),
(node_added_cb), (node_removed_cb), (ephy_bookmark_group_new):
* src/bookmarks/ephy-bookmark-action.c:
(ephy_bookmark_action_sync_smart_url),
(ephy_bookmark_action_sync_icon), (connect_proxy),
(ephy_bookmark_action_set_bookmark),
(ephy_bookmark_action_get_property), (ephy_bookmark_action_init),
(ephy_bookmark_action_dispose), (ephy_bookmark_action_class_init),
(ephy_bookmark_action_get_type):
* src/bookmarks/ephy-bookmark-action.h:
* src/bookmarks/ephy-bookmarks-ui.c:
(ephy_bookmarks_ui_attach_window):
* src/bookmarks/ephy-open-tabs-action.c: (activate_cb),
(node_added_cb), (node_removed_cb), (ephy_open_tabs_group_new),
(ephy_open_tabs_action_name):
* src/bookmarks/ephy-related-action.c: (node_changed),
(node_destroyed), (open_link), (ephy_related_action_new):
* src/bookmarks/ephy-topics-entry.c:
* src/bookmarks/ephy-topics-entry.h:
Misc code cleanups: fewer gobject casts, disconnect handlers,
save a few strdups etc.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmark-action-group.c | 72 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.c | 156 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.h | 3 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-ui.c | 6 | ||||
-rw-r--r-- | src/bookmarks/ephy-open-tabs-action.c | 109 | ||||
-rw-r--r-- | src/bookmarks/ephy-related-action.c | 146 | ||||
-rw-r--r-- | src/bookmarks/ephy-topics-entry.c | 1 | ||||
-rw-r--r-- | src/bookmarks/ephy-topics-entry.h | 3 |
8 files changed, 282 insertions, 214 deletions
diff --git a/src/bookmarks/ephy-bookmark-action-group.c b/src/bookmarks/ephy-bookmark-action-group.c index 85598df94..05630bd85 100644 --- a/src/bookmarks/ephy-bookmark-action-group.c +++ b/src/bookmarks/ephy-bookmark-action-group.c @@ -87,13 +87,14 @@ node_changed_cb (EphyNode *parent, char *name; name = ephy_bookmark_action_name (child); - g_return_if_fail (name); + g_assert (name != NULL); + action = gtk_action_group_get_action (actions, name); if (action) { ephy_bookmark_action_updated - (EPHY_BOOKMARK_ACTION (action)); + (EPHY_BOOKMARK_ACTION (action)); } g_free (name); @@ -102,7 +103,7 @@ node_changed_cb (EphyNode *parent, static void node_added_cb (EphyNode *parent, EphyNode *child, - GtkActionGroup *actions) + GtkActionGroup *action_group) { GtkAction *action; char *name, *accel; @@ -110,72 +111,77 @@ node_added_cb (EphyNode *parent, name = ephy_bookmark_action_name (child); action = ephy_bookmark_action_new (child, name); accel = g_strjoin ("/", "<Actions>", - gtk_action_group_get_name (actions), + gtk_action_group_get_name (action_group), name, NULL); 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_bookmark_action_updated (EPHY_BOOKMARK_ACTION (action)); - g_signal_connect_swapped (G_OBJECT(action), "open-link", - G_CALLBACK (ephy_link_open), actions); + g_signal_connect_swapped (action, "open-link", + G_CALLBACK (ephy_link_open), action_group); } static void node_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) { - gtk_action_group_remove_action (actions, action); + gtk_action_group_remove_action (action_group, action); } - - g_free (name); } GtkActionGroup * ephy_bookmark_group_new (EphyNode *node) { - EphyBookmarks *bookmarks = ephy_shell_get_bookmarks (ephy_shell); - EphyNode *smart = ephy_bookmarks_get_smart_bookmarks (bookmarks); - - GPtrArray *children = ephy_node_get_children (node); - GObject *actions = (GObject *) ephy_link_action_group_new ("BA"); + EphyBookmarks *bookmarks; + EphyNode *smart; + GPtrArray *children; + GtkActionGroup *action_group; guint i; + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + smart = ephy_bookmarks_get_smart_bookmarks (bookmarks); + + action_group = (GtkActionGroup *) ephy_link_action_group_new ("BA"); + + children = ephy_node_get_children (node); 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); ephy_node_signal_connect_object (smart, EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback)smart_added_cb, - actions); + (EphyNodeCallback) smart_added_cb, + (GObject *) action_group); ephy_node_signal_connect_object (smart, EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback)smart_removed_cb, - actions); + (EphyNodeCallback) smart_removed_cb, + (GObject *) action_group); - return GTK_ACTION_GROUP (actions); + return action_group; } diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 11fd985e8..9f4f6ea6d 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -59,9 +59,6 @@ static const GtkTargetEntry drag_types[] = { #define TOOLITEM_WIDTH_CHARS 20 #define LABEL_WIDTH_CHARS 32 -static void ephy_bookmark_action_init (EphyBookmarkAction *action); -static void ephy_bookmark_action_class_init (EphyBookmarkActionClass *class); - #define EPHY_BOOKMARK_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_BOOKMARK_ACTION, EphyBookmarkActionPrivate)) struct _EphyBookmarkActionPrivate @@ -81,35 +78,7 @@ enum PROP_ICON }; -static GObjectClass *parent_class = NULL; - -GType -ephy_bookmark_action_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo type_info = - { - sizeof (EphyBookmarkActionClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ephy_bookmark_action_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (EphyBookmarkAction), - 0, /* n_preallocs */ - (GInstanceInitFunc) ephy_bookmark_action_init, - }; - - type = g_type_register_static (EPHY_TYPE_LINK_ACTION, - "EphyBookmarkAction", - &type_info, 0); - } - - return type; -} +static GObjectClass *parent_class; static GtkWidget * create_tool_item (GtkAction *action) @@ -157,7 +126,9 @@ create_tool_item (GtkAction *action) } static void -ephy_bookmark_action_sync_smart_url (GtkAction *gaction, GParamSpec *pspec, GtkWidget *proxy) +ephy_bookmark_action_sync_smart_url (GtkAction *gaction, + GParamSpec *pspec, + GtkWidget *proxy) { if (GTK_IS_TOOL_ITEM (proxy)) { @@ -203,7 +174,9 @@ favicon_cache_changed_cb (EphyFaviconCache *cache, } static void -ephy_bookmark_action_sync_icon (GtkAction *action, GParamSpec *pspec, GtkWidget *proxy) +ephy_bookmark_action_sync_icon (GtkAction *action, + GParamSpec *pspec, + GtkWidget *proxy) { EphyBookmarkAction *bma = EPHY_BOOKMARK_ACTION (action); const char *icon_location; @@ -214,9 +187,9 @@ ephy_bookmark_action_sync_icon (GtkAction *action, GParamSpec *pspec, GtkWidget icon_location = ephy_node_get_property_string (bma->priv->node, EPHY_NODE_BMK_PROP_ICON); - + cache = EPHY_FAVICON_CACHE (ephy_embed_shell_get_favicon_cache - (EPHY_EMBED_SHELL (ephy_shell))); + (ephy_embed_shell_get_default ())); if (icon_location && *icon_location) { @@ -436,7 +409,8 @@ drag_data_get_cb (GtkWidget *widget, } static void -connect_proxy (GtkAction *action, GtkWidget *proxy) +connect_proxy (GtkAction *action, + GtkWidget *proxy) { GtkWidget *button, *entry; @@ -530,17 +504,20 @@ ephy_bookmark_action_get_bookmark (EphyBookmarkAction *action) void ephy_bookmark_action_set_bookmark (EphyBookmarkAction *action, EphyNode *node) -{ +{ + EphyBookmarkActionPrivate *priv = action->priv; + GObject *object = G_OBJECT (action); + g_return_if_fail (node != NULL); - - action->priv->node = node; - - g_object_freeze_notify (G_OBJECT (action)); - - g_object_notify (G_OBJECT (action), "bookmark"); + + priv->node = node; + + g_object_freeze_notify (object); + + g_object_notify (object, "bookmark"); ephy_bookmark_action_updated (action); - - g_object_thaw_notify (G_OBJECT (action)); + + g_object_thaw_notify (object); } static void @@ -572,37 +549,57 @@ ephy_bookmark_action_get_property (GObject *object, GParamSpec *pspec) { EphyBookmarkAction *action = EPHY_BOOKMARK_ACTION (object); + EphyBookmarkActionPrivate *priv = action->priv; - g_return_if_fail (action->priv->node != NULL); + g_return_if_fail (priv->node != NULL); switch (prop_id) { case PROP_BOOKMARK: - g_value_set_pointer (value, action->priv->node); + g_value_set_pointer (value, priv->node); break; case PROP_TOOLTIP: case PROP_LOCATION: g_value_set_string (value, - ephy_node_get_property_string (action->priv->node, + ephy_node_get_property_string (priv->node, EPHY_NODE_BMK_PROP_LOCATION)); break; case PROP_SMART_URL: - g_value_set_boolean (value, action->priv->smart_url); + g_value_set_boolean (value, priv->smart_url); break; case PROP_ICON: g_value_set_string (value, - ephy_node_get_property_string (action->priv->node, + ephy_node_get_property_string (priv->node, EPHY_NODE_BMK_PROP_ICON)); break; } } static void -ephy_bookmark_action_finalize (GObject *object) +ephy_bookmark_action_init (EphyBookmarkAction *action) { - LOG ("Bookmark action %p finalized", object); + action->priv = EPHY_BOOKMARK_ACTION_GET_PRIVATE (action); + + action->priv->cache_handler = 0; +} + +static void +ephy_bookmark_action_dispose (GObject *object) +{ + EphyBookmarkAction *action = (EphyBookmarkAction *) object; + EphyBookmarkActionPrivate *priv = action->priv; + GObject *cache; - parent_class->finalize (object); + if (priv->cache_handler != 0) + { + cache = ephy_embed_shell_get_favicon_cache + (ephy_embed_shell_get_default ()); + + g_signal_handler_disconnect (cache, priv->cache_handler); + priv->cache_handler = 0; + } + + parent_class->dispose (object); } static void @@ -618,15 +615,15 @@ ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) action_class->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM; action_class->connect_proxy = connect_proxy; - object_class->finalize = ephy_bookmark_action_finalize; + object_class->dispose = ephy_bookmark_action_dispose; object_class->set_property = ephy_bookmark_action_set_property; object_class->get_property = ephy_bookmark_action_get_property; g_object_class_install_property (object_class, PROP_BOOKMARK, g_param_spec_pointer ("bookmark", - "Bookmark", - "Bookmark", + "bookmark", + "bookmark", G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_CONSTRUCT_ONLY)); @@ -634,41 +631,62 @@ ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) g_object_class_install_property (object_class, PROP_TOOLTIP, g_param_spec_string ("tooltip", - "Tooltip", - "Tooltip", + "tooltip", + "tooltip", NULL, G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, PROP_LOCATION, g_param_spec_string ("location", - "Location", - "Location", + "location", + "location", NULL, G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, PROP_SMART_URL, g_param_spec_boolean ("smarturl", - "Smart url", - "Smart url", + "smarturl", + "smarturl", FALSE, G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, PROP_ICON, g_param_spec_string ("icon", - "Icon", - "Icon", + "icon", + "icon", NULL, G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); g_type_class_add_private (object_class, sizeof(EphyBookmarkActionPrivate)); } -static void -ephy_bookmark_action_init (EphyBookmarkAction *action) +GType +ephy_bookmark_action_get_type (void) { - action->priv = EPHY_BOOKMARK_ACTION_GET_PRIVATE (action); - action->priv->cache_handler = 0; + static GType type = 0; + + if (G_UNLIKELY (type == 0)) + { + static const GTypeInfo type_info = + { + sizeof (EphyBookmarkActionClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) ephy_bookmark_action_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (EphyBookmarkAction), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_bookmark_action_init, + }; + + type = g_type_register_static (EPHY_TYPE_LINK_ACTION, + "EphyBookmarkAction", + &type_info, 0); + } + + return type; } char * diff --git a/src/bookmarks/ephy-bookmark-action.h b/src/bookmarks/ephy-bookmark-action.h index 205923b20..ec77a353b 100644 --- a/src/bookmarks/ephy-bookmark-action.h +++ b/src/bookmarks/ephy-bookmark-action.h @@ -37,6 +37,9 @@ 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; diff --git a/src/bookmarks/ephy-bookmarks-ui.c b/src/bookmarks/ephy-bookmarks-ui.c index 199e8d5bc..acf9a0b0c 100644 --- a/src/bookmarks/ephy-bookmarks-ui.c +++ b/src/bookmarks/ephy-bookmarks-ui.c @@ -251,14 +251,14 @@ ephy_bookmarks_ui_attach_window (EphyWindow *window) /* Create the self-maintaining action groups for bookmarks and topics */ actions = ephy_bookmark_group_new (bookmarks); gtk_ui_manager_insert_action_group (manager, actions, -1); - g_signal_connect_object (G_OBJECT (actions), "open-link", + g_signal_connect_object (actions, "open-link", G_CALLBACK (ephy_link_open), G_OBJECT (window), G_CONNECT_SWAPPED | G_CONNECT_AFTER); - g_object_unref (G_OBJECT (actions)); + g_object_unref (actions); actions = ephy_topic_group_new (topics, manager); gtk_ui_manager_insert_action_group (manager, actions, -1); - g_object_unref (G_OBJECT (actions)); + g_object_unref (actions); actions = ephy_open_tabs_group_new (topics); gtk_ui_manager_insert_action_group (manager, actions, -1); diff --git a/src/bookmarks/ephy-open-tabs-action.c b/src/bookmarks/ephy-open-tabs-action.c index 137769ea1..eb0955446 100644 --- a/src/bookmarks/ephy-open-tabs-action.c +++ b/src/bookmarks/ephy-open-tabs-action.c @@ -18,78 +18,99 @@ * $Id$ */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif - -#include <gtk/gtktoolitem.h> -#include <glib/gi18n.h> -#include <libgnomevfs/gnome-vfs-uri.h> -#include <string.h> #include "ephy-open-tabs-action.h" + #include "ephy-bookmarks.h" #include "ephy-node-common.h" #include "ephy-link-action.h" #include "ephy-link.h" +#include <glib/gi18n.h> +#include <gtk/gtktoolitem.h> + +#include <libgnomevfs/gnome-vfs-uri.h> + +#include <string.h> + static void -activate_cb (GtkAction *action, gpointer dummy) +activate_cb (GtkAction *action, + gpointer dummy) { - EphyLink *link = g_object_get_data (G_OBJECT (action), "ephy-link"); - EphyNode *node = g_object_get_data (G_OBJECT (action), "ephy-node"); - GPtrArray *children = ephy_node_get_children (node); + GObject *object = G_OBJECT (action); + EphyLink *link; + EphyNode *node; + GPtrArray *children; EphyTab *tab = 0; - - gint i; const char *url; + guint i; - for (i = 0; i < children->len; i++) + link = g_object_get_data (object, "ephy-link"); + node = g_object_get_data (object, "ephy-node"); + + children = ephy_node_get_children (node); + for (i = 0; i < children->len; ++i) { node = g_ptr_array_index (children, i); + url = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION); - tab = ephy_link_open (link, url, tab, EPHY_LINK_NEW_TAB); + tab = ephy_link_open (link, url, tab, + EPHY_LINK_NEW_TAB | ephy_link_flags_from_current_event ()); } } static void -node_added_cb (EphyNode *parent, EphyNode *child, GObject *object) +node_added_cb (EphyNode *parent, + EphyNode *child, + GtkActionGroup *action_group) { - GtkActionGroup *actions = GTK_ACTION_GROUP (object); + GObject *action_object; GtkAction *action; char *name, *accel; name = ephy_open_tabs_action_name (child); - g_return_if_fail (name); + g_assert (name != NULL); + /* FIXME !!!! */ action = gtk_action_new (name, _("Open in New _Tabs"), "Open this topic in tabs", NULL); + action_object = G_OBJECT (action); + + g_object_set_data (action_object, "ephy-node", child); + g_object_set_data (action_object, "ephy-link", EPHY_LINK (action_group)); - g_object_set_data (G_OBJECT (action), "ephy-node", child); - g_object_set_data (G_OBJECT (action), "ephy-link", EPHY_LINK (object)); - - g_signal_connect (G_OBJECT (action), "activate", + g_signal_connect (action, "activate", G_CALLBACK (activate_cb), NULL); - + accel = g_strjoin ("/", "<Actions>", - gtk_action_group_get_name (actions), + gtk_action_group_get_name (action_group), name, NULL); + 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); } static void -node_removed_cb (EphyNode *parent, EphyNode *child, guint index, GObject *object) +node_removed_cb (EphyNode *parent, + EphyNode *child, + guint index, + GtkActionGroup *action_group) { - char *name = ephy_open_tabs_action_name (child); + GtkAction *action; + char *name; + + name = ephy_open_tabs_action_name (child); + + // FIXME can this really ever be NULL ?? if (name) { - GtkActionGroup *actions = GTK_ACTION_GROUP (object); - GtkAction *action = gtk_action_group_get_action (actions, name); - if (action) gtk_action_group_remove_action (actions, action); + action = gtk_action_group_get_action (action_group, name); + if (action) gtk_action_group_remove_action (action_group, action); g_free (name); } } @@ -97,25 +118,31 @@ node_removed_cb (EphyNode *parent, EphyNode *child, guint index, GObject *object GtkActionGroup * ephy_open_tabs_group_new (EphyNode *node) { - GPtrArray *children = ephy_node_get_children (node); - GObject *actions = G_OBJECT (ephy_link_action_group_new ("OpenTabsActions")); - gint i; + GPtrArray *children; + GtkActionGroup *action_group; + guint i; + children = ephy_node_get_children (node); + action_group = (GtkActionGroup *) ephy_link_action_group_new ("OpenTabsActions"); + for (i = 0; i < children->len; i++) - node_added_cb (node, g_ptr_array_index (children, i), 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); - return GTK_ACTION_GROUP (actions); + return action_group; } char * ephy_open_tabs_action_name (EphyNode *node) { - return g_strdup_printf("OpenTabs%u", ephy_node_get_id (node)); + return g_strdup_printf("OpTb%u", ephy_node_get_id (node)); } diff --git a/src/bookmarks/ephy-related-action.c b/src/bookmarks/ephy-related-action.c index 30db41481..3b83fba60 100644 --- a/src/bookmarks/ephy-related-action.c +++ b/src/bookmarks/ephy-related-action.c @@ -20,31 +20,38 @@ #include "config.h" -#include <gtk/gtk.h> -#include <gtk/gtkaction.h> -#include <gtk/gtkactiongroup.h> -#include <glib/gi18n.h> +#include "ephy-related-action.h" #include "ephy-window.h" #include "ephy-bookmarks.h" #include "ephy-shell.h" #include "ephy-node-common.h" #include "ephy-stock-icons.h" -#include "ephy-related-action.h" + +#include <gtk/gtk.h> +#include <gtk/gtkaction.h> +#include <gtk/gtkactiongroup.h> +#include <glib/gi18n.h> static void -node_changed (EphyNode *node, guint propertyid, GObject *object) +node_changed (EphyNode *node, + guint propertyid, + EphyTopicAction *action) { - ephy_topic_action_updated (EPHY_TOPIC_ACTION (object)); + ephy_topic_action_updated (action); } static void -node_destroyed (EphyNode *node, GObject *object) +node_destroyed (EphyNode *node, + EphyTopicAction *action) { - EphyBookmarks *eb = ephy_shell_get_bookmarks (ephy_shell); - - ephy_topic_action_set_topic (EPHY_TOPIC_ACTION (object), - ephy_bookmarks_get_favorites (eb)); + EphyBookmarks *eb; + EphyNode *favorites; + + eb = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + favorites = ephy_bookmarks_get_favorites (eb); + + ephy_topic_action_set_topic (action, favorites); } static EphyTab * @@ -53,57 +60,58 @@ open_link (EphyLink *link, EphyTab *tab, EphyLinkFlags flags) { - EphyBookmarks *eb = ephy_shell_get_bookmarks (ephy_shell); - EphyNode *bookmark = ephy_bookmarks_find_bookmark (eb, address); + EphyBookmarks *eb; + EphyNode *bookmark; EphyNode *topic, *chosen = NULL; + GPtrArray *topics; + gint i, tmp, best = 0; - if (bookmark != NULL) + eb = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + bookmark = ephy_bookmarks_find_bookmark (eb, address); + if (bookmark == NULL) return NULL; + + topic = ephy_topic_action_get_topic (EPHY_TOPIC_ACTION (link)); + tmp = ephy_node_get_property_int (topic, EPHY_NODE_KEYWORD_PROP_PRIORITY); + if (tmp == EPHY_NODE_NORMAL_PRIORITY && + ephy_node_has_child (topic, bookmark)) + { + return NULL; + } + ephy_node_signal_disconnect_object (topic, EPHY_NODE_CHANGED, + (EphyNodeCallback) node_changed, + G_OBJECT (link)); + ephy_node_signal_disconnect_object (topic, EPHY_NODE_DESTROY, + (EphyNodeCallback) node_destroyed, + G_OBJECT (link)); + + topics = ephy_node_get_children (ephy_bookmarks_get_keywords (eb)); + for (i = 0; i < topics->len; i++) { - GPtrArray *topics; - gint i, tmp, best = 0; - - topic = ephy_topic_action_get_topic (EPHY_TOPIC_ACTION (link)); - tmp = ephy_node_get_property_int (topic, EPHY_NODE_KEYWORD_PROP_PRIORITY); + topic = g_ptr_array_index (topics, i); + tmp = ephy_node_get_property_int (topic, EPHY_NODE_KEYWORD_PROP_PRIORITY); if (tmp == EPHY_NODE_NORMAL_PRIORITY && ephy_node_has_child (topic, bookmark)) { - return NULL; - } - ephy_node_signal_disconnect_object (topic, EPHY_NODE_CHANGED, - (EphyNodeCallback) node_changed, - G_OBJECT (link)); - ephy_node_signal_disconnect_object (topic, EPHY_NODE_DESTROY, - (EphyNodeCallback) node_destroyed, - G_OBJECT (link)); - - topics = ephy_node_get_children (ephy_bookmarks_get_keywords (eb)); - for (i = 0; i < topics->len; i++) - { - topic = g_ptr_array_index (topics, i); - tmp = ephy_node_get_property_int (topic, EPHY_NODE_KEYWORD_PROP_PRIORITY); - if (tmp == EPHY_NODE_NORMAL_PRIORITY && - ephy_node_has_child (topic, bookmark)) + tmp = ephy_node_get_n_children (topic); + if (chosen == NULL || + (tmp >= 10 && tmp <= best)) { - tmp = ephy_node_get_n_children (topic); - if (chosen == NULL || (tmp >= 10 && tmp <= best)) - { - chosen = topic; - best = tmp; - } + chosen = topic; + best = tmp; } } - - if (chosen == NULL) chosen = ephy_bookmarks_get_favorites (eb); - - ephy_topic_action_set_topic (EPHY_TOPIC_ACTION (link), chosen); - ephy_node_signal_connect_object (chosen, EPHY_NODE_CHANGED, - (EphyNodeCallback) node_changed, - G_OBJECT (link)); - ephy_node_signal_connect_object (chosen, EPHY_NODE_DESTROY, - (EphyNodeCallback) node_destroyed, - G_OBJECT (link)); } + if (chosen == NULL) chosen = ephy_bookmarks_get_favorites (eb); + + ephy_topic_action_set_topic (EPHY_TOPIC_ACTION (link), chosen); + ephy_node_signal_connect_object (chosen, EPHY_NODE_CHANGED, + (EphyNodeCallback) node_changed, + G_OBJECT (link)); + ephy_node_signal_connect_object (chosen, EPHY_NODE_DESTROY, + (EphyNodeCallback) node_destroyed, + G_OBJECT (link)); + return NULL; } @@ -151,24 +159,28 @@ ephy_related_action_get_type (void) } GtkAction * -ephy_related_action_new (EphyLink *link, GtkUIManager *manager, char * name) +ephy_related_action_new (EphyLink *link, + GtkUIManager *manager, + char * name) { - EphyBookmarks *eb = ephy_shell_get_bookmarks (ephy_shell); - EphyNode *favorites = ephy_bookmarks_get_favorites (eb); - - EphyRelatedAction *action = - EPHY_RELATED_ACTION (g_object_new (EPHY_TYPE_RELATED_ACTION, - "name", name, - "topic", favorites, - "short_label", _("Related"), - "stock-id", GTK_STOCK_INDEX, - "manager", manager, - NULL)); + EphyBookmarks *eb; + EphyNode *favorites; + EphyRelatedAction *action; + + eb = ephy_shell_get_bookmarks (ephy_shell); + favorites = ephy_bookmarks_get_favorites (eb); + + action = (EphyRelatedAction *) (g_object_new (EPHY_TYPE_RELATED_ACTION, + "name", name, + "topic", favorites, + "short_label", _("Related"), + "stock-id", GTK_STOCK_INDEX, + "manager", manager, + NULL)); - g_signal_connect_object (G_OBJECT (link), "open-link", + g_signal_connect_object (link, "open-link", G_CALLBACK (ephy_link_open), action, G_CONNECT_SWAPPED); - return GTK_ACTION (action); + return (GtkAction *) action; } - diff --git a/src/bookmarks/ephy-topics-entry.c b/src/bookmarks/ephy-topics-entry.c index 02a305e60..0df525799 100644 --- a/src/bookmarks/ephy-topics-entry.c +++ b/src/bookmarks/ephy-topics-entry.c @@ -27,6 +27,7 @@ #include <glib/gi18n.h> #include <gtk/gtktreeselection.h> +#include <gtk/gtkentry.h> #include <gtk/gtkentrycompletion.h> #include <string.h> diff --git a/src/bookmarks/ephy-topics-entry.h b/src/bookmarks/ephy-topics-entry.h index 295e0ab65..db3713600 100644 --- a/src/bookmarks/ephy-topics-entry.h +++ b/src/bookmarks/ephy-topics-entry.h @@ -22,7 +22,8 @@ #define EPHY_TOPICS_ENTRY_H #include "ephy-bookmarks.h" -#include <gtk/gtk.h> + +#include <gtk/gtkentry.h> G_BEGIN_DECLS |