From c90132b2e18252796eabf770ac2334c381b5d1f5 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Wed, 23 Feb 2011 13:56:01 -0500 Subject: Rework widget_notify_cb() to get the properties directly. --- libdbusmenu-gtk/parser.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f516dde..b910ee7 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -750,30 +750,34 @@ widget_notify_cb (GtkWidget *widget, gpointer data) { DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + GValue prop_value = {0}; + + g_value_init (&prop_value, pspec->value_type); + g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value); if (pspec->name == g_intern_static_string ("sensitive")) { dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_ENABLED, - gtk_widget_get_sensitive (widget)); + g_value_get_boolean (&prop_value)); } else if (pspec->name == g_intern_static_string ("label")) { dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_menu_item_get_label (GTK_MENU_ITEM (widget))); + g_value_get_string (&prop_value)); } else if (pspec->name == g_intern_static_string ("visible")) { dbusmenu_menuitem_property_set_bool (child, DBUSMENU_MENUITEM_PROP_VISIBLE, - gtk_widget_get_visible (widget)); + g_value_get_boolean (&prop_value)); } else if (pspec->name == g_intern_static_string ("image") || pspec->name == g_intern_static_string ("always-show-image")) { GtkWidget *image; - image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); + image = GTK_WIDGET (g_value_get_object (&prop_value)); update_icon (child, GTK_IMAGE (image)); } else if (pspec->name == g_intern_static_string ("parent")) @@ -782,7 +786,7 @@ widget_notify_cb (GtkWidget *widget, * We probably should have added a 'remove' method to the * UbuntuMenuProxy early on, but it's late in the cycle now. */ - if (gtk_widget_get_parent (widget) == NULL) + if (GTK_WIDGET (g_value_get_object (&prop_value)) == NULL) { g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (widget_notify_cb), @@ -818,7 +822,7 @@ widget_notify_cb (GtkWidget *widget, recurse.parent = item; if (item != NULL) { - GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + GtkWidget * menu = GTK_WIDGET (g_value_get_object (&prop_value)); parse_menu_structure_helper(menu, &recurse); } else { /* Note: it would be really odd that we wouldn't have a cached @@ -827,6 +831,7 @@ widget_notify_cb (GtkWidget *widget, g_object_unref(G_OBJECT(recurse.parent)); } } + g_value_unset (&prop_value); } /* A child item was added to a menu we're watching. Let's try to integrate it. */ -- cgit v1.2.3 From 5653c7e5642ae25fb54445f749ecfb0c947ead0c Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Thu, 24 Feb 2011 15:41:16 +0000 Subject: Disconnect the theme_changed_cb handler when widgets are destroyed --- libdbusmenu-gtk/parser.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f2fcb58..09b1e6e 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -161,6 +161,15 @@ dbusmenu_item_freed (gpointer data, GObject * obj) } } +static void +widget_freed (gpointer data, GObject * obj) +{ + g_signal_handlers_disconnect_by_func(gtk_icon_theme_get_default(), G_CALLBACK(theme_changed_cb), obj); + + return; +} + +#if 0 /* Called if we replace the cache on the object with a new dbusmenu menuitem */ static void @@ -175,6 +184,7 @@ object_cache_freed (gpointer data) return; } +#endif /* Gets the positon of the child with its' parent if it has one. Returns -1 if the position is unable to be calculated. */ @@ -213,8 +223,9 @@ new_menuitem (GtkWidget * widget) ParserData *pdata = g_new0 (ParserData, 1); g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, parse_data_free); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, item, object_cache_freed); + /* g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, item, object_cache_freed); */ g_object_weak_ref(G_OBJECT(item), dbusmenu_item_freed, NULL); + g_object_weak_ref(G_OBJECT(widget), widget_freed, NULL); pdata->widget = widget; g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); -- cgit v1.2.3 From 37fb090b4f9fb1e1a894c5c57e7c3d28eb71f92d Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Thu, 24 Feb 2011 15:43:25 +0000 Subject: Hold a weak pointer to each DbusmenuMenuitems parent. This avoids using g_object_{get/set}_data for storing a nodes parent in the parser code, and the associated problems with that (ie, a child out-living its parent, leading to invalid reads --- libdbusmenu-gtk/parser.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 09b1e6e..44ea301 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -321,10 +321,6 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) /* Oops, let's tell our parents about us */ if (peek == NULL) { - /* TODO: Should we set a weak ref on the parent? */ - g_object_set_data (G_OBJECT (thisitem), - "dbusmenu-parent", - recurse->parent); gint pos = get_child_position (widget); if (pos >= 0) dbusmenu_menuitem_child_add_position (recurse->parent, @@ -813,7 +809,7 @@ widget_notify_cb (GtkWidget *widget, G_CALLBACK (widget_notify_cb), child); - DbusmenuMenuitem *parent = g_object_get_data (G_OBJECT (child), "dbusmenu-parent"); + DbusmenuMenuitem *parent = dbusmenu_menuitem_get_parent (child); if (DBUSMENU_IS_MENUITEM (parent) && DBUSMENU_IS_MENUITEM (child)) { -- cgit v1.2.3 From 017f243186a993adda6b55eac436bb7b6ce784c2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 24 Feb 2011 10:22:46 -0600 Subject: Not commenting out code, just deleteing --- libdbusmenu-gtk/parser.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 09b1e6e..a68508b 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -169,23 +169,6 @@ widget_freed (gpointer data, GObject * obj) return; } -#if 0 -/* Called if we replace the cache on the object with a new - dbusmenu menuitem */ -static void -object_cache_freed (gpointer data) -{ - // TODO: make this have access to both data and obj so we can call these - //if (!G_IS_OBJECT(obj)) return; - //g_object_weak_unref(G_OBJECT(obj), dbusmenu_cache_freed, data); - //dbusmenu_cache_freed(data, obj); - - g_signal_handlers_disconnect_by_func(gtk_icon_theme_get_default(), G_CALLBACK(theme_changed_cb), data); - - return; -} -#endif - /* Gets the positon of the child with its' parent if it has one. Returns -1 if the position is unable to be calculated. */ static gint @@ -223,7 +206,6 @@ new_menuitem (GtkWidget * widget) ParserData *pdata = g_new0 (ParserData, 1); g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, parse_data_free); - /* g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, item, object_cache_freed); */ g_object_weak_ref(G_OBJECT(item), dbusmenu_item_freed, NULL); g_object_weak_ref(G_OBJECT(widget), widget_freed, NULL); -- cgit v1.2.3