Merge lp:~charlesk/libdbusmenu/lp-959821 into lp:libdbusmenu/0.6

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 410
Merged at revision: 407
Proposed branch: lp:~charlesk/libdbusmenu/lp-959821
Merge into: lp:libdbusmenu/0.6
Diff against target: 466 lines (+165/-114)
1 file modified
libdbusmenu-gtk/parser.c (+165/-114)
To merge this branch: bzr merge lp:~charlesk/libdbusmenu/lp-959821
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
Review via email: mp+101255@code.launchpad.net

Description of the change

This patch includes code cleanup too, so here's a guide to what's going on, ordered by line number:

 * g_intern_static_string() was being used as a drop-in replacement for strcmp(). This has been changed to only call g_intern_static_string() once per key and cache the result in a static const char * field.

 * parser_data_free() has new warnings to notify if we're fail to disconnect from the right number of signals. This was added because odd callbacks seem to be a recurring theme for this code in LP.

 * dbusmenu_item_freed() called g_object_get_data() on a disposed object. We can make this safer by moving that function's purpose into parser_data_free() which, like dbusmenu_item_freed(), is called only when the dbusmenuitem is being closed.

 * update_icon() had an unnecessary conditional that could have caused the wrong GtkImage for being monitored for changes. I suspect that this is the cause behind bug #959821, although I'm not able to reproduce the bug in testing.

 * Fix a memory leak in widget_notify_cb() where prop_value wasn't cleaned up if the "label" property changed.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

A lot of cleanups!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libdbusmenu-gtk/parser.c'
--- libdbusmenu-gtk/parser.c 2012-03-21 12:20:21 +0000
+++ libdbusmenu-gtk/parser.c 2012-04-09 16:33:19 +0000
@@ -61,7 +61,6 @@
61 DbusmenuMenuitem * mi);61 DbusmenuMenuitem * mi);
62static void update_icon (DbusmenuMenuitem * menuitem,62static void update_icon (DbusmenuMenuitem * menuitem,
63 ParserData * pdata,63 ParserData * pdata,
64 GtkImageMenuItem * gmenuitem,
65 GtkImage * image);64 GtkImage * image);
66static GtkWidget * find_menu_label (GtkWidget * widget);65static GtkWidget * find_menu_label (GtkWidget * widget);
67static void label_notify_cb (GtkWidget * widget,66static void label_notify_cb (GtkWidget * widget,
@@ -106,6 +105,61 @@
106 GParamSpec * pspec,105 GParamSpec * pspec,
107 gpointer data);106 gpointer data);
108107
108/***
109****
110***/
111
112static const char * interned_str_accessible_name = NULL;
113static const char * interned_str_active = NULL;
114static const char * interned_str_always_show_image = NULL;
115static const char * interned_str_file = NULL;
116static const char * interned_str_gicon = NULL;
117static const char * interned_str_icon_name = NULL;
118static const char * interned_str_icon_set = NULL;
119static const char * interned_str_image = NULL;
120static const char * interned_str_label = NULL;
121static const char * interned_str_mask = NULL;
122static const char * interned_str_parent = NULL;
123static const char * interned_str_pixbuf_animation = NULL;
124static const char * interned_str_pixbuf = NULL;
125static const char * interned_str_pixmap = NULL;
126static const char * interned_str_sensitive = NULL;
127static const char * interned_str_stock = NULL;
128static const char * interned_str_storage_type = NULL;
129static const char * interned_str_submenu = NULL;
130static const char * interned_str_visible = NULL;
131
132static void
133ensure_interned_strings_loaded (void)
134{
135 if (G_UNLIKELY(interned_str_file == NULL))
136 {
137 interned_str_accessible_name = g_intern_static_string ("accessible-name");
138 interned_str_active = g_intern_static_string ("active");
139 interned_str_always_show_image = g_intern_static_string ("always-show-image");
140 interned_str_file = g_intern_static_string ("file");
141 interned_str_gicon = g_intern_static_string ("gicon");
142 interned_str_icon_name = g_intern_static_string ("icon-name");
143 interned_str_icon_set = g_intern_static_string ("icon-set");
144 interned_str_image = g_intern_static_string ("image");
145 interned_str_label = g_intern_static_string ("label");
146 interned_str_mask = g_intern_static_string ("mask");
147 interned_str_parent = g_intern_static_string ("parent");
148 interned_str_pixbuf_animation = g_intern_static_string ("pixbuf-animation");
149 interned_str_pixbuf = g_intern_static_string ("pixbuf");
150 interned_str_pixmap = g_intern_static_string ("pixmap");
151 interned_str_sensitive = g_intern_static_string ("sensitive");
152 interned_str_stock = g_intern_static_string ("stock");
153 interned_str_storage_type = g_intern_static_string ("storage-type");
154 interned_str_submenu = g_intern_static_string ("submenu");
155 interned_str_visible = g_intern_static_string ("visible");
156 }
157}
158
159/***
160****
161***/
162
109/**163/**
110 * dbusmenu_gtk_parse_menu_structure:164 * dbusmenu_gtk_parse_menu_structure:
111 * @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem165 * @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem
@@ -163,73 +217,76 @@
163}217}
164218
165static void219static void
166parse_data_free (gpointer data)220parser_data_free (ParserData * pdata)
167{221{
168 ParserData *pdata = (ParserData *)data;222 g_return_if_fail (pdata != NULL);
169223
170 if (pdata != NULL && pdata->label != NULL) {224 if (pdata->label != NULL) {
171 g_signal_handlers_disconnect_matched(pdata->label, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,225 gint i = 0;
172 0, 0, NULL, G_CALLBACK(label_notify_cb), NULL);226 i += g_signal_handlers_disconnect_matched(pdata->label, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
227 0, 0, NULL, G_CALLBACK(label_notify_cb), NULL);
228 g_warn_if_fail (i != 1);
173 g_object_remove_weak_pointer(G_OBJECT(pdata->label), (gpointer*)&pdata->label);229 g_object_remove_weak_pointer(G_OBJECT(pdata->label), (gpointer*)&pdata->label);
174 }230 }
175231
176 if (pdata != NULL && pdata->action != NULL) {232 if (pdata->action != NULL) {
177 g_signal_handlers_disconnect_matched(pdata->action, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,233 gint i = 0;
178 0, 0, NULL, G_CALLBACK(action_notify_cb), NULL);234 i += g_signal_handlers_disconnect_matched(pdata->action, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
235 0, 0, NULL, G_CALLBACK(action_notify_cb), NULL);
236 g_warn_if_fail (i != 1);
179 g_object_remove_weak_pointer(G_OBJECT(pdata->action), (gpointer*)&pdata->action);237 g_object_remove_weak_pointer(G_OBJECT(pdata->action), (gpointer*)&pdata->action);
180 }238 }
181239
182 if (pdata != NULL && pdata->widget != NULL) {240 if (pdata->widget != NULL) {
183 g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,241 GObject * o = G_OBJECT(pdata->widget);
184 0, 0, NULL, G_CALLBACK(widget_notify_cb), NULL);242 gint i = 0;
185 g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,243 i += g_signal_handlers_disconnect_matched(o, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
186 0, 0, NULL, G_CALLBACK(widget_add_cb), NULL);244 0, 0, NULL, G_CALLBACK(widget_notify_cb), NULL);
187 g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,245 i += g_signal_handlers_disconnect_matched(o, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
188 0, 0, NULL, G_CALLBACK(accel_changed), NULL);246 0, 0, NULL, G_CALLBACK(widget_add_cb), NULL);
189 g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,247 i += g_signal_handlers_disconnect_matched(o, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
190 0, 0, NULL, G_CALLBACK(checkbox_toggled), NULL);248 0, 0, NULL, G_CALLBACK(accel_changed), NULL);
191 g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,249 i += g_signal_handlers_disconnect_matched(o, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
192 0, 0, NULL, G_CALLBACK(menuitem_notify_cb), NULL);250 0, 0, NULL, G_CALLBACK(checkbox_toggled), NULL);
193 g_object_remove_weak_pointer(G_OBJECT(pdata->widget), (gpointer*)&pdata->widget);251 i += g_signal_handlers_disconnect_matched(o, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
252 0, 0, NULL, G_CALLBACK(menuitem_notify_cb), NULL);
253 g_warn_if_fail (i != 5);
254 g_object_remove_weak_pointer(o, (gpointer*)&pdata->widget);
255 /* since the DbusmenuMenuitem is being destroyed, uncache it from the GtkWidget */
256 g_object_steal_data(o, CACHED_MENUITEM);
194 }257 }
195258
196 if (pdata != NULL && pdata->shell != NULL) {259 if (pdata->shell != NULL) {
197 g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,260 gint i = 0;
198 0, 0, NULL, G_CALLBACK(item_inserted_cb), NULL);261 i += g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
199 g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,262 0, 0, NULL, G_CALLBACK(item_inserted_cb), NULL);
200 0, 0, NULL, G_CALLBACK(item_removed_cb), NULL);263 i += g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
264 0, 0, NULL, G_CALLBACK(item_removed_cb), NULL);
265 g_warn_if_fail (i != 2);
201 g_object_remove_weak_pointer(G_OBJECT(pdata->shell), (gpointer*)&pdata->shell);266 g_object_remove_weak_pointer(G_OBJECT(pdata->shell), (gpointer*)&pdata->shell);
202 }267 }
203268
204 if (pdata != NULL && pdata->image != NULL) {269 if (pdata->image != NULL) {
205 g_signal_handlers_disconnect_matched(pdata->image, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,270 gint i = 0;
206 0, 0, NULL, G_CALLBACK(image_notify_cb), NULL);271 i += g_signal_handlers_disconnect_matched(pdata->image, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
272 0, 0, NULL, G_CALLBACK(image_notify_cb), NULL);
273 g_warn_if_fail (i != 1);
207 g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image);274 g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image);
208 }275 }
209276
210 if (pdata != NULL && pdata->accessible != NULL) {277 if (pdata->accessible != NULL) {
211 g_signal_handlers_disconnect_matched(pdata->accessible, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,278 gint i = 0;
212 0, 0, NULL, G_CALLBACK(a11y_name_notify_cb), NULL);279 i += g_signal_handlers_disconnect_matched(pdata->accessible, (GSignalMatchType)G_SIGNAL_MATCH_FUNC,
213 g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible);280 0, 0, NULL, G_CALLBACK(a11y_name_notify_cb), NULL);
214 }281 g_warn_if_fail (i != 1);
282 g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible);
283 }
215284
216 g_free(pdata);285 g_free(pdata);
217286
218 return;287 return;
219}288}
220289
221/* Called when the dbusmenu item that we're keeping around
222 is finalized */
223static void
224dbusmenu_item_freed (gpointer data, GObject * obj)
225{
226 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA);
227
228 if (pdata != NULL && pdata->widget != NULL) {
229 g_object_steal_data(G_OBJECT(pdata->widget), CACHED_MENUITEM);
230 }
231}
232
233/* Gets the positon of the child with its' parent if it has one.290/* Gets the positon of the child with its' parent if it has one.
234 Returns -1 if the position is unable to be calculated. */291 Returns -1 if the position is unable to be calculated. */
235static gint292static gint
@@ -265,9 +322,7 @@
265 DbusmenuMenuitem * item = dbusmenu_menuitem_new();322 DbusmenuMenuitem * item = dbusmenu_menuitem_new();
266323
267 ParserData *pdata = g_new0 (ParserData, 1);324 ParserData *pdata = g_new0 (ParserData, 1);
268 g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, parse_data_free);325 g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, (GDestroyNotify)parser_data_free);
269
270 g_object_weak_ref(G_OBJECT(item), dbusmenu_item_freed, NULL);
271326
272 pdata->widget = widget;327 pdata->widget = widget;
273 g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget);328 g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget);
@@ -558,7 +613,7 @@
558613
559 if (GTK_IS_IMAGE (image))614 if (GTK_IS_IMAGE (image))
560 {615 {
561 update_icon (mi, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image));616 update_icon (mi, pdata, GTK_IMAGE (image));
562 }617 }
563 }618 }
564619
@@ -682,7 +737,9 @@
682 GParamSpec *pspec,737 GParamSpec *pspec,
683 gpointer data)738 gpointer data)
684{739{
685 if (pspec->name == g_intern_static_string ("visible"))740 ensure_interned_strings_loaded ();
741
742 if (pspec->name == interned_str_visible)
686 {743 {
687 GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget);744 GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget);
688 GtkWidget * old_toplevel = GTK_WIDGET(data);745 GtkWidget * old_toplevel = GTK_WIDGET(data);
@@ -715,7 +772,7 @@
715}772}
716773
717static void774static void
718update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImageMenuItem * gmenuitem, GtkImage *image)775update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImage *image)
719{776{
720 GdkPixbuf * pixbuf = NULL;777 GdkPixbuf * pixbuf = NULL;
721 const gchar * icon_name = NULL;778 const gchar * icon_name = NULL;
@@ -724,12 +781,8 @@
724 GtkIconInfo * info;781 GtkIconInfo * info;
725 gint width;782 gint width;
726783
727 /* Check to see if we're changing the image. If so, we need to track784 /* Check to see if we're changing the image. If so, we need to track that little bugger */
728 that little bugger */785 if (image != GTK_IMAGE(pdata->image)) {
729 /* Why check for gmenuitem being NULL? Because there are some cases where
730 we can't get it easily, and those mean it's not changed just the icon
731 underneith, so we can ignore these larger impacts */
732 if (image != GTK_IMAGE(pdata->image) && gmenuitem != NULL) {
733786
734 if (pdata->image != NULL) {787 if (pdata->image != NULL) {
735 g_signal_handlers_disconnect_by_func(pdata->image, G_CALLBACK(image_notify_cb), menuitem);788 g_signal_handlers_disconnect_by_func(pdata->image, G_CALLBACK(image_notify_cb), menuitem);
@@ -894,10 +947,12 @@
894 DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;947 DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
895 GValue prop_value = {0};948 GValue prop_value = {0};
896949
950 ensure_interned_strings_loaded ();
951
897 g_value_init (&prop_value, pspec->value_type); 952 g_value_init (&prop_value, pspec->value_type);
898 g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value);953 g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value);
899954
900 if (pspec->name == g_intern_static_string ("label"))955 if (pspec->name == interned_str_label)
901 {956 {
902 gchar * text = sanitize_label (GTK_LABEL (widget));957 gchar * text = sanitize_label (GTK_LABEL (widget));
903 dbusmenu_menuitem_property_set (child,958 dbusmenu_menuitem_property_set (child,
@@ -905,7 +960,7 @@
905 text);960 text);
906 g_free (text);961 g_free (text);
907 }962 }
908 else if (pspec->name == g_intern_static_string ("parent"))963 else if (pspec->name == interned_str_parent)
909 {964 {
910 if (GTK_WIDGET (g_value_get_object (&prop_value)) == NULL)965 if (GTK_WIDGET (g_value_get_object (&prop_value)) == NULL)
911 {966 {
@@ -929,55 +984,53 @@
929}984}
930985
931static void986static void
932image_notify_cb (GtkWidget *widget,987image_notify_cb (GtkWidget * image, GParamSpec * pspec, gpointer data)
933 GParamSpec *pspec,
934 gpointer data)
935{988{
936 DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data;989 ensure_interned_strings_loaded();
937990
938 if (pspec->name == g_intern_static_string ("file") ||991 if (pspec->name == interned_str_file ||
939 pspec->name == g_intern_static_string ("gicon") ||992 pspec->name == interned_str_gicon ||
940 pspec->name == g_intern_static_string ("icon-name") ||993 pspec->name == interned_str_icon_name ||
941 pspec->name == g_intern_static_string ("icon-set") ||994 pspec->name == interned_str_icon_set ||
942 pspec->name == g_intern_static_string ("image") ||995 pspec->name == interned_str_image ||
943 pspec->name == g_intern_static_string ("mask") ||996 pspec->name == interned_str_mask ||
944 pspec->name == g_intern_static_string ("pixbuf") ||997 pspec->name == interned_str_pixbuf ||
945 pspec->name == g_intern_static_string ("pixbuf-animation") ||998 pspec->name == interned_str_pixbuf_animation ||
946 pspec->name == g_intern_static_string ("pixmap") ||999 pspec->name == interned_str_pixmap ||
947 pspec->name == g_intern_static_string ("stock") ||1000 pspec->name == interned_str_stock ||
948 pspec->name == g_intern_static_string ("storage-type"))1001 pspec->name == interned_str_storage_type)
949 {1002 {
1003 DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data);
950 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA);1004 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA);
951 update_icon (mi, pdata, NULL, GTK_IMAGE (widget));1005 update_icon (mi, pdata, GTK_IMAGE (image));
952 }1006 }
953}1007}
9541008
955static void1009static void
956action_notify_cb (GtkAction *action,1010action_notify_cb (GtkAction *action, GParamSpec * pspec, gpointer data)
957 GParamSpec *pspec,
958 gpointer data)
959{1011{
960 DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data;1012 DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data);
1013 ensure_interned_strings_loaded ();
9611014
962 if (pspec->name == g_intern_static_string ("sensitive"))1015 if (pspec->name == interned_str_sensitive)
963 {1016 {
964 dbusmenu_menuitem_property_set_bool (mi,1017 dbusmenu_menuitem_property_set_bool (mi,
965 DBUSMENU_MENUITEM_PROP_ENABLED,1018 DBUSMENU_MENUITEM_PROP_ENABLED,
966 gtk_action_is_sensitive (action));1019 gtk_action_is_sensitive (action));
967 }1020 }
968 else if (pspec->name == g_intern_static_string ("visible"))1021 else if (pspec->name == interned_str_visible)
969 {1022 {
970 dbusmenu_menuitem_property_set_bool (mi,1023 dbusmenu_menuitem_property_set_bool (mi,
971 DBUSMENU_MENUITEM_PROP_VISIBLE,1024 DBUSMENU_MENUITEM_PROP_VISIBLE,
972 gtk_action_is_visible (action));1025 gtk_action_is_visible (action));
973 }1026 }
974 else if (pspec->name == g_intern_static_string ("active"))1027 else if (pspec->name == interned_str_active)
975 {1028 {
976 dbusmenu_menuitem_property_set_int (mi,1029 dbusmenu_menuitem_property_set_int (mi,
977 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,1030 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
978 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);1031 gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
979 }1032 }
980 else if (pspec->name == g_intern_static_string ("label"))1033 else if (pspec->name == interned_str_label)
981 {1034 {
982 gchar * text = sanitize_label_text (gtk_action_get_label (action));1035 gchar * text = sanitize_label_text (gtk_action_get_label (action));
983 dbusmenu_menuitem_property_set (mi,1036 dbusmenu_menuitem_property_set (mi,
@@ -988,23 +1041,23 @@
988}1041}
9891042
990static void1043static void
991a11y_name_notify_cb (AtkObject *accessible,1044a11y_name_notify_cb (AtkObject * accessible, GParamSpec * pspec, gpointer data)
992 GParamSpec *pspec,
993 gpointer data)
994{1045{
995 DbusmenuMenuitem *item = (DbusmenuMenuitem *)data;1046 ensure_interned_strings_loaded ();
996 GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
997 GtkWidget *label = find_menu_label (widget);
998 const gchar *label_text = gtk_label_get_text (GTK_LABEL (label));
999 const gchar *name = atk_object_get_name (accessible);
10001047
1001 /* If an application sets the accessible name to NULL, then a subsequent1048 /* If an application sets the accessible name to NULL, then a subsequent
1002 * call to get the accessible name from the Atk object should return the same1049 * call to get the accessible name from the Atk object should return the same
1003 * string as the text of the menu item label, in which case, we want to clear1050 * string as the text of the menu item label, in which case, we want to clear
1004 * the accessible description property of the dbusmenu item.1051 * the accessible description property of the dbusmenu item.
1005 */1052 */
1006 if (pspec->name == g_intern_static_string ("accessible-name"))1053 if (pspec->name == interned_str_accessible_name)
1007 {1054 {
1055 DbusmenuMenuitem * item = DBUSMENU_MENUITEM(data);
1056 GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
1057 GtkWidget *label = find_menu_label (widget);
1058 const gchar *label_text = gtk_label_get_text (GTK_LABEL (label));
1059 const gchar *name = atk_object_get_name (accessible);
1060
1008 if (!g_strcmp0 (name, label_text))1061 if (!g_strcmp0 (name, label_text))
1009 dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL);1062 dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL);
1010 else1063 else
@@ -1099,54 +1152,52 @@
1099}1152}
11001153
1101static void1154static void
1102widget_notify_cb (GtkWidget *widget,1155widget_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data)
1103 GParamSpec *pspec,
1104 gpointer data)
1105{1156{
1106 DbusmenuMenuitem *child = (DbusmenuMenuitem *)data;
1107 GValue prop_value = {0};1157 GValue prop_value = {0};
1158 DbusmenuMenuitem * child = DBUSMENU_MENUITEM(data);
1159 g_return_if_fail (child != NULL);
1160
1161 ensure_interned_strings_loaded ();
11081162
1109 g_value_init (&prop_value, pspec->value_type); 1163 g_value_init (&prop_value, pspec->value_type);
1110 g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value);1164 g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value);
11111165
1112 if (pspec->name == g_intern_static_string ("sensitive"))1166 if (pspec->name == interned_str_sensitive)
1113 {1167 {
1114 dbusmenu_menuitem_property_set_bool (child,1168 dbusmenu_menuitem_property_set_bool (child,
1115 DBUSMENU_MENUITEM_PROP_ENABLED,1169 DBUSMENU_MENUITEM_PROP_ENABLED,
1116 g_value_get_boolean (&prop_value));1170 g_value_get_boolean (&prop_value));
1117 }1171 }
1118 else if (pspec->name == g_intern_static_string ("label"))1172 else if (pspec->name == interned_str_label)
1119 {1173 {
1120 if (handle_first_label (child))1174 if (!handle_first_label (child))
1121 {1175 {
1122 return;1176 dbusmenu_menuitem_property_set (child,
1177 DBUSMENU_MENUITEM_PROP_LABEL,
1178 g_value_get_string (&prop_value));
1123 }1179 }
1124
1125 dbusmenu_menuitem_property_set (child,
1126 DBUSMENU_MENUITEM_PROP_LABEL,
1127 g_value_get_string (&prop_value));
1128 }1180 }
1129 else if (pspec->name == g_intern_static_string ("visible"))1181 else if (pspec->name == interned_str_visible)
1130 {1182 {
1131 dbusmenu_menuitem_property_set_bool (child,1183 dbusmenu_menuitem_property_set_bool (child,
1132 DBUSMENU_MENUITEM_PROP_VISIBLE,1184 DBUSMENU_MENUITEM_PROP_VISIBLE,
1133 g_value_get_boolean (&prop_value));1185 g_value_get_boolean (&prop_value));
1134 }1186 }
1135 else if (pspec->name == g_intern_static_string ("always-show-image"))1187 else if (pspec->name == interned_str_always_show_image)
1136 {1188 {
1137 GtkWidget *image = NULL;1189 GtkWidget *image = NULL;
1138 g_object_get(widget, "image", &image, NULL);1190 g_object_get(widget, "image", &image, NULL);
1139 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);1191 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);
1140 update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE(image));1192 update_icon (child, pdata, GTK_IMAGE(image));
1141 }1193 }
1142 else if (pspec->name == g_intern_static_string ("image"))1194 else if (pspec->name == interned_str_image)
1143 {1195 {
1144 GtkWidget *image;1196 GtkWidget * image = GTK_WIDGET (g_value_get_object (&prop_value));
1145 image = GTK_WIDGET (g_value_get_object (&prop_value));
1146 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);1197 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);
1147 update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image));1198 update_icon (child, pdata, GTK_IMAGE (image));
1148 }1199 }
1149 else if (pspec->name == g_intern_static_string ("parent"))1200 else if (pspec->name == interned_str_parent)
1150 {1201 {
1151 /*1202 /*
1152 * We probably should have added a 'remove' method to the1203 * We probably should have added a 'remove' method to the
@@ -1166,7 +1217,7 @@
1166 }1217 }
1167 }1218 }
1168 }1219 }
1169 else if (pspec->name == g_intern_static_string ("submenu"))1220 else if (pspec->name == interned_str_submenu)
1170 {1221 {
1171 /* The underlying submenu got swapped out. Let's see what it is now. */1222 /* The underlying submenu got swapped out. Let's see what it is now. */
1172 /* First, delete any children that may exist currently. */1223 /* First, delete any children that may exist currently. */

Subscribers

People subscribed via source and target branches

to all changes: