aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-favorites-menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ephy-favorites-menu.c')
-rw-r--r--src/ephy-favorites-menu.c287
1 files changed, 131 insertions, 156 deletions
diff --git a/src/ephy-favorites-menu.c b/src/ephy-favorites-menu.c
index ef31b3c52..f5da952d3 100644
--- a/src/ephy-favorites-menu.c
+++ b/src/ephy-favorites-menu.c
@@ -21,19 +21,11 @@
#endif
#include "ephy-favorites-menu.h"
-#include "ephy-gobject-misc.h"
-#include "ephy-string.h"
#include "egg-menu-merge.h"
-#include "ephy-marshal.h"
+#include "ephy-bookmark-action.h"
#include "ephy-shell.h"
#include "ephy-debug.h"
-#include <string.h>
-#include <stdlib.h>
-#include <libxml/entities.h>
-
-#define MAX_LABEL_LENGTH 30
-
/**
* Private data
*/
@@ -45,27 +37,12 @@ struct _EphyFavoritesMenuPrivate
guint ui_id;
};
-typedef struct
-{
- EphyWindow *window;
- const char *url;
-} FavoriteData;
-
/**
* Private functions, only availble from this file
*/
static void ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass);
static void ephy_favorites_menu_init (EphyFavoritesMenu *wrhm);
-static void ephy_favorites_menu_finalize_impl (GObject *o);
-static void ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm);
-static void ephy_favorites_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void ephy_favorites_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+static void ephy_favorites_menu_finalize (GObject *o);
enum
{
@@ -73,45 +50,33 @@ enum
PROP_EPHY_WINDOW
};
-static gpointer g_object_class;
-
-/**
- * EphyFavoritesMenu object
- */
-MAKE_GET_TYPE (ephy_favorites_menu,
- "EphyFavoritesMenu", EphyFavoritesMenu,
- ephy_favorites_menu_class_init, ephy_favorites_menu_init,
- G_TYPE_OBJECT);
-
-static void
-ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- G_OBJECT_CLASS (klass)->finalize = ephy_favorites_menu_finalize_impl;
- g_object_class = g_type_class_peek_parent (klass);
-
- object_class->set_property = ephy_favorites_menu_set_property;
- object_class->get_property = ephy_favorites_menu_get_property;
-
- g_object_class_install_property (object_class,
- PROP_EPHY_WINDOW,
- g_param_spec_object ("EphyWindow",
- "EphyWindow",
- "Parent window",
- EPHY_WINDOW_TYPE,
- G_PARAM_READWRITE));
-}
+static gpointer parent_class;
-static void
-ephy_favorites_menu_init (EphyFavoritesMenu *wrhm)
+GType
+ephy_favorites_menu_get_type (void)
{
- EphyFavoritesMenuPrivate *p = g_new0 (EphyFavoritesMenuPrivate, 1);
- wrhm->priv = p;
+ static GType ephy_favorites_menu_type = 0;
- wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell);
- wrhm->priv->ui_id = -1;
- wrhm->priv->action_group = NULL;
+ if (ephy_favorites_menu_type == 0)
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (EphyFavoritesMenuClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) ephy_favorites_menu_class_init,
+ NULL,
+ NULL, /* class_data */
+ sizeof (EphyFavoritesMenu),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) ephy_favorites_menu_init
+ };
+
+ ephy_favorites_menu_type = g_type_register_static (G_TYPE_OBJECT,
+ "EphyFavoritesMenu",
+ &our_info, 0);
+ }
+ return ephy_favorites_menu_type;
}
static void
@@ -134,71 +99,14 @@ ephy_favorites_menu_clean (EphyFavoritesMenu *wrhm)
}
static void
-ephy_favorites_menu_finalize_impl (GObject *o)
-{
- EphyFavoritesMenu *wrhm = EPHY_FAVORITES_MENU (o);
- EphyFavoritesMenuPrivate *p = wrhm->priv;
-
- if (p->action_group != NULL)
- {
- egg_menu_merge_remove_action_group
- (EGG_MENU_MERGE (p->window->ui_merge),
- p->action_group);
- g_object_unref (p->action_group);
- }
-
- g_free (p);
-
- G_OBJECT_CLASS (g_object_class)->finalize (o);
-}
-
-static void
-ephy_favorites_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object);
-
- switch (prop_id)
- {
- case PROP_EPHY_WINDOW:
- m->priv->window = g_value_get_object (value);
- ephy_favorites_menu_rebuild (m);
- break;
- }
-}
-
-static void
-ephy_favorites_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+go_location_cb (EggAction *action, char *location, EphyWindow *window)
{
- EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object);
+ EphyEmbed *embed;
- switch (prop_id)
- {
- case PROP_EPHY_WINDOW:
- g_value_set_object (value, m->priv->window);
- break;
- }
-}
+ embed = ephy_window_get_active_embed (window);
+ g_return_if_fail (embed != NULL);
-EphyFavoritesMenu *
-ephy_favorites_menu_new (EphyWindow *window)
-{
- EphyFavoritesMenu *ret = g_object_new (EPHY_TYPE_FAVORITES_MENU,
- "EphyWindow", window,
- NULL);
- return ret;
-}
-
-static void
-ephy_favorites_menu_verb_cb (EggMenuMerge *merge,
- FavoriteData *data)
-{
- ephy_window_load_url (data->window, data->url);
+ ephy_embed_load_url (embed, location);
}
static void
@@ -229,38 +137,17 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm)
for (i = 0; i < children->len; i++)
{
char *verb = g_strdup_printf ("GoFav%d", i);
- char *title_s;
- const char *title;
- const char *url;
- xmlChar *label_x;
- EphyNode *child;
- FavoriteData *data;
+ EphyNode *node;
EggAction *action;
- child = g_ptr_array_index (children, i);
- title = ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_TITLE);
- url = ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_LOCATION);
- title_s = ephy_string_shorten (title, MAX_LABEL_LENGTH);
- label_x = xmlEncodeSpecialChars (NULL, title_s);
-
- data = g_new0 (FavoriteData, 1);
- data->window = wrhm->priv->window;
- data->url = url;
-
- action = g_object_new (EGG_TYPE_ACTION,
- "name", verb,
- "label", label_x,
- "tooltip", "Hello",
- "stock_id", NULL,
- NULL);
- g_signal_connect_closure
- (action, "activate",
- g_cclosure_new (G_CALLBACK (ephy_favorites_menu_verb_cb),
- data,
- (GClosureNotify)g_free),
- FALSE);
+ node = g_ptr_array_index (children, i);
+
+ action = ephy_bookmark_action_new (verb,
+ ephy_node_get_id (node));
egg_action_group_add_action (p->action_group, action);
g_object_unref (action);
+ g_signal_connect (action, "go_location",
+ G_CALLBACK (go_location_cb), p->window);
g_string_append (xml, "<menuitem name=\"");
g_string_append (xml, verb);
@@ -268,12 +155,7 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm)
g_string_append (xml, "\" verb=\"");
g_string_append (xml, verb);
g_string_append (xml, "\"/>\n");
-
- xmlFree (label_x);
- g_free (title_s);
- g_free (verb);
}
-
ephy_node_thaw (fav);
g_string_append (xml, "</placeholder></submenu></menu></Root>");
@@ -289,6 +171,99 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm)
g_string_free (xml, TRUE);
}
+static void
+ephy_favorites_menu_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object);
+
+ switch (prop_id)
+ {
+ case PROP_EPHY_WINDOW:
+ m->priv->window = g_value_get_object (value);
+ ephy_favorites_menu_rebuild (m);
+ break;
+ }
+}
+
+static void
+ephy_favorites_menu_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyFavoritesMenu *m = EPHY_FAVORITES_MENU (object);
+
+ switch (prop_id)
+ {
+ case PROP_EPHY_WINDOW:
+ g_value_set_object (value, m->priv->window);
+ break;
+ }
+}
+
+
+static void
+ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->finalize = ephy_favorites_menu_finalize;
+ object_class->set_property = ephy_favorites_menu_set_property;
+ object_class->get_property = ephy_favorites_menu_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_EPHY_WINDOW,
+ g_param_spec_object ("EphyWindow",
+ "EphyWindow",
+ "Parent window",
+ EPHY_WINDOW_TYPE,
+ G_PARAM_READWRITE));
+}
+
+static void
+ephy_favorites_menu_init (EphyFavoritesMenu *wrhm)
+{
+ EphyFavoritesMenuPrivate *p = g_new0 (EphyFavoritesMenuPrivate, 1);
+ wrhm->priv = p;
+
+ wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell);
+ wrhm->priv->ui_id = -1;
+ wrhm->priv->action_group = NULL;
+}
+
+static void
+ephy_favorites_menu_finalize (GObject *o)
+{
+ EphyFavoritesMenu *wrhm = EPHY_FAVORITES_MENU (o);
+ EphyFavoritesMenuPrivate *p = wrhm->priv;
+
+ if (p->action_group != NULL)
+ {
+ egg_menu_merge_remove_action_group
+ (EGG_MENU_MERGE (p->window->ui_merge),
+ p->action_group);
+ g_object_unref (p->action_group);
+ }
+
+ g_free (p);
+
+ G_OBJECT_CLASS (parent_class)->finalize (o);
+}
+
+EphyFavoritesMenu *
+ephy_favorites_menu_new (EphyWindow *window)
+{
+ EphyFavoritesMenu *ret = g_object_new (EPHY_TYPE_FAVORITES_MENU,
+ "EphyWindow", window,
+ NULL);
+ return ret;
+}
+
void ephy_favorites_menu_update (EphyFavoritesMenu *wrhm)
{
ephy_favorites_menu_rebuild (wrhm);