diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-10-18 19:29:17 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-10-18 19:29:17 +0800 |
commit | 8e878e61d90213c812163e1cf5a56381ff8cb641 (patch) | |
tree | 9da1ee081db5ec170f6b55e2c911f64a639c8182 | |
parent | ed1beb51d5c674250dcb31db142c6cb27f996fcf (diff) | |
download | gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar.gz gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar.bz2 gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar.lz gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar.xz gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.tar.zst gsoc2013-epiphany-8e878e61d90213c812163e1cf5a56381ff8cb641.zip |
Get rid of the last vestige of ephy_window_update_control(), and make the
2003-10-18 Christian Persch <chpe@cvs.gnome.org>
* src/bookmarks/ephy-bookmarks.c: (add_to_favorites),
(history_site_visited_cb):
* src/ephy-favorites-menu.c: (ephy_favorites_menu_get_type),
(ephy_favorites_menu_clean), (ephy_favorites_menu_rebuild),
(ephy_favorites_menu_set_property),
(ephy_favorites_menu_get_property),
(ephy_favorites_menu_class_init), (do_updates), (fav_removed_cb),
(fav_added_cb), (ephy_favorites_menu_init),
(ephy_favorites_menu_finalize), (ephy_favorites_menu_new):
* src/ephy-favorites-menu.h:
* src/ephy-window.c:
* src/ephy-window.h:
Get rid of the last vestige of ephy_window_update_control(), and make
the favourites menu self-updating.
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 24 | ||||
-rw-r--r-- | src/ephy-favorites-menu.c | 190 | ||||
-rw-r--r-- | src/ephy-favorites-menu.h | 29 | ||||
-rw-r--r-- | src/ephy-window.c | 23 | ||||
-rw-r--r-- | src/ephy-window.h | 8 |
6 files changed, 144 insertions, 148 deletions
@@ -1,3 +1,21 @@ +2003-10-18 Christian Persch <chpe@cvs.gnome.org> + + * src/bookmarks/ephy-bookmarks.c: (add_to_favorites), + (history_site_visited_cb): + * src/ephy-favorites-menu.c: (ephy_favorites_menu_get_type), + (ephy_favorites_menu_clean), (ephy_favorites_menu_rebuild), + (ephy_favorites_menu_set_property), + (ephy_favorites_menu_get_property), + (ephy_favorites_menu_class_init), (do_updates), (fav_removed_cb), + (fav_added_cb), (ephy_favorites_menu_init), + (ephy_favorites_menu_finalize), (ephy_favorites_menu_new): + * src/ephy-favorites-menu.h: + * src/ephy-window.c: + * src/ephy-window.h: + + Get rid of the last vestige of ephy_window_update_control(), and make + the favourites menu self-updating. + 2003-10-18 Marco Pesenti Gritti <marco@gnome.org> * src/ephy-window.c: (setup_window): diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 9dc4e977e..be3ebe1f9 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -397,7 +397,7 @@ add_to_favorites (EphyBookmarks *eb, EphyNode *node, EphyHistory *eh) url = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION); score = get_history_item_score (eh, url); full_menu = ephy_node_get_n_children (eb->priv->favorites) - > MAX_FAVORITES_NUM; + >= MAX_FAVORITES_NUM; if (full_menu && score < eb->priv->lower_score) return FALSE; if (eb->priv->lower_fav && full_menu) @@ -413,23 +413,6 @@ add_to_favorites (EphyBookmarks *eb, EphyNode *node, EphyHistory *eh) } static void -update_favorites_menus () -{ - Session *session; - const GList *l; - - session = EPHY_SESSION (ephy_shell_get_session (ephy_shell)); - l = session_get_windows (session); - - for (; l != NULL; l = l->next) - { - EphyWindow *window = EPHY_WINDOW (l->data); - - ephy_window_update_control (window, FavoritesControl); - } -} - -static void history_site_visited_cb (EphyHistory *gh, const char *url, EphyBookmarks *eb) { EphyNode *node; @@ -437,10 +420,7 @@ history_site_visited_cb (EphyHistory *gh, const char *url, EphyBookmarks *eb) node = ephy_bookmarks_find_bookmark (eb, url); if (node == NULL) return; - if (add_to_favorites (eb, node, gh)) - { - update_favorites_menus (); - } + add_to_favorites (eb, node, gh); } static void diff --git a/src/ephy-favorites-menu.c b/src/ephy-favorites-menu.c index c191b721e..67dafe759 100644 --- a/src/ephy-favorites-menu.c +++ b/src/ephy-favorites-menu.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2002 Ricardo Fernández Pascual + * Copyright (C) 2003 Marco Pesenti Gritti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,10 +31,6 @@ #include <gtk/gtkuimanager.h> #include <glib/gprintf.h> -/** - * Private data - */ - #define EPHY_FAVORITES_MENU_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuPrivate)) struct _EphyFavoritesMenuPrivate @@ -42,19 +39,17 @@ struct _EphyFavoritesMenuPrivate EphyBookmarks *bookmarks; GtkActionGroup *action_group; guint ui_id; + guint update_tag; }; -/** - * 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_init (EphyFavoritesMenu *menu); static void ephy_favorites_menu_finalize (GObject *o); enum { PROP_0, - PROP_EPHY_WINDOW + PROP_WINDOW }; static gpointer parent_class; @@ -62,34 +57,34 @@ static gpointer parent_class; GType ephy_favorites_menu_get_type (void) { - static GType ephy_favorites_menu_type = 0; - - 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 GType ephy_favorites_menu_type = 0; + + 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 -ephy_favorites_menu_clean (EphyFavoritesMenu *wrhm) +ephy_favorites_menu_clean (EphyFavoritesMenu *menu) { - EphyFavoritesMenuPrivate *p = wrhm->priv; + EphyFavoritesMenuPrivate *p = menu->priv; GtkUIManager *merge = GTK_UI_MANAGER (p->window->ui_merge); if (p->ui_id > 0) @@ -113,9 +108,9 @@ go_location_cb (GtkAction *action, char *location, EphyWindow *window) } static void -ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) +ephy_favorites_menu_rebuild (EphyFavoritesMenu *menu) { - EphyFavoritesMenuPrivate *p = wrhm->priv; + EphyFavoritesMenuPrivate *p = menu->priv; gint i; EphyNode *fav; GPtrArray *children; @@ -125,7 +120,7 @@ ephy_favorites_menu_rebuild (EphyFavoritesMenu *wrhm) START_PROFILER ("Rebuild favorites menu") - ephy_favorites_menu_clean (wrhm); + ephy_favorites_menu_clean (menu); fav = ephy_bookmarks_get_favorites (p->bookmarks); children = ephy_node_get_children (fav); @@ -169,31 +164,31 @@ ephy_favorites_menu_set_property (GObject *object, 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; - } + EphyFavoritesMenu *menu = EPHY_FAVORITES_MENU (object); + + switch (prop_id) + { + case PROP_WINDOW: + menu->priv->window = g_value_get_object (value); + ephy_favorites_menu_rebuild (menu); + break; + } } static void ephy_favorites_menu_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + 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; - } + EphyFavoritesMenu *menu = EPHY_FAVORITES_MENU (object); + + switch (prop_id) + { + case PROP_WINDOW: + g_value_set_object (value, menu->priv->window); + break; + } } @@ -209,9 +204,9 @@ ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass) 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", + PROP_WINDOW, + g_param_spec_object ("window", + "Window", "Parent window", EPHY_TYPE_WINDOW, G_PARAM_READWRITE | @@ -220,26 +215,71 @@ ephy_favorites_menu_class_init (EphyFavoritesMenuClass *klass) g_type_class_add_private (object_class, sizeof(EphyFavoritesMenuPrivate)); } +static gboolean +do_updates (EphyFavoritesMenu *menu) +{ + ephy_favorites_menu_rebuild (menu); + + menu->priv->update_tag = 0; + + /* don't run again */ + return FALSE; +} + static void -ephy_favorites_menu_init (EphyFavoritesMenu *wrhm) +fav_removed_cb (EphyNode *node, + EphyNode *child, + guint old_index, + EphyFavoritesMenu *menu) { - EphyFavoritesMenuPrivate *p = EPHY_FAVORITES_MENU_GET_PRIVATE (wrhm); - wrhm->priv = p; + if (menu->priv->update_tag == 0) + { + menu->priv->update_tag = g_idle_add((GSourceFunc)do_updates, menu); + } +} + +static void +fav_added_cb (EphyNode *node, + EphyNode *child, + EphyFavoritesMenu *menu) +{ + if (menu->priv->update_tag == 0) + { + menu->priv->update_tag = g_idle_add((GSourceFunc)do_updates, menu); + } +} - wrhm->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell); - wrhm->priv->ui_id = 0; - wrhm->priv->action_group = NULL; +static void +ephy_favorites_menu_init (EphyFavoritesMenu *menu) +{ + EphyFavoritesMenuPrivate *p = EPHY_FAVORITES_MENU_GET_PRIVATE (menu); + EphyNode *fav; + menu->priv = p; + + menu->priv->bookmarks = ephy_shell_get_bookmarks (ephy_shell); + menu->priv->ui_id = 0; + menu->priv->update_tag = 0; + menu->priv->action_group = NULL; + + fav = ephy_bookmarks_get_favorites (menu->priv->bookmarks); + ephy_node_signal_connect_object (fav, + EPHY_NODE_CHILD_REMOVED, + (EphyNodeCallback) fav_removed_cb, + G_OBJECT (menu)); + ephy_node_signal_connect_object (fav, + EPHY_NODE_CHILD_ADDED, + (EphyNodeCallback) fav_added_cb, + G_OBJECT (menu)); } static void ephy_favorites_menu_finalize (GObject *o) { - EphyFavoritesMenu *wrhm = EPHY_FAVORITES_MENU (o); - EphyFavoritesMenuPrivate *p = wrhm->priv; + EphyFavoritesMenu *menu = EPHY_FAVORITES_MENU (o); - if (p->action_group != NULL) + if (menu->priv->action_group != NULL) { - g_object_unref (p->action_group); + g_object_unref (menu->priv->action_group); } G_OBJECT_CLASS (parent_class)->finalize (o); @@ -248,13 +288,7 @@ ephy_favorites_menu_finalize (GObject *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); + return g_object_new (EPHY_TYPE_FAVORITES_MENU, + "window", window, + NULL); } diff --git a/src/ephy-favorites-menu.h b/src/ephy-favorites-menu.h index 78bd74193..c7d069283 100644 --- a/src/ephy-favorites-menu.h +++ b/src/ephy-favorites-menu.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2002 Ricardo Fernández Pascual + * Copyright (C) 2002 Ricardo Fernández Pascual + * Copyright (C) 2003 Marco Pesenti Gritti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,29 +22,24 @@ #include "ephy-window.h" -/* object forward declarations */ +G_BEGIN_DECLS + +#define EPHY_TYPE_FAVORITES_MENU (ephy_favorites_menu_get_type()) +#define EPHY_FAVORITES_MENU(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenu)) +#define EPHY_FAVORITES_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuClass)) +#define EPHY_IS_FAVORITES_MENU(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_FAVORITES_MENU)) +#define EPHY_IS_FAVORITES_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_FAVORITES_MENU)) +#define EPHY_FAVORITES_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuClass)) typedef struct _EphyFavoritesMenu EphyFavoritesMenu; typedef struct _EphyFavoritesMenuClass EphyFavoritesMenuClass; typedef struct _EphyFavoritesMenuPrivate EphyFavoritesMenuPrivate; -/** - * Editor object - */ - -#define EPHY_TYPE_FAVORITES_MENU (ephy_favorites_menu_get_type()) -#define EPHY_FAVORITES_MENU(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenu)) -#define EPHY_FAVORITES_MENU_CLASS(klass)(G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuClass)) -#define EPHY_IS_FAVORITES_MENU(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_FAVORITES_MENU)) -#define EPHY_IS_FAVORITES_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_FAVORITES_MENU)) -#define EPHY_FAVORITES_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_FAVORITES_MENU, EphyFavoritesMenuClass)) - struct _EphyFavoritesMenuClass { GObjectClass parent_class; }; -/* Remember: fields are public read-only */ struct _EphyFavoritesMenu { GObject parent_object; @@ -51,11 +47,10 @@ struct _EphyFavoritesMenu EphyFavoritesMenuPrivate *priv; }; -GType ephy_favorites_menu_get_type (void); +GType ephy_favorites_menu_get_type (void); EphyFavoritesMenu *ephy_favorites_menu_new (EphyWindow *window); -void ephy_favorites_menu_update (EphyFavoritesMenu *wrhm); +G_END_DECLS #endif - diff --git a/src/ephy-window.c b/src/ephy-window.c index 0ff42c00a..3cf31c15e 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1696,29 +1696,6 @@ ephy_window_show (GtkWidget *widget) GTK_WIDGET_CLASS (parent_class)->show (widget); } -static void -update_favorites_control (EphyWindow *window) -{ - ephy_favorites_menu_update (window->priv->fav_menu); -} - -void -ephy_window_update_control (EphyWindow *window, - ControlID control) -{ - g_return_if_fail (EPHY_IS_WINDOW (window)); - - switch (control) - { - case FavoritesControl: - update_favorites_control (window); - break; - default: - g_warning ("unknown control specified for updating"); - break; - } -} - EphyTab * ephy_window_get_active_tab (EphyWindow *window) { diff --git a/src/ephy-window.h b/src/ephy-window.h index 4f5a4d677..598d72194 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -61,11 +61,6 @@ typedef enum FullscreenMode } EphyWindowMode; -typedef enum -{ - FavoritesControl -} ControlID; - /* Include the header down here to resolve circular dependency */ #include "ephy-tab.h" @@ -99,9 +94,6 @@ void ephy_window_set_zoom (EphyWindow *window, void ephy_window_activate_location (EphyWindow *window); -void ephy_window_update_control (EphyWindow *window, - ControlID control); - EphyTab *ephy_window_get_active_tab (EphyWindow *window); EphyEmbed *ephy_window_get_active_embed (EphyWindow *window); |