Merge lp:~ted/libdbusmenu/lp746091 into lp:libdbusmenu/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: 294
Proposed branch: lp:~ted/libdbusmenu/lp746091
Merge into: lp:libdbusmenu/0.5
Diff against target: 158 lines (+24/-29)
5 files modified
libdbusmenu-glib/client-menuitem.c (+1/-1)
libdbusmenu-glib/client-private.h (+2/-1)
libdbusmenu-glib/client.c (+1/-2)
libdbusmenu-gtk/client.c (+6/-25)
libdbusmenu-gtk/menu.c (+14/-0)
To merge this branch: bzr merge lp:~ted/libdbusmenu/lp746091
Reviewer Review Type Date Requested Status
DBus Menu Team Pending
Review via email: mp+56850@code.launchpad.net

Description of the change

Make the destruction cleaner.

To post a comment you must log in.
lp:~ted/libdbusmenu/lp746091 updated
296. By Ted Gould

Attaching the data in a way that it'll cleanup itself

297. By Ted Gould

Protecting the label with the null check and don't unref something that shouldn't be.

298. By Ted Gould

Passing the menuitem instead of finding it.

299. By Ted Gould

Ensuring all the menus are hidden before unref'ing root

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libdbusmenu-glib/client-menuitem.c'
--- libdbusmenu-glib/client-menuitem.c 2011-02-21 18:55:10 +0000
+++ libdbusmenu-glib/client-menuitem.c 2011-04-11 04:46:25 +0000
@@ -106,7 +106,7 @@
106handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp)106handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp)
107{107{
108 DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi);108 DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi);
109 dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp);109 dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp, mi);
110 return;110 return;
111}111}
112112
113113
=== modified file 'libdbusmenu-glib/client-private.h'
--- libdbusmenu-glib/client-private.h 2011-02-21 18:55:10 +0000
+++ libdbusmenu-glib/client-private.h 2011-04-11 04:46:25 +0000
@@ -37,7 +37,8 @@
37 gint id,37 gint id,
38 const gchar * name,38 const gchar * name,
39 GVariant * variant,39 GVariant * variant,
40 guint timestamp);40 guint timestamp,
41 DbusmenuMenuitem * mi);
41void dbusmenu_client_send_about_to_show(DbusmenuClient * client,42void dbusmenu_client_send_about_to_show(DbusmenuClient * client,
42 gint id,43 gint id,
43 void (*cb) (gpointer user_data),44 void (*cb) (gpointer user_data),
4445
=== modified file 'libdbusmenu-glib/client.c'
--- libdbusmenu-glib/client.c 2011-04-07 15:04:04 +0000
+++ libdbusmenu-glib/client.c 2011-04-11 04:46:25 +0000
@@ -1516,14 +1516,13 @@
1516/* Sends the event over DBus to the server on the other side1516/* Sends the event over DBus to the server on the other side
1517 of the bus. */1517 of the bus. */
1518void1518void
1519dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp)1519dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp, DbusmenuMenuitem * mi)
1520{1520{
1521 g_return_if_fail(DBUSMENU_IS_CLIENT(client));1521 g_return_if_fail(DBUSMENU_IS_CLIENT(client));
1522 g_return_if_fail(id >= 0);1522 g_return_if_fail(id >= 0);
1523 g_return_if_fail(name != NULL);1523 g_return_if_fail(name != NULL);
15241524
1525 DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);1525 DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
1526 DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id);
1527 if (mi == NULL) {1526 if (mi == NULL) {
1528 g_warning("Asked to activate a menuitem %d that we don't know about", id);1527 g_warning("Asked to activate a menuitem %d that we don't know about", id);
1529 return;1528 return;
15301529
=== modified file 'libdbusmenu-gtk/client.c'
--- libdbusmenu-gtk/client.c 2011-04-05 18:38:28 +0000
+++ libdbusmenu-gtk/client.c 2011-04-11 04:46:25 +0000
@@ -571,7 +571,8 @@
571 } else {571 } else {
572 /* We need to build a menu for these guys to live in. */572 /* We need to build a menu for these guys to live in. */
573 GtkMenu * menu = GTK_MENU(gtk_menu_new());573 GtkMenu * menu = GTK_MENU(gtk_menu_new());
574 g_object_set_data(G_OBJECT(mi), data_menu, menu);574 g_object_ref_sink(menu);
575 g_object_set_data_full(G_OBJECT(mi), data_menu, menu, g_object_unref);
575576
576 gtk_menu_item_set_submenu(gmi, GTK_WIDGET(menu));577 gtk_menu_item_set_submenu(gmi, GTK_WIDGET(menu));
577578
@@ -616,19 +617,6 @@
616 return;617 return;
617}618}
618619
619/* Call back that happens when the DbusmenuMenuitem
620 is destroyed. We're making sure to clean up everything
621 else down the pipe. */
622static void
623destoryed_dbusmenuitem_cb (gpointer udata, GObject * dbusmenuitem)
624{
625 #ifdef MASSIVEDEBUGGING
626 g_debug("DbusmenuMenuitem was destroyed");
627 #endif
628 gtk_widget_destroy(GTK_WIDGET(udata));
629 return;
630}
631
632/* The new menuitem signal only happens if we don't have a type handler620/* The new menuitem signal only happens if we don't have a type handler
633 for the type of the item. This should be an error condition and we're621 for the type of the item. This should be an error condition and we're
634 printing out a message. */622 printing out a message. */
@@ -731,11 +719,8 @@
731 #endif719 #endif
732720
733 /* Attach these two */721 /* Attach these two */
734 g_object_set_data(G_OBJECT(item), data_menuitem, gmi);722 g_object_ref_sink(G_OBJECT(gmi));
735 g_object_ref(G_OBJECT(gmi));723 g_object_set_data_full(G_OBJECT(item), data_menuitem, gmi, (GDestroyNotify)gtk_widget_destroy);
736 #ifdef MASSIVEDEBUGGING
737 g_signal_connect(G_OBJECT(gmi), "destroy", G_CALLBACK(destroy_gmi), item);
738 #endif
739724
740 /* DbusmenuMenuitem signals */725 /* DbusmenuMenuitem signals */
741 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client);726 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client);
@@ -746,9 +731,6 @@
746 /* GtkMenuitem signals */731 /* GtkMenuitem signals */
747 g_signal_connect(G_OBJECT(gmi), "activate", G_CALLBACK(menu_pressed_cb), item);732 g_signal_connect(G_OBJECT(gmi), "activate", G_CALLBACK(menu_pressed_cb), item);
748733
749 /* Life insurance */
750 g_object_weak_ref(G_OBJECT(item), destoryed_dbusmenuitem_cb, gmi);
751
752 /* Check our set of props to see if any are set already */734 /* Check our set of props to see if any are set already */
753 process_visible(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_VISIBLE));735 process_visible(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_VISIBLE));
754 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED));736 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED));
@@ -801,7 +783,7 @@
801783
802 if (menu != NULL) {784 if (menu != NULL) {
803 gtk_widget_destroy(GTK_WIDGET(menu));785 gtk_widget_destroy(GTK_WIDGET(menu));
804 g_object_set_data(G_OBJECT(mi), data_menu, NULL);786 g_object_steal_data(G_OBJECT(mi), data_menu);
805 }787 }
806 }788 }
807789
@@ -905,11 +887,10 @@
905887
906 GtkMenuItem * gmi;888 GtkMenuItem * gmi;
907 gmi = GTK_MENU_ITEM(g_object_new(GENERICMENUITEM_TYPE, NULL));889 gmi = GTK_MENU_ITEM(g_object_new(GENERICMENUITEM_TYPE, NULL));
908 gtk_menu_item_set_label(gmi, dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL));
909890
910 if (gmi != NULL) {891 if (gmi != NULL) {
892 gtk_menu_item_set_label(gmi, dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL));
911 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);893 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
912 g_object_unref(gmi);
913 } else {894 } else {
914 return FALSE;895 return FALSE;
915 }896 }
916897
=== modified file 'libdbusmenu-gtk/menu.c'
--- libdbusmenu-gtk/menu.c 2011-02-21 20:13:29 +0000
+++ libdbusmenu-gtk/menu.c 2011-04-11 04:46:25 +0000
@@ -329,6 +329,18 @@
329 return;329 return;
330}330}
331331
332/* Handler for all of the menu items on a root change to ensure that
333 the menus are hidden before we start going and deleting things. */
334static void
335popdown_all (DbusmenuMenuitem * mi, gpointer user_data)
336{
337 GtkMenu * menu = dbusmenu_gtkclient_menuitem_get_submenu(DBUSMENU_GTKCLIENT(user_data), mi);
338 if (menu != NULL) {
339 gtk_menu_popdown(menu);
340 }
341 return;
342}
343
332/* When the root menuitem changes we need to resetup things so that344/* When the root menuitem changes we need to resetup things so that
333 we're back in the game. */345 we're back in the game. */
334static void346static void
@@ -344,6 +356,8 @@
344 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_moved, menu);356 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_moved, menu);
345 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_delete, menu);357 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_delete, menu);
346358
359 dbusmenu_menuitem_foreach(priv->root, popdown_all, client);
360
347 g_object_unref(priv->root);361 g_object_unref(priv->root);
348 priv->root = NULL;362 priv->root = NULL;
349 }363 }

Subscribers

People subscribed via source and target branches