Merge lp:~charlesk/libdbusmenu/lp-959821 into lp:libdbusmenu/0.6
- lp-959821
- Merge into trunk.0.6
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ted Gould (community) | Approve | ||
Review via email: mp+101255@code.launchpad.net |
Commit message
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_
* 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_
* 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.
Preview Diff
1 | === modified file 'libdbusmenu-gtk/parser.c' | |||
2 | --- libdbusmenu-gtk/parser.c 2012-03-21 12:20:21 +0000 | |||
3 | +++ libdbusmenu-gtk/parser.c 2012-04-09 16:33:19 +0000 | |||
4 | @@ -61,7 +61,6 @@ | |||
5 | 61 | DbusmenuMenuitem * mi); | 61 | DbusmenuMenuitem * mi); |
6 | 62 | static void update_icon (DbusmenuMenuitem * menuitem, | 62 | static void update_icon (DbusmenuMenuitem * menuitem, |
7 | 63 | ParserData * pdata, | 63 | ParserData * pdata, |
8 | 64 | GtkImageMenuItem * gmenuitem, | ||
9 | 65 | GtkImage * image); | 64 | GtkImage * image); |
10 | 66 | static GtkWidget * find_menu_label (GtkWidget * widget); | 65 | static GtkWidget * find_menu_label (GtkWidget * widget); |
11 | 67 | static void label_notify_cb (GtkWidget * widget, | 66 | static void label_notify_cb (GtkWidget * widget, |
12 | @@ -106,6 +105,61 @@ | |||
13 | 106 | GParamSpec * pspec, | 105 | GParamSpec * pspec, |
14 | 107 | gpointer data); | 106 | gpointer data); |
15 | 108 | 107 | ||
16 | 108 | /*** | ||
17 | 109 | **** | ||
18 | 110 | ***/ | ||
19 | 111 | |||
20 | 112 | static const char * interned_str_accessible_name = NULL; | ||
21 | 113 | static const char * interned_str_active = NULL; | ||
22 | 114 | static const char * interned_str_always_show_image = NULL; | ||
23 | 115 | static const char * interned_str_file = NULL; | ||
24 | 116 | static const char * interned_str_gicon = NULL; | ||
25 | 117 | static const char * interned_str_icon_name = NULL; | ||
26 | 118 | static const char * interned_str_icon_set = NULL; | ||
27 | 119 | static const char * interned_str_image = NULL; | ||
28 | 120 | static const char * interned_str_label = NULL; | ||
29 | 121 | static const char * interned_str_mask = NULL; | ||
30 | 122 | static const char * interned_str_parent = NULL; | ||
31 | 123 | static const char * interned_str_pixbuf_animation = NULL; | ||
32 | 124 | static const char * interned_str_pixbuf = NULL; | ||
33 | 125 | static const char * interned_str_pixmap = NULL; | ||
34 | 126 | static const char * interned_str_sensitive = NULL; | ||
35 | 127 | static const char * interned_str_stock = NULL; | ||
36 | 128 | static const char * interned_str_storage_type = NULL; | ||
37 | 129 | static const char * interned_str_submenu = NULL; | ||
38 | 130 | static const char * interned_str_visible = NULL; | ||
39 | 131 | |||
40 | 132 | static void | ||
41 | 133 | ensure_interned_strings_loaded (void) | ||
42 | 134 | { | ||
43 | 135 | if (G_UNLIKELY(interned_str_file == NULL)) | ||
44 | 136 | { | ||
45 | 137 | interned_str_accessible_name = g_intern_static_string ("accessible-name"); | ||
46 | 138 | interned_str_active = g_intern_static_string ("active"); | ||
47 | 139 | interned_str_always_show_image = g_intern_static_string ("always-show-image"); | ||
48 | 140 | interned_str_file = g_intern_static_string ("file"); | ||
49 | 141 | interned_str_gicon = g_intern_static_string ("gicon"); | ||
50 | 142 | interned_str_icon_name = g_intern_static_string ("icon-name"); | ||
51 | 143 | interned_str_icon_set = g_intern_static_string ("icon-set"); | ||
52 | 144 | interned_str_image = g_intern_static_string ("image"); | ||
53 | 145 | interned_str_label = g_intern_static_string ("label"); | ||
54 | 146 | interned_str_mask = g_intern_static_string ("mask"); | ||
55 | 147 | interned_str_parent = g_intern_static_string ("parent"); | ||
56 | 148 | interned_str_pixbuf_animation = g_intern_static_string ("pixbuf-animation"); | ||
57 | 149 | interned_str_pixbuf = g_intern_static_string ("pixbuf"); | ||
58 | 150 | interned_str_pixmap = g_intern_static_string ("pixmap"); | ||
59 | 151 | interned_str_sensitive = g_intern_static_string ("sensitive"); | ||
60 | 152 | interned_str_stock = g_intern_static_string ("stock"); | ||
61 | 153 | interned_str_storage_type = g_intern_static_string ("storage-type"); | ||
62 | 154 | interned_str_submenu = g_intern_static_string ("submenu"); | ||
63 | 155 | interned_str_visible = g_intern_static_string ("visible"); | ||
64 | 156 | } | ||
65 | 157 | } | ||
66 | 158 | |||
67 | 159 | /*** | ||
68 | 160 | **** | ||
69 | 161 | ***/ | ||
70 | 162 | |||
71 | 109 | /** | 163 | /** |
72 | 110 | * dbusmenu_gtk_parse_menu_structure: | 164 | * dbusmenu_gtk_parse_menu_structure: |
73 | 111 | * @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem | 165 | * @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem |
74 | @@ -163,73 +217,76 @@ | |||
75 | 163 | } | 217 | } |
76 | 164 | 218 | ||
77 | 165 | static void | 219 | static void |
79 | 166 | parse_data_free (gpointer data) | 220 | parser_data_free (ParserData * pdata) |
80 | 167 | { | 221 | { |
82 | 168 | ParserData *pdata = (ParserData *)data; | 222 | g_return_if_fail (pdata != NULL); |
83 | 169 | 223 | ||
87 | 170 | if (pdata != NULL && pdata->label != NULL) { | 224 | if (pdata->label != NULL) { |
88 | 171 | g_signal_handlers_disconnect_matched(pdata->label, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 225 | gint i = 0; |
89 | 172 | 0, 0, NULL, G_CALLBACK(label_notify_cb), NULL); | 226 | i += g_signal_handlers_disconnect_matched(pdata->label, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, |
90 | 227 | 0, 0, NULL, G_CALLBACK(label_notify_cb), NULL); | ||
91 | 228 | g_warn_if_fail (i != 1); | ||
92 | 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); |
93 | 174 | } | 230 | } |
94 | 175 | 231 | ||
98 | 176 | if (pdata != NULL && pdata->action != NULL) { | 232 | if (pdata->action != NULL) { |
99 | 177 | g_signal_handlers_disconnect_matched(pdata->action, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 233 | gint i = 0; |
100 | 178 | 0, 0, NULL, G_CALLBACK(action_notify_cb), NULL); | 234 | i += g_signal_handlers_disconnect_matched(pdata->action, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, |
101 | 235 | 0, 0, NULL, G_CALLBACK(action_notify_cb), NULL); | ||
102 | 236 | g_warn_if_fail (i != 1); | ||
103 | 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); |
104 | 180 | } | 238 | } |
105 | 181 | 239 | ||
118 | 182 | if (pdata != NULL && pdata->widget != NULL) { | 240 | if (pdata->widget != NULL) { |
119 | 183 | g_signal_handlers_disconnect_matched(pdata->widget, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 241 | GObject * o = G_OBJECT(pdata->widget); |
120 | 184 | 0, 0, NULL, G_CALLBACK(widget_notify_cb), NULL); | 242 | gint i = 0; |
121 | 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, |
122 | 186 | 0, 0, NULL, G_CALLBACK(widget_add_cb), NULL); | 244 | 0, 0, NULL, G_CALLBACK(widget_notify_cb), NULL); |
123 | 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, |
124 | 188 | 0, 0, NULL, G_CALLBACK(accel_changed), NULL); | 246 | 0, 0, NULL, G_CALLBACK(widget_add_cb), NULL); |
125 | 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, |
126 | 190 | 0, 0, NULL, G_CALLBACK(checkbox_toggled), NULL); | 248 | 0, 0, NULL, G_CALLBACK(accel_changed), NULL); |
127 | 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, |
128 | 192 | 0, 0, NULL, G_CALLBACK(menuitem_notify_cb), NULL); | 250 | 0, 0, NULL, G_CALLBACK(checkbox_toggled), NULL); |
129 | 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, |
130 | 252 | 0, 0, NULL, G_CALLBACK(menuitem_notify_cb), NULL); | ||
131 | 253 | g_warn_if_fail (i != 5); | ||
132 | 254 | g_object_remove_weak_pointer(o, (gpointer*)&pdata->widget); | ||
133 | 255 | /* since the DbusmenuMenuitem is being destroyed, uncache it from the GtkWidget */ | ||
134 | 256 | g_object_steal_data(o, CACHED_MENUITEM); | ||
135 | 194 | } | 257 | } |
136 | 195 | 258 | ||
142 | 196 | if (pdata != NULL && pdata->shell != NULL) { | 259 | if (pdata->shell != NULL) { |
143 | 197 | g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 260 | gint i = 0; |
144 | 198 | 0, 0, NULL, G_CALLBACK(item_inserted_cb), NULL); | 261 | i += g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, |
145 | 199 | g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 262 | 0, 0, NULL, G_CALLBACK(item_inserted_cb), NULL); |
146 | 200 | 0, 0, NULL, G_CALLBACK(item_removed_cb), NULL); | 263 | i += g_signal_handlers_disconnect_matched(pdata->shell, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, |
147 | 264 | 0, 0, NULL, G_CALLBACK(item_removed_cb), NULL); | ||
148 | 265 | g_warn_if_fail (i != 2); | ||
149 | 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); |
150 | 202 | } | 267 | } |
151 | 203 | 268 | ||
155 | 204 | if (pdata != NULL && pdata->image != NULL) { | 269 | if (pdata->image != NULL) { |
156 | 205 | g_signal_handlers_disconnect_matched(pdata->image, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 270 | gint i = 0; |
157 | 206 | 0, 0, NULL, G_CALLBACK(image_notify_cb), NULL); | 271 | i += g_signal_handlers_disconnect_matched(pdata->image, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, |
158 | 272 | 0, 0, NULL, G_CALLBACK(image_notify_cb), NULL); | ||
159 | 273 | g_warn_if_fail (i != 1); | ||
160 | 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); |
161 | 208 | } | 275 | } |
162 | 209 | 276 | ||
168 | 210 | if (pdata != NULL && pdata->accessible != NULL) { | 277 | if (pdata->accessible != NULL) { |
169 | 211 | g_signal_handlers_disconnect_matched(pdata->accessible, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, | 278 | gint i = 0; |
170 | 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, |
171 | 213 | g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible); | 280 | 0, 0, NULL, G_CALLBACK(a11y_name_notify_cb), NULL); |
172 | 214 | } | 281 | g_warn_if_fail (i != 1); |
173 | 282 | g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible); | ||
174 | 283 | } | ||
175 | 215 | 284 | ||
176 | 216 | g_free(pdata); | 285 | g_free(pdata); |
177 | 217 | 286 | ||
178 | 218 | return; | 287 | return; |
179 | 219 | } | 288 | } |
180 | 220 | 289 | ||
181 | 221 | /* Called when the dbusmenu item that we're keeping around | ||
182 | 222 | is finalized */ | ||
183 | 223 | static void | ||
184 | 224 | dbusmenu_item_freed (gpointer data, GObject * obj) | ||
185 | 225 | { | ||
186 | 226 | ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA); | ||
187 | 227 | |||
188 | 228 | if (pdata != NULL && pdata->widget != NULL) { | ||
189 | 229 | g_object_steal_data(G_OBJECT(pdata->widget), CACHED_MENUITEM); | ||
190 | 230 | } | ||
191 | 231 | } | ||
192 | 232 | |||
193 | 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. |
194 | 234 | Returns -1 if the position is unable to be calculated. */ | 291 | Returns -1 if the position is unable to be calculated. */ |
195 | 235 | static gint | 292 | static gint |
196 | @@ -265,9 +322,7 @@ | |||
197 | 265 | DbusmenuMenuitem * item = dbusmenu_menuitem_new(); | 322 | DbusmenuMenuitem * item = dbusmenu_menuitem_new(); |
198 | 266 | 323 | ||
199 | 267 | ParserData *pdata = g_new0 (ParserData, 1); | 324 | ParserData *pdata = g_new0 (ParserData, 1); |
203 | 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); |
201 | 269 | |||
202 | 270 | g_object_weak_ref(G_OBJECT(item), dbusmenu_item_freed, NULL); | ||
204 | 271 | 326 | ||
205 | 272 | pdata->widget = widget; | 327 | pdata->widget = widget; |
206 | 273 | g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); | 328 | g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); |
207 | @@ -558,7 +613,7 @@ | |||
208 | 558 | 613 | ||
209 | 559 | if (GTK_IS_IMAGE (image)) | 614 | if (GTK_IS_IMAGE (image)) |
210 | 560 | { | 615 | { |
212 | 561 | update_icon (mi, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image)); | 616 | update_icon (mi, pdata, GTK_IMAGE (image)); |
213 | 562 | } | 617 | } |
214 | 563 | } | 618 | } |
215 | 564 | 619 | ||
216 | @@ -682,7 +737,9 @@ | |||
217 | 682 | GParamSpec *pspec, | 737 | GParamSpec *pspec, |
218 | 683 | gpointer data) | 738 | gpointer data) |
219 | 684 | { | 739 | { |
221 | 685 | if (pspec->name == g_intern_static_string ("visible")) | 740 | ensure_interned_strings_loaded (); |
222 | 741 | |||
223 | 742 | if (pspec->name == interned_str_visible) | ||
224 | 686 | { | 743 | { |
225 | 687 | GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget); | 744 | GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget); |
226 | 688 | GtkWidget * old_toplevel = GTK_WIDGET(data); | 745 | GtkWidget * old_toplevel = GTK_WIDGET(data); |
227 | @@ -715,7 +772,7 @@ | |||
228 | 715 | } | 772 | } |
229 | 716 | 773 | ||
230 | 717 | static void | 774 | static void |
232 | 718 | update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImageMenuItem * gmenuitem, GtkImage *image) | 775 | update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImage *image) |
233 | 719 | { | 776 | { |
234 | 720 | GdkPixbuf * pixbuf = NULL; | 777 | GdkPixbuf * pixbuf = NULL; |
235 | 721 | const gchar * icon_name = NULL; | 778 | const gchar * icon_name = NULL; |
236 | @@ -724,12 +781,8 @@ | |||
237 | 724 | GtkIconInfo * info; | 781 | GtkIconInfo * info; |
238 | 725 | gint width; | 782 | gint width; |
239 | 726 | 783 | ||
246 | 727 | /* Check to see if we're changing the image. If so, we need to track | 784 | /* Check to see if we're changing the image. If so, we need to track that little bugger */ |
247 | 728 | that little bugger */ | 785 | if (image != GTK_IMAGE(pdata->image)) { |
242 | 729 | /* Why check for gmenuitem being NULL? Because there are some cases where | ||
243 | 730 | we can't get it easily, and those mean it's not changed just the icon | ||
244 | 731 | underneith, so we can ignore these larger impacts */ | ||
245 | 732 | if (image != GTK_IMAGE(pdata->image) && gmenuitem != NULL) { | ||
248 | 733 | 786 | ||
249 | 734 | if (pdata->image != NULL) { | 787 | if (pdata->image != NULL) { |
250 | 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); |
251 | @@ -894,10 +947,12 @@ | |||
252 | 894 | DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; | 947 | DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; |
253 | 895 | GValue prop_value = {0}; | 948 | GValue prop_value = {0}; |
254 | 896 | 949 | ||
255 | 950 | ensure_interned_strings_loaded (); | ||
256 | 951 | |||
257 | 897 | g_value_init (&prop_value, pspec->value_type); | 952 | g_value_init (&prop_value, pspec->value_type); |
258 | 898 | g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value); | 953 | g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value); |
259 | 899 | 954 | ||
261 | 900 | if (pspec->name == g_intern_static_string ("label")) | 955 | if (pspec->name == interned_str_label) |
262 | 901 | { | 956 | { |
263 | 902 | gchar * text = sanitize_label (GTK_LABEL (widget)); | 957 | gchar * text = sanitize_label (GTK_LABEL (widget)); |
264 | 903 | dbusmenu_menuitem_property_set (child, | 958 | dbusmenu_menuitem_property_set (child, |
265 | @@ -905,7 +960,7 @@ | |||
266 | 905 | text); | 960 | text); |
267 | 906 | g_free (text); | 961 | g_free (text); |
268 | 907 | } | 962 | } |
270 | 908 | else if (pspec->name == g_intern_static_string ("parent")) | 963 | else if (pspec->name == interned_str_parent) |
271 | 909 | { | 964 | { |
272 | 910 | if (GTK_WIDGET (g_value_get_object (&prop_value)) == NULL) | 965 | if (GTK_WIDGET (g_value_get_object (&prop_value)) == NULL) |
273 | 911 | { | 966 | { |
274 | @@ -929,55 +984,53 @@ | |||
275 | 929 | } | 984 | } |
276 | 930 | 985 | ||
277 | 931 | static void | 986 | static void |
281 | 932 | image_notify_cb (GtkWidget *widget, | 987 | image_notify_cb (GtkWidget * image, GParamSpec * pspec, gpointer data) |
279 | 933 | GParamSpec *pspec, | ||
280 | 934 | gpointer data) | ||
282 | 935 | { | 988 | { |
284 | 936 | DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; | 989 | ensure_interned_strings_loaded(); |
285 | 937 | 990 | ||
297 | 938 | if (pspec->name == g_intern_static_string ("file") || | 991 | if (pspec->name == interned_str_file || |
298 | 939 | pspec->name == g_intern_static_string ("gicon") || | 992 | pspec->name == interned_str_gicon || |
299 | 940 | pspec->name == g_intern_static_string ("icon-name") || | 993 | pspec->name == interned_str_icon_name || |
300 | 941 | pspec->name == g_intern_static_string ("icon-set") || | 994 | pspec->name == interned_str_icon_set || |
301 | 942 | pspec->name == g_intern_static_string ("image") || | 995 | pspec->name == interned_str_image || |
302 | 943 | pspec->name == g_intern_static_string ("mask") || | 996 | pspec->name == interned_str_mask || |
303 | 944 | pspec->name == g_intern_static_string ("pixbuf") || | 997 | pspec->name == interned_str_pixbuf || |
304 | 945 | pspec->name == g_intern_static_string ("pixbuf-animation") || | 998 | pspec->name == interned_str_pixbuf_animation || |
305 | 946 | pspec->name == g_intern_static_string ("pixmap") || | 999 | pspec->name == interned_str_pixmap || |
306 | 947 | pspec->name == g_intern_static_string ("stock") || | 1000 | pspec->name == interned_str_stock || |
307 | 948 | pspec->name == g_intern_static_string ("storage-type")) | 1001 | pspec->name == interned_str_storage_type) |
308 | 949 | { | 1002 | { |
309 | 1003 | DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data); | ||
310 | 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); |
312 | 951 | update_icon (mi, pdata, NULL, GTK_IMAGE (widget)); | 1005 | update_icon (mi, pdata, GTK_IMAGE (image)); |
313 | 952 | } | 1006 | } |
314 | 953 | } | 1007 | } |
315 | 954 | 1008 | ||
316 | 955 | static void | 1009 | static void |
320 | 956 | action_notify_cb (GtkAction *action, | 1010 | action_notify_cb (GtkAction *action, GParamSpec * pspec, gpointer data) |
318 | 957 | GParamSpec *pspec, | ||
319 | 958 | gpointer data) | ||
321 | 959 | { | 1011 | { |
323 | 960 | DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; | 1012 | DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data); |
324 | 1013 | ensure_interned_strings_loaded (); | ||
325 | 961 | 1014 | ||
327 | 962 | if (pspec->name == g_intern_static_string ("sensitive")) | 1015 | if (pspec->name == interned_str_sensitive) |
328 | 963 | { | 1016 | { |
329 | 964 | dbusmenu_menuitem_property_set_bool (mi, | 1017 | dbusmenu_menuitem_property_set_bool (mi, |
330 | 965 | DBUSMENU_MENUITEM_PROP_ENABLED, | 1018 | DBUSMENU_MENUITEM_PROP_ENABLED, |
331 | 966 | gtk_action_is_sensitive (action)); | 1019 | gtk_action_is_sensitive (action)); |
332 | 967 | } | 1020 | } |
334 | 968 | else if (pspec->name == g_intern_static_string ("visible")) | 1021 | else if (pspec->name == interned_str_visible) |
335 | 969 | { | 1022 | { |
336 | 970 | dbusmenu_menuitem_property_set_bool (mi, | 1023 | dbusmenu_menuitem_property_set_bool (mi, |
337 | 971 | DBUSMENU_MENUITEM_PROP_VISIBLE, | 1024 | DBUSMENU_MENUITEM_PROP_VISIBLE, |
338 | 972 | gtk_action_is_visible (action)); | 1025 | gtk_action_is_visible (action)); |
339 | 973 | } | 1026 | } |
341 | 974 | else if (pspec->name == g_intern_static_string ("active")) | 1027 | else if (pspec->name == interned_str_active) |
342 | 975 | { | 1028 | { |
343 | 976 | dbusmenu_menuitem_property_set_int (mi, | 1029 | dbusmenu_menuitem_property_set_int (mi, |
344 | 977 | DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, | 1030 | DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
345 | 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); |
346 | 979 | } | 1032 | } |
348 | 980 | else if (pspec->name == g_intern_static_string ("label")) | 1033 | else if (pspec->name == interned_str_label) |
349 | 981 | { | 1034 | { |
350 | 982 | gchar * text = sanitize_label_text (gtk_action_get_label (action)); | 1035 | gchar * text = sanitize_label_text (gtk_action_get_label (action)); |
351 | 983 | dbusmenu_menuitem_property_set (mi, | 1036 | dbusmenu_menuitem_property_set (mi, |
352 | @@ -988,23 +1041,23 @@ | |||
353 | 988 | } | 1041 | } |
354 | 989 | 1042 | ||
355 | 990 | static void | 1043 | static void |
359 | 991 | a11y_name_notify_cb (AtkObject *accessible, | 1044 | a11y_name_notify_cb (AtkObject * accessible, GParamSpec * pspec, gpointer data) |
357 | 992 | GParamSpec *pspec, | ||
358 | 993 | gpointer data) | ||
360 | 994 | { | 1045 | { |
366 | 995 | DbusmenuMenuitem *item = (DbusmenuMenuitem *)data; | 1046 | ensure_interned_strings_loaded (); |
362 | 996 | GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); | ||
363 | 997 | GtkWidget *label = find_menu_label (widget); | ||
364 | 998 | const gchar *label_text = gtk_label_get_text (GTK_LABEL (label)); | ||
365 | 999 | const gchar *name = atk_object_get_name (accessible); | ||
367 | 1000 | 1047 | ||
368 | 1001 | /* If an application sets the accessible name to NULL, then a subsequent | 1048 | /* If an application sets the accessible name to NULL, then a subsequent |
369 | 1002 | * call to get the accessible name from the Atk object should return the same | 1049 | * call to get the accessible name from the Atk object should return the same |
370 | 1003 | * string as the text of the menu item label, in which case, we want to clear | 1050 | * string as the text of the menu item label, in which case, we want to clear |
371 | 1004 | * the accessible description property of the dbusmenu item. | 1051 | * the accessible description property of the dbusmenu item. |
372 | 1005 | */ | 1052 | */ |
374 | 1006 | if (pspec->name == g_intern_static_string ("accessible-name")) | 1053 | if (pspec->name == interned_str_accessible_name) |
375 | 1007 | { | 1054 | { |
376 | 1055 | DbusmenuMenuitem * item = DBUSMENU_MENUITEM(data); | ||
377 | 1056 | GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); | ||
378 | 1057 | GtkWidget *label = find_menu_label (widget); | ||
379 | 1058 | const gchar *label_text = gtk_label_get_text (GTK_LABEL (label)); | ||
380 | 1059 | const gchar *name = atk_object_get_name (accessible); | ||
381 | 1060 | |||
382 | 1008 | if (!g_strcmp0 (name, label_text)) | 1061 | if (!g_strcmp0 (name, label_text)) |
383 | 1009 | dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL); | 1062 | dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL); |
384 | 1010 | else | 1063 | else |
385 | @@ -1099,54 +1152,52 @@ | |||
386 | 1099 | } | 1152 | } |
387 | 1100 | 1153 | ||
388 | 1101 | static void | 1154 | static void |
392 | 1102 | widget_notify_cb (GtkWidget *widget, | 1155 | widget_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data) |
390 | 1103 | GParamSpec *pspec, | ||
391 | 1104 | gpointer data) | ||
393 | 1105 | { | 1156 | { |
394 | 1106 | DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; | ||
395 | 1107 | GValue prop_value = {0}; | 1157 | GValue prop_value = {0}; |
396 | 1158 | DbusmenuMenuitem * child = DBUSMENU_MENUITEM(data); | ||
397 | 1159 | g_return_if_fail (child != NULL); | ||
398 | 1160 | |||
399 | 1161 | ensure_interned_strings_loaded (); | ||
400 | 1108 | 1162 | ||
401 | 1109 | g_value_init (&prop_value, pspec->value_type); | 1163 | g_value_init (&prop_value, pspec->value_type); |
402 | 1110 | g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value); | 1164 | g_object_get_property (G_OBJECT (widget), pspec->name, &prop_value); |
403 | 1111 | 1165 | ||
405 | 1112 | if (pspec->name == g_intern_static_string ("sensitive")) | 1166 | if (pspec->name == interned_str_sensitive) |
406 | 1113 | { | 1167 | { |
407 | 1114 | dbusmenu_menuitem_property_set_bool (child, | 1168 | dbusmenu_menuitem_property_set_bool (child, |
408 | 1115 | DBUSMENU_MENUITEM_PROP_ENABLED, | 1169 | DBUSMENU_MENUITEM_PROP_ENABLED, |
409 | 1116 | g_value_get_boolean (&prop_value)); | 1170 | g_value_get_boolean (&prop_value)); |
410 | 1117 | } | 1171 | } |
412 | 1118 | else if (pspec->name == g_intern_static_string ("label")) | 1172 | else if (pspec->name == interned_str_label) |
413 | 1119 | { | 1173 | { |
415 | 1120 | if (handle_first_label (child)) | 1174 | if (!handle_first_label (child)) |
416 | 1121 | { | 1175 | { |
418 | 1122 | return; | 1176 | dbusmenu_menuitem_property_set (child, |
419 | 1177 | DBUSMENU_MENUITEM_PROP_LABEL, | ||
420 | 1178 | g_value_get_string (&prop_value)); | ||
421 | 1123 | } | 1179 | } |
422 | 1124 | |||
423 | 1125 | dbusmenu_menuitem_property_set (child, | ||
424 | 1126 | DBUSMENU_MENUITEM_PROP_LABEL, | ||
425 | 1127 | g_value_get_string (&prop_value)); | ||
426 | 1128 | } | 1180 | } |
428 | 1129 | else if (pspec->name == g_intern_static_string ("visible")) | 1181 | else if (pspec->name == interned_str_visible) |
429 | 1130 | { | 1182 | { |
430 | 1131 | dbusmenu_menuitem_property_set_bool (child, | 1183 | dbusmenu_menuitem_property_set_bool (child, |
431 | 1132 | DBUSMENU_MENUITEM_PROP_VISIBLE, | 1184 | DBUSMENU_MENUITEM_PROP_VISIBLE, |
432 | 1133 | g_value_get_boolean (&prop_value)); | 1185 | g_value_get_boolean (&prop_value)); |
433 | 1134 | } | 1186 | } |
435 | 1135 | else if (pspec->name == g_intern_static_string ("always-show-image")) | 1187 | else if (pspec->name == interned_str_always_show_image) |
436 | 1136 | { | 1188 | { |
437 | 1137 | GtkWidget *image = NULL; | 1189 | GtkWidget *image = NULL; |
438 | 1138 | g_object_get(widget, "image", &image, NULL); | 1190 | g_object_get(widget, "image", &image, NULL); |
439 | 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); |
441 | 1140 | update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE(image)); | 1192 | update_icon (child, pdata, GTK_IMAGE(image)); |
442 | 1141 | } | 1193 | } |
444 | 1142 | else if (pspec->name == g_intern_static_string ("image")) | 1194 | else if (pspec->name == interned_str_image) |
445 | 1143 | { | 1195 | { |
448 | 1144 | GtkWidget *image; | 1196 | GtkWidget * image = GTK_WIDGET (g_value_get_object (&prop_value)); |
447 | 1145 | image = GTK_WIDGET (g_value_get_object (&prop_value)); | ||
449 | 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); |
451 | 1147 | update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image)); | 1198 | update_icon (child, pdata, GTK_IMAGE (image)); |
452 | 1148 | } | 1199 | } |
454 | 1149 | else if (pspec->name == g_intern_static_string ("parent")) | 1200 | else if (pspec->name == interned_str_parent) |
455 | 1150 | { | 1201 | { |
456 | 1151 | /* | 1202 | /* |
457 | 1152 | * We probably should have added a 'remove' method to the | 1203 | * We probably should have added a 'remove' method to the |
458 | @@ -1166,7 +1217,7 @@ | |||
459 | 1166 | } | 1217 | } |
460 | 1167 | } | 1218 | } |
461 | 1168 | } | 1219 | } |
463 | 1169 | else if (pspec->name == g_intern_static_string ("submenu")) | 1220 | else if (pspec->name == interned_str_submenu) |
464 | 1170 | { | 1221 | { |
465 | 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. */ |
466 | 1172 | /* First, delete any children that may exist currently. */ | 1223 | /* First, delete any children that may exist currently. */ |
A lot of cleanups!