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
1=== modified file 'libdbusmenu-glib/client-menuitem.c'
2--- libdbusmenu-glib/client-menuitem.c 2011-02-21 18:55:10 +0000
3+++ libdbusmenu-glib/client-menuitem.c 2011-04-11 04:46:25 +0000
4@@ -106,7 +106,7 @@
5 handle_event (DbusmenuMenuitem * mi, const gchar * name, GVariant * variant, guint timestamp)
6 {
7 DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi);
8- dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp);
9+ dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, variant, timestamp, mi);
10 return;
11 }
12
13
14=== modified file 'libdbusmenu-glib/client-private.h'
15--- libdbusmenu-glib/client-private.h 2011-02-21 18:55:10 +0000
16+++ libdbusmenu-glib/client-private.h 2011-04-11 04:46:25 +0000
17@@ -37,7 +37,8 @@
18 gint id,
19 const gchar * name,
20 GVariant * variant,
21- guint timestamp);
22+ guint timestamp,
23+ DbusmenuMenuitem * mi);
24 void dbusmenu_client_send_about_to_show(DbusmenuClient * client,
25 gint id,
26 void (*cb) (gpointer user_data),
27
28=== modified file 'libdbusmenu-glib/client.c'
29--- libdbusmenu-glib/client.c 2011-04-07 15:04:04 +0000
30+++ libdbusmenu-glib/client.c 2011-04-11 04:46:25 +0000
31@@ -1516,14 +1516,13 @@
32 /* Sends the event over DBus to the server on the other side
33 of the bus. */
34 void
35-dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp)
36+dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, GVariant * variant, guint timestamp, DbusmenuMenuitem * mi)
37 {
38 g_return_if_fail(DBUSMENU_IS_CLIENT(client));
39 g_return_if_fail(id >= 0);
40 g_return_if_fail(name != NULL);
41
42 DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
43- DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id);
44 if (mi == NULL) {
45 g_warning("Asked to activate a menuitem %d that we don't know about", id);
46 return;
47
48=== modified file 'libdbusmenu-gtk/client.c'
49--- libdbusmenu-gtk/client.c 2011-04-05 18:38:28 +0000
50+++ libdbusmenu-gtk/client.c 2011-04-11 04:46:25 +0000
51@@ -571,7 +571,8 @@
52 } else {
53 /* We need to build a menu for these guys to live in. */
54 GtkMenu * menu = GTK_MENU(gtk_menu_new());
55- g_object_set_data(G_OBJECT(mi), data_menu, menu);
56+ g_object_ref_sink(menu);
57+ g_object_set_data_full(G_OBJECT(mi), data_menu, menu, g_object_unref);
58
59 gtk_menu_item_set_submenu(gmi, GTK_WIDGET(menu));
60
61@@ -616,19 +617,6 @@
62 return;
63 }
64
65-/* Call back that happens when the DbusmenuMenuitem
66- is destroyed. We're making sure to clean up everything
67- else down the pipe. */
68-static void
69-destoryed_dbusmenuitem_cb (gpointer udata, GObject * dbusmenuitem)
70-{
71- #ifdef MASSIVEDEBUGGING
72- g_debug("DbusmenuMenuitem was destroyed");
73- #endif
74- gtk_widget_destroy(GTK_WIDGET(udata));
75- return;
76-}
77-
78 /* The new menuitem signal only happens if we don't have a type handler
79 for the type of the item. This should be an error condition and we're
80 printing out a message. */
81@@ -731,11 +719,8 @@
82 #endif
83
84 /* Attach these two */
85- g_object_set_data(G_OBJECT(item), data_menuitem, gmi);
86- g_object_ref(G_OBJECT(gmi));
87- #ifdef MASSIVEDEBUGGING
88- g_signal_connect(G_OBJECT(gmi), "destroy", G_CALLBACK(destroy_gmi), item);
89- #endif
90+ g_object_ref_sink(G_OBJECT(gmi));
91+ g_object_set_data_full(G_OBJECT(item), data_menuitem, gmi, (GDestroyNotify)gtk_widget_destroy);
92
93 /* DbusmenuMenuitem signals */
94 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client);
95@@ -746,9 +731,6 @@
96 /* GtkMenuitem signals */
97 g_signal_connect(G_OBJECT(gmi), "activate", G_CALLBACK(menu_pressed_cb), item);
98
99- /* Life insurance */
100- g_object_weak_ref(G_OBJECT(item), destoryed_dbusmenuitem_cb, gmi);
101-
102 /* Check our set of props to see if any are set already */
103 process_visible(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_VISIBLE));
104 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED));
105@@ -801,7 +783,7 @@
106
107 if (menu != NULL) {
108 gtk_widget_destroy(GTK_WIDGET(menu));
109- g_object_set_data(G_OBJECT(mi), data_menu, NULL);
110+ g_object_steal_data(G_OBJECT(mi), data_menu);
111 }
112 }
113
114@@ -905,11 +887,10 @@
115
116 GtkMenuItem * gmi;
117 gmi = GTK_MENU_ITEM(g_object_new(GENERICMENUITEM_TYPE, NULL));
118- gtk_menu_item_set_label(gmi, dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL));
119
120 if (gmi != NULL) {
121+ gtk_menu_item_set_label(gmi, dbusmenu_menuitem_property_get(newitem, DBUSMENU_MENUITEM_PROP_LABEL));
122 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
123- g_object_unref(gmi);
124 } else {
125 return FALSE;
126 }
127
128=== modified file 'libdbusmenu-gtk/menu.c'
129--- libdbusmenu-gtk/menu.c 2011-02-21 20:13:29 +0000
130+++ libdbusmenu-gtk/menu.c 2011-04-11 04:46:25 +0000
131@@ -329,6 +329,18 @@
132 return;
133 }
134
135+/* Handler for all of the menu items on a root change to ensure that
136+ the menus are hidden before we start going and deleting things. */
137+static void
138+popdown_all (DbusmenuMenuitem * mi, gpointer user_data)
139+{
140+ GtkMenu * menu = dbusmenu_gtkclient_menuitem_get_submenu(DBUSMENU_GTKCLIENT(user_data), mi);
141+ if (menu != NULL) {
142+ gtk_menu_popdown(menu);
143+ }
144+ return;
145+}
146+
147 /* When the root menuitem changes we need to resetup things so that
148 we're back in the game. */
149 static void
150@@ -344,6 +356,8 @@
151 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_moved, menu);
152 g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_delete, menu);
153
154+ dbusmenu_menuitem_foreach(priv->root, popdown_all, client);
155+
156 g_object_unref(priv->root);
157 priv->root = NULL;
158 }

Subscribers

People subscribed via source and target branches