Merge lp:~3v1n0/bamf/app-main-view into lp:bamf
- app-main-view
- Merge into trunk
Proposed by
Marco Trevisan (Treviño)
Status: | Merged |
---|---|
Approved by: | Brandon Schaefer |
Approved revision: | 609 |
Merged at revision: | 564 |
Proposed branch: | lp:~3v1n0/bamf/app-main-view |
Merge into: | lp:bamf |
Diff against target: |
1004 lines (+594/-125) 6 files modified
src/bamf-application.c (+216/-111) src/bamf-application.h (+18/-6) src/bamf-unity-webapps-application.c (+1/-1) src/bamf-unity-webapps-observer.c (+7/-1) tests/bamfdaemon/test-application.c (+338/-6) tests/bamfdaemon/test-bamf.c (+14/-0) |
To merge this branch: | bzr merge lp:~3v1n0/bamf/app-main-view |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brandon Schaefer (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+175063@code.launchpad.net |
Commit message
BamfApplication: keep track of the application main-window and update name and icon accordingly
Applications without a .desktop file should update their name and icon based on their children.
So now we try to compute the main window children, and we update name and icon based on it.
Description of the change
Add a special "main_window" children to the BamfApplication, in this way we keep track of the child that is currently leading the application window group.
Thanks to this, we can update the application name and icon whenever they change.
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote : | # |
LGTM
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/bamf-application.c' |
2 | --- src/bamf-application.c 2013-07-16 00:25:51 +0000 |
3 | +++ src/bamf-application.c 2013-07-16 16:30:44 +0000 |
4 | @@ -38,12 +38,12 @@ |
5 | struct _BamfApplicationPrivate |
6 | { |
7 | BamfDBusItemApplication *dbus_iface; |
8 | + BamfApplicationType app_type; |
9 | + BamfView * main_child; |
10 | char * desktop_file; |
11 | GList * desktop_file_list; |
12 | - char * app_type; |
13 | char * wmclass; |
14 | char ** mimes; |
15 | - gboolean is_tab_container; |
16 | gboolean show_stubs; |
17 | }; |
18 | |
19 | @@ -57,6 +57,8 @@ |
20 | |
21 | #define STUB_KEY "X-Ayatana-Appmenu-Show-Stubs" |
22 | |
23 | +static void on_main_child_name_changed (BamfView *, const gchar *, const gchar *, BamfApplication *); |
24 | + |
25 | void |
26 | bamf_application_supported_mime_types_changed (BamfApplication *application, |
27 | const gchar **new_mimes) |
28 | @@ -136,23 +138,21 @@ |
29 | return g_strdupv (mimes); |
30 | } |
31 | |
32 | -char * |
33 | +BamfApplicationType |
34 | bamf_application_get_application_type (BamfApplication *application) |
35 | { |
36 | - g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL); |
37 | + g_return_val_if_fail (BAMF_IS_APPLICATION (application), BAMF_APPLICATION_UNKNOWN); |
38 | |
39 | - return g_strdup (application->priv->app_type); |
40 | + return application->priv->app_type; |
41 | } |
42 | |
43 | void |
44 | -bamf_application_set_application_type (BamfApplication *application, const gchar *type) |
45 | +bamf_application_set_application_type (BamfApplication *application, BamfApplicationType type) |
46 | { |
47 | g_return_if_fail (BAMF_IS_APPLICATION (application)); |
48 | - |
49 | - if (application->priv->app_type) |
50 | - g_free (application->priv->app_type); |
51 | - |
52 | - application->priv->app_type = g_strdup (type); |
53 | + g_return_if_fail (type >= 0 && type < BAMF_APPLICATION_UNKNOWN); |
54 | + |
55 | + application->priv->app_type = type; |
56 | } |
57 | |
58 | const char * |
59 | @@ -201,22 +201,24 @@ |
60 | } |
61 | |
62 | static void |
63 | -bamf_application_setup_icon_and_name (BamfApplication *self) |
64 | +bamf_application_setup_icon_and_name (BamfApplication *self, gboolean force) |
65 | { |
66 | - BamfView *view; |
67 | - BamfWindow *window = NULL; |
68 | + BamfWindow *window; |
69 | + BamfLegacyWindow *legacy_window; |
70 | GDesktopAppInfo *desktop; |
71 | GKeyFile * keyfile; |
72 | GIcon *gicon; |
73 | - GList *children, *l; |
74 | const char *class; |
75 | char *icon = NULL, *generic_icon = NULL, *name = NULL; |
76 | GError *error; |
77 | |
78 | g_return_if_fail (BAMF_IS_APPLICATION (self)); |
79 | |
80 | - if (bamf_view_get_icon (BAMF_VIEW (self)) && bamf_view_get_name (BAMF_VIEW (self))) |
81 | - return; |
82 | + if (!force) |
83 | + { |
84 | + if (bamf_view_get_icon (BAMF_VIEW (self)) && bamf_view_get_name (BAMF_VIEW (self))) |
85 | + return; |
86 | + } |
87 | |
88 | if (self->priv->desktop_file) |
89 | { |
90 | @@ -289,66 +291,57 @@ |
91 | g_object_unref (desktop); |
92 | g_key_file_free (keyfile); |
93 | } |
94 | - else if ((children = bamf_view_get_children (BAMF_VIEW (self))) != NULL) |
95 | + else if (BAMF_IS_WINDOW (self->priv->main_child)) |
96 | { |
97 | - for (l = children; l && !icon; l = l->next) |
98 | - { |
99 | - view = l->data; |
100 | - if (!BAMF_IS_WINDOW (view)) |
101 | - continue; |
102 | - |
103 | - window = BAMF_WINDOW (view); |
104 | - |
105 | - do |
106 | - { |
107 | - class = bamf_legacy_window_get_class_name (bamf_window_get_window (window)); |
108 | - |
109 | - if (class) |
110 | - { |
111 | - icon = g_utf8_strdown (class, -1); |
112 | - |
113 | - if (icon_name_is_valid (icon)) |
114 | - { |
115 | - if (icon_name_is_generic (icon)) |
116 | - { |
117 | - generic_icon = g_strdup (icon); |
118 | - } |
119 | - else |
120 | - { |
121 | - break; |
122 | - } |
123 | - } |
124 | - } |
125 | - |
126 | - g_free (icon); |
127 | - char *exec = bamf_legacy_window_get_exec_string (bamf_window_get_window (window)); |
128 | - icon = bamf_matcher_get_trimmed_exec (bamf_matcher_get_default (), exec); |
129 | - g_free (exec); |
130 | - |
131 | - if (icon_name_is_valid (icon)) |
132 | - { |
133 | - if (icon_name_is_generic (icon)) |
134 | - { |
135 | - generic_icon = g_strdup (icon); |
136 | - } |
137 | - else |
138 | - { |
139 | - break; |
140 | - } |
141 | - } |
142 | - |
143 | - g_free (icon); |
144 | - icon = NULL; |
145 | - } |
146 | - while (FALSE); |
147 | - |
148 | - name = g_strdup (bamf_legacy_window_get_name (bamf_window_get_window (window))); |
149 | - } |
150 | - |
151 | - if (!icon) |
152 | - { |
153 | - if (window) |
154 | - icon = g_strdup (bamf_legacy_window_save_mini_icon (bamf_window_get_window (window))); |
155 | + name = g_strdup (bamf_view_get_name (self->priv->main_child)); |
156 | + window = BAMF_WINDOW (self->priv->main_child); |
157 | + legacy_window = bamf_window_get_window (window); |
158 | + class = bamf_legacy_window_get_class_name (legacy_window); |
159 | + |
160 | + if (class) |
161 | + { |
162 | + icon = g_utf8_strdown (class, -1); |
163 | + |
164 | + if (icon_name_is_valid (icon)) |
165 | + { |
166 | + if (icon_name_is_generic (icon)) |
167 | + { |
168 | + generic_icon = icon; |
169 | + icon = NULL; |
170 | + } |
171 | + } |
172 | + else |
173 | + { |
174 | + g_free (icon); |
175 | + icon = NULL; |
176 | + } |
177 | + } |
178 | + |
179 | + if (!icon) |
180 | + { |
181 | + char *exec = bamf_legacy_window_get_exec_string (legacy_window); |
182 | + icon = bamf_matcher_get_trimmed_exec (bamf_matcher_get_default (), exec); |
183 | + g_free (exec); |
184 | + |
185 | + if (icon_name_is_valid (icon)) |
186 | + { |
187 | + if (icon_name_is_generic (icon)) |
188 | + { |
189 | + g_free (generic_icon); |
190 | + generic_icon = icon; |
191 | + icon = NULL; |
192 | + } |
193 | + } |
194 | + else |
195 | + { |
196 | + g_free (icon); |
197 | + icon = NULL; |
198 | + } |
199 | + } |
200 | + |
201 | + if (!icon) |
202 | + { |
203 | + icon = g_strdup (bamf_legacy_window_save_mini_icon (legacy_window)); |
204 | |
205 | if (!icon) |
206 | { |
207 | @@ -381,15 +374,22 @@ |
208 | { |
209 | g_return_if_fail (BAMF_IS_APPLICATION (application)); |
210 | |
211 | - if (application->priv->desktop_file) |
212 | - g_free (application->priv->desktop_file); |
213 | + if (g_strcmp0 (application->priv->desktop_file, desktop_file) == 0) |
214 | + return; |
215 | + |
216 | + g_free (application->priv->desktop_file); |
217 | + application->priv->desktop_file = NULL; |
218 | |
219 | if (desktop_file && desktop_file[0] != '\0') |
220 | application->priv->desktop_file = g_strdup (desktop_file); |
221 | - else |
222 | - application->priv->desktop_file = NULL; |
223 | - |
224 | - bamf_application_setup_icon_and_name (application); |
225 | + |
226 | + if (application->priv->main_child) |
227 | + { |
228 | + g_signal_handlers_disconnect_by_func (application->priv->main_child, |
229 | + on_main_child_name_changed, application); |
230 | + } |
231 | + |
232 | + bamf_application_setup_icon_and_name (application, TRUE); |
233 | } |
234 | |
235 | gboolean |
236 | @@ -632,25 +632,79 @@ |
237 | } |
238 | |
239 | static void |
240 | +on_main_child_name_changed (BamfView *child, const gchar *old_name, |
241 | + const gchar *new_name, BamfApplication *self) |
242 | +{ |
243 | + bamf_view_set_name (BAMF_VIEW (self), new_name); |
244 | +} |
245 | + |
246 | +static void |
247 | +bamf_application_set_main_child (BamfApplication *self, BamfView *child) |
248 | +{ |
249 | + if (self->priv->main_child == child) |
250 | + return; |
251 | + |
252 | + if (self->priv->main_child) |
253 | + { |
254 | + g_object_remove_weak_pointer (G_OBJECT (self->priv->main_child), |
255 | + (gpointer*) &self->priv->main_child); |
256 | + g_signal_handlers_disconnect_by_func (self->priv->main_child, |
257 | + on_main_child_name_changed, self); |
258 | + } |
259 | + |
260 | + self->priv->main_child = child; |
261 | + |
262 | + if (self->priv->main_child) |
263 | + { |
264 | + g_object_add_weak_pointer (G_OBJECT (self->priv->main_child), |
265 | + (gpointer*) &self->priv->main_child); |
266 | + |
267 | + if (!self->priv->desktop_file) |
268 | + { |
269 | + g_signal_connect (child, "name-changed", |
270 | + G_CALLBACK (on_main_child_name_changed), self); |
271 | + } |
272 | + } |
273 | +} |
274 | + |
275 | +BamfView * |
276 | +bamf_application_get_main_child (BamfApplication *self) |
277 | +{ |
278 | + g_return_val_if_fail (BAMF_IS_APPLICATION (self), NULL); |
279 | + |
280 | + return self->priv->main_child; |
281 | +} |
282 | + |
283 | +static void |
284 | view_exported (BamfView *view, BamfApplication *self) |
285 | { |
286 | g_signal_emit_by_name (self, "window-added", bamf_view_get_path (view)); |
287 | + g_signal_handlers_disconnect_by_func (view, view_exported, self); |
288 | } |
289 | |
290 | static void |
291 | bamf_application_child_added (BamfView *view, BamfView *child) |
292 | { |
293 | BamfApplication *application; |
294 | + BamfWindow *window = NULL; |
295 | + gboolean reset_emblems = FALSE; |
296 | |
297 | application = BAMF_APPLICATION (view); |
298 | |
299 | if (BAMF_IS_WINDOW (child)) |
300 | { |
301 | + window = BAMF_WINDOW (child); |
302 | + |
303 | if (bamf_view_is_on_bus (child)) |
304 | - g_signal_emit_by_name (BAMF_APPLICATION (view), "window-added", bamf_view_get_path (child)); |
305 | + { |
306 | + g_signal_emit_by_name (BAMF_APPLICATION (view), "window-added", |
307 | + bamf_view_get_path (child)); |
308 | + } |
309 | else |
310 | - g_signal_connect (G_OBJECT (child), "exported", |
311 | - (GCallback) view_exported, view); |
312 | + { |
313 | + g_signal_connect (G_OBJECT (child), "exported", |
314 | + (GCallback) view_exported, view); |
315 | + } |
316 | } |
317 | |
318 | g_signal_connect (G_OBJECT (child), "active-changed", |
319 | @@ -666,9 +720,30 @@ |
320 | (GCallback) view_xid_changed, view); |
321 | } |
322 | |
323 | + if (application->priv->main_child) |
324 | + { |
325 | + if (window && BAMF_IS_WINDOW (application->priv->main_child)) |
326 | + { |
327 | + BamfWindow *main_window = BAMF_WINDOW (application->priv->main_child); |
328 | + |
329 | + if (bamf_window_get_window_type (main_window) != BAMF_WINDOW_NORMAL && |
330 | + bamf_window_get_window_type (window) == BAMF_WINDOW_NORMAL) |
331 | + { |
332 | + bamf_application_set_main_child (application, child); |
333 | + } |
334 | + } |
335 | + } |
336 | + else |
337 | + { |
338 | + bamf_application_set_main_child (application, child); |
339 | + } |
340 | + |
341 | bamf_application_ensure_flags (BAMF_APPLICATION (view)); |
342 | |
343 | - bamf_application_setup_icon_and_name (application); |
344 | + if (!application->priv->desktop_file && application->priv->main_child == child) |
345 | + reset_emblems = TRUE; |
346 | + |
347 | + bamf_application_setup_icon_and_name (application, reset_emblems); |
348 | } |
349 | |
350 | static char * |
351 | @@ -740,6 +815,8 @@ |
352 | bamf_application_child_removed (BamfView *view, BamfView *child) |
353 | { |
354 | BamfApplication *self = BAMF_APPLICATION (view); |
355 | + GList *children, *l; |
356 | + |
357 | if (BAMF_IS_WINDOW (child)) |
358 | { |
359 | if (bamf_view_is_on_bus (child)) |
360 | @@ -751,7 +828,35 @@ |
361 | |
362 | bamf_application_ensure_flags (self); |
363 | |
364 | - if (!bamf_view_get_children (view) && bamf_application_get_close_when_empty (self)) |
365 | + children = bamf_view_get_children (view); |
366 | + |
367 | + if (self->priv->main_child == child) |
368 | + { |
369 | + /* Giving priority to older windows, and BamfView has a reversed list */ |
370 | + children = g_list_last (children); |
371 | + bamf_application_set_main_child (self, (children ? children->data : NULL)); |
372 | + |
373 | + if (self->priv->app_type == BAMF_APPLICATION_SYSTEM) |
374 | + { |
375 | + /* We check if we have a better target in next windows */ |
376 | + for (l = children; l; l = l->prev) |
377 | + { |
378 | + if (bamf_window_get_window_type (BAMF_WINDOW (l->data)) == BAMF_WINDOW_NORMAL) |
379 | + { |
380 | + bamf_application_set_main_child (self, l->data); |
381 | + break; |
382 | + } |
383 | + } |
384 | + } |
385 | + |
386 | + if (self->priv->main_child) |
387 | + { |
388 | + gboolean reset_emblems = (!self->priv->desktop_file); |
389 | + bamf_application_setup_icon_and_name (self, reset_emblems); |
390 | + } |
391 | + } |
392 | + |
393 | + if (!children && bamf_application_get_close_when_empty (self)) |
394 | { |
395 | bamf_view_close (view); |
396 | } |
397 | @@ -901,9 +1006,21 @@ |
398 | GDBusMethodInvocation *invocation, |
399 | BamfApplication *self) |
400 | { |
401 | - const char *type = self->priv->app_type ? self->priv->app_type : ""; |
402 | - g_dbus_method_invocation_return_value (invocation, |
403 | - g_variant_new ("(s)", type)); |
404 | + const char *type = ""; |
405 | + |
406 | + switch (self->priv->app_type) |
407 | + { |
408 | + case BAMF_APPLICATION_SYSTEM: |
409 | + type = "system"; |
410 | + break; |
411 | + case BAMF_APPLICATION_WEB: |
412 | + type = "webapp"; |
413 | + break; |
414 | + default: |
415 | + type = "unknown"; |
416 | + } |
417 | + |
418 | + g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", type)); |
419 | |
420 | return TRUE; |
421 | } |
422 | @@ -929,18 +1046,20 @@ |
423 | priv->desktop_file_list = NULL; |
424 | } |
425 | |
426 | - if (priv->app_type) |
427 | - { |
428 | - g_free (priv->app_type); |
429 | - priv->app_type = NULL; |
430 | - } |
431 | - |
432 | if (priv->wmclass) |
433 | { |
434 | g_free (priv->wmclass); |
435 | priv->wmclass = NULL; |
436 | } |
437 | |
438 | + if (priv->main_child) |
439 | + { |
440 | + g_object_remove_weak_pointer (G_OBJECT (priv->main_child), |
441 | + (gpointer*) &priv->main_child); |
442 | + g_signal_handlers_disconnect_by_data (priv->main_child, app); |
443 | + priv->main_child = NULL; |
444 | + } |
445 | + |
446 | g_strfreev (priv->mimes); |
447 | priv->mimes = NULL; |
448 | |
449 | @@ -967,10 +1086,8 @@ |
450 | BamfApplicationPrivate *priv; |
451 | priv = self->priv = BAMF_APPLICATION_GET_PRIVATE (self); |
452 | |
453 | - priv->is_tab_container = FALSE; |
454 | - priv->app_type = g_strdup ("system"); |
455 | + priv->app_type = BAMF_APPLICATION_SYSTEM; |
456 | priv->show_stubs = TRUE; |
457 | - priv->wmclass = NULL; |
458 | |
459 | /* Initializing the dbus interface */ |
460 | priv->dbus_iface = _bamf_dbus_item_application_skeleton_new (); |
461 | @@ -1087,17 +1204,6 @@ |
462 | return application; |
463 | } |
464 | |
465 | -/** |
466 | - bamf_application_get_show_stubs: |
467 | - @application: Application to check for menu stubs |
468 | - |
469 | - Checks to see if the application should show menu stubs or not. |
470 | - This is specified with the "X-Ayatana-Appmenu-Show-Stubs" desktop |
471 | - file key. |
472 | - |
473 | - Return Value: Defaults to TRUE, else FALSE if specified in |
474 | - .desktop file. |
475 | -*/ |
476 | gboolean |
477 | bamf_application_get_show_stubs (BamfApplication *application) |
478 | { |
479 | @@ -1105,7 +1211,6 @@ |
480 | return application->priv->show_stubs; |
481 | } |
482 | |
483 | - |
484 | gboolean |
485 | bamf_application_get_close_when_empty (BamfApplication *application) |
486 | { |
487 | |
488 | === modified file 'src/bamf-application.h' |
489 | --- src/bamf-application.h 2013-06-18 13:44:04 +0000 |
490 | +++ src/bamf-application.h 2013-07-16 16:30:44 +0000 |
491 | @@ -56,6 +56,13 @@ |
492 | BamfApplicationPrivate *priv; |
493 | }; |
494 | |
495 | +typedef enum |
496 | +{ |
497 | + BAMF_APPLICATION_SYSTEM, /* BamfWindow container */ |
498 | + BAMF_APPLICATION_WEB, /* BamfTab container */ |
499 | + BAMF_APPLICATION_UNKNOWN, |
500 | +} BamfApplicationType; |
501 | + |
502 | GType bamf_application_get_type (void) G_GNUC_CONST; |
503 | |
504 | void bamf_application_emit_supported_mime_types_changed (BamfApplication *application); |
505 | @@ -64,7 +71,7 @@ |
506 | void bamf_application_set_desktop_file (BamfApplication *application, |
507 | const char * desktop_file); |
508 | |
509 | -char ** bamf_application_get_supported_mime_types (BamfApplication *application); |
510 | +char ** bamf_application_get_supported_mime_types (BamfApplication *application); |
511 | |
512 | GVariant * bamf_application_get_xids (BamfApplication *application); |
513 | |
514 | @@ -90,11 +97,16 @@ |
515 | |
516 | BamfApplication * bamf_application_new_with_wmclass (const char *wmclass); |
517 | |
518 | -void bamf_application_set_application_type (BamfApplication *application, const gchar *type); |
519 | - |
520 | -void bamf_application_get_application_menu (BamfApplication *application, gchar **name, gchar **object_path); |
521 | - |
522 | -BamfView * bamf_application_get_focusable_child (BamfApplication *application); |
523 | +void bamf_application_set_application_type (BamfApplication *application, |
524 | + BamfApplicationType type); |
525 | +BamfApplicationType bamf_application_get_application_type (BamfApplication *application); |
526 | + |
527 | +void bamf_application_get_application_menu (BamfApplication *application, |
528 | + gchar **name, gchar **object_path); |
529 | + |
530 | +BamfView * bamf_application_get_focusable_child (BamfApplication *application); |
531 | + |
532 | +BamfView * bamf_application_get_main_child (BamfApplication *application); |
533 | |
534 | gboolean bamf_application_get_close_when_empty (BamfApplication *application); |
535 | gboolean bamf_application_set_desktop_file_from_id (BamfApplication *application, const char *id); |
536 | |
537 | === modified file 'src/bamf-unity-webapps-application.c' |
538 | --- src/bamf-unity-webapps-application.c 2013-06-13 18:40:56 +0000 |
539 | +++ src/bamf-unity-webapps-application.c 2013-07-16 16:30:44 +0000 |
540 | @@ -267,7 +267,7 @@ |
541 | { |
542 | self->priv = BAMF_UNITY_WEBAPPS_APPLICATION_GET_PRIVATE (self); |
543 | |
544 | - bamf_application_set_application_type (BAMF_APPLICATION (self), "webapp"); |
545 | + bamf_application_set_application_type (BAMF_APPLICATION (self), BAMF_APPLICATION_WEB); |
546 | |
547 | } |
548 | |
549 | |
550 | === modified file 'src/bamf-unity-webapps-observer.c' |
551 | --- src/bamf-unity-webapps-observer.c 2013-06-13 18:40:56 +0000 |
552 | +++ src/bamf-unity-webapps-observer.c 2013-07-16 16:30:44 +0000 |
553 | @@ -204,7 +204,10 @@ |
554 | |
555 | g_hash_table_destroy (observer->priv->applications_by_context_name); |
556 | |
557 | - g_bus_unwatch_name (observer->priv->service_watch_id); |
558 | + if (observer->priv->service_watch_id) |
559 | + { |
560 | + g_bus_unwatch_name (observer->priv->service_watch_id); |
561 | + } |
562 | |
563 | if (observer->priv->service) |
564 | { |
565 | @@ -225,6 +228,9 @@ |
566 | G_OBJECT_CLASS (bamf_unity_webapps_observer_parent_class)->constructed (object); |
567 | } |
568 | |
569 | + if (g_strcmp0 (g_getenv ("BAMF_TEST_MODE"), "TRUE") == 0) |
570 | + return; |
571 | + |
572 | observer->priv->service_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, |
573 | "com.canonical.Unity.Webapps.Service", |
574 | G_BUS_NAME_WATCHER_FLAGS_NONE, |
575 | |
576 | === modified file 'tests/bamfdaemon/test-application.c' |
577 | --- tests/bamfdaemon/test-application.c 2013-07-16 00:27:11 +0000 |
578 | +++ tests/bamfdaemon/test-application.c 2013-07-16 16:30:44 +0000 |
579 | @@ -27,7 +27,9 @@ |
580 | #include "bamf-legacy-window.h" |
581 | #include "bamf-legacy-window-test.h" |
582 | |
583 | -#define DESKTOP_FILE "/usr/share/applications/gnome-terminal.desktop" |
584 | +#define DESKTOP_FILE TESTDIR"/data/test-bamf-app.desktop" |
585 | + |
586 | +void ignore_fatal_errors (void); |
587 | |
588 | static gboolean signal_seen = FALSE; |
589 | static gboolean signal_result = FALSE; |
590 | @@ -66,7 +68,7 @@ |
591 | static void |
592 | test_allocation (void) |
593 | { |
594 | - BamfApplication *application; |
595 | + BamfApplication *application; |
596 | |
597 | /* Check it allocates */ |
598 | application = bamf_application_new (); |
599 | @@ -81,12 +83,47 @@ |
600 | } |
601 | |
602 | static void |
603 | +test_type (void) |
604 | +{ |
605 | + BamfApplication *application = bamf_application_new (); |
606 | + g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM); |
607 | + |
608 | + g_object_unref (application); |
609 | +} |
610 | + |
611 | +static void |
612 | +test_type_set (void) |
613 | +{ |
614 | + BamfApplication *application = bamf_application_new (); |
615 | + |
616 | + bamf_application_set_application_type (application, BAMF_APPLICATION_WEB); |
617 | + g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_WEB); |
618 | + |
619 | + bamf_application_set_application_type (application, BAMF_APPLICATION_SYSTEM); |
620 | + g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM); |
621 | + |
622 | + g_object_unref (application); |
623 | +} |
624 | + |
625 | +static void |
626 | +test_type_set_invalid (void) |
627 | +{ |
628 | + ignore_fatal_errors(); |
629 | + BamfApplication *application = bamf_application_new (); |
630 | + |
631 | + bamf_application_set_application_type (application, BAMF_APPLICATION_UNKNOWN); |
632 | + g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM); |
633 | + |
634 | + bamf_application_set_application_type (application, -1); |
635 | + g_assert_cmpuint (bamf_application_get_application_type (application), ==, BAMF_APPLICATION_SYSTEM); |
636 | + |
637 | + g_object_unref (application); |
638 | +} |
639 | + |
640 | +static void |
641 | test_desktop_file (void) |
642 | { |
643 | - BamfApplication *application; |
644 | - |
645 | - /* Check it allocates */ |
646 | - application = bamf_application_new (); |
647 | + BamfApplication *application = bamf_application_new (); |
648 | g_assert (bamf_application_get_desktop_file (application) == NULL); |
649 | |
650 | bamf_application_set_desktop_file (application, DESKTOP_FILE); |
651 | @@ -733,6 +770,7 @@ |
652 | |
653 | g_object_unref (window); |
654 | g_object_unref (test); |
655 | + g_object_unref (application); |
656 | } |
657 | |
658 | static void |
659 | @@ -777,6 +815,287 @@ |
660 | |
661 | g_object_unref (window); |
662 | g_object_unref (test); |
663 | + g_object_unref (application); |
664 | +} |
665 | + |
666 | +static void |
667 | +test_desktop_app_main_child (void) |
668 | +{ |
669 | + BamfApplication *application; |
670 | + BamfLegacyWindowTest *lwin; |
671 | + BamfWindow *win; |
672 | + |
673 | + application = bamf_application_new_from_desktop_file (DESKTOP_FILE); |
674 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
675 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
676 | + |
677 | + g_assert (!bamf_application_get_main_child (application)); |
678 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
679 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win)); |
680 | + |
681 | + g_object_unref (lwin); |
682 | + g_object_unref (win); |
683 | + g_object_unref (application); |
684 | +} |
685 | + |
686 | +static void |
687 | +test_desktop_app_main_child_doesnt_match_emblems (void) |
688 | +{ |
689 | + BamfApplication *application; |
690 | + BamfLegacyWindowTest *lwin; |
691 | + BamfWindow *win; |
692 | + |
693 | + application = bamf_application_new_from_desktop_file (DESKTOP_FILE); |
694 | + lwin = bamf_legacy_window_test_new (20, "window", "python", "execution-binary"); |
695 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
696 | + |
697 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
698 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "window"); |
699 | + g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), !=, "python"); |
700 | + |
701 | + g_object_unref (lwin); |
702 | + g_object_unref (win); |
703 | + g_object_unref (application); |
704 | +} |
705 | + |
706 | +static void |
707 | +test_desktop_app_main_child_doesnt_update_emblems (void) |
708 | +{ |
709 | + BamfApplication *application; |
710 | + BamfLegacyWindowTest *lwin; |
711 | + BamfWindow *win; |
712 | + |
713 | + application = bamf_application_new_from_desktop_file (DESKTOP_FILE); |
714 | + lwin = bamf_legacy_window_test_new (20, "window", "python", "execution-binary"); |
715 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
716 | + |
717 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
718 | + bamf_legacy_window_test_set_name (lwin, "New Window Name"); |
719 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "New Window Name"); |
720 | + |
721 | + bamf_legacy_window_test_set_name (lwin, "even-new-name"); |
722 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), !=, "even-new-name"); |
723 | + |
724 | + g_object_unref (lwin); |
725 | + g_object_unref (win); |
726 | + g_object_unref (application); |
727 | +} |
728 | + |
729 | +static void |
730 | +test_app_main_child (void) |
731 | +{ |
732 | + BamfApplication *application; |
733 | + BamfLegacyWindowTest *lwin; |
734 | + BamfWindow *win; |
735 | + |
736 | + application = bamf_application_new (); |
737 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
738 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
739 | + |
740 | + g_assert (!bamf_application_get_main_child (application)); |
741 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
742 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win)); |
743 | + |
744 | + g_object_unref (lwin); |
745 | + g_object_unref (win); |
746 | + |
747 | + g_assert (!bamf_application_get_main_child (application)); |
748 | + g_object_unref (application); |
749 | +} |
750 | + |
751 | +static void |
752 | +test_app_main_child_matches_emblems (void) |
753 | +{ |
754 | + BamfApplication *application; |
755 | + BamfLegacyWindowTest *lwin; |
756 | + BamfWindow *win; |
757 | + |
758 | + application = bamf_application_new (); |
759 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
760 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
761 | + |
762 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
763 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window"); |
764 | + g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon"); |
765 | + |
766 | + g_object_unref (lwin); |
767 | + g_object_unref (win); |
768 | + g_object_unref (application); |
769 | +} |
770 | + |
771 | +static void |
772 | +test_app_main_child_updates_emblems (void) |
773 | +{ |
774 | + BamfApplication *application; |
775 | + BamfLegacyWindowTest *lwin; |
776 | + BamfWindow *win; |
777 | + |
778 | + application = bamf_application_new (); |
779 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
780 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
781 | + |
782 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
783 | + bamf_legacy_window_test_set_name (lwin, "New Window Name"); |
784 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "New Window Name"); |
785 | + |
786 | + bamf_legacy_window_test_set_name (lwin, "even-new-name"); |
787 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "even-new-name"); |
788 | + |
789 | + g_object_unref (lwin); |
790 | + g_object_unref (win); |
791 | + g_object_unref (application); |
792 | +} |
793 | + |
794 | +static void |
795 | +test_app_main_child_multiple_children (void) |
796 | +{ |
797 | + BamfApplication *application; |
798 | + BamfLegacyWindowTest *lwin; |
799 | + BamfWindow *win1; |
800 | + GList *wins = NULL; |
801 | + GList *lwins = NULL; |
802 | + int i; |
803 | + |
804 | + application = bamf_application_new (); |
805 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
806 | + win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
807 | + g_object_unref (lwin); |
808 | + |
809 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win1)); |
810 | + |
811 | + for (i = 0; i < 10; ++i) |
812 | + { |
813 | + lwin = bamf_legacy_window_test_new (i, "other-window", "", "execution-binary"); |
814 | + lwins = g_list_prepend (lwins, lwin); |
815 | + wins = g_list_prepend (wins, bamf_window_new (BAMF_LEGACY_WINDOW (lwin))); |
816 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (wins->data)); |
817 | + |
818 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1)); |
819 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window"); |
820 | + g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon"); |
821 | + } |
822 | + |
823 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1)); |
824 | + |
825 | + g_object_unref (win1); |
826 | + g_object_unref (application); |
827 | + g_list_free_full (wins, g_object_unref); |
828 | + g_list_free_full (lwins, g_object_unref); |
829 | +} |
830 | + |
831 | +static void |
832 | +test_app_main_child_normal_priority (void) |
833 | +{ |
834 | + BamfApplication *application; |
835 | + BamfLegacyWindowTest *lwin; |
836 | + BamfWindow *dialog, *win; |
837 | + |
838 | + application = bamf_application_new (); |
839 | + lwin = bamf_legacy_window_test_new (10, "dialog", "python", "execution-binary"); |
840 | + lwin->window_type = BAMF_WINDOW_DIALOG; |
841 | + dialog = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
842 | + g_object_unref (lwin); |
843 | + |
844 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (dialog)); |
845 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (dialog)); |
846 | + |
847 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "dialog"); |
848 | + g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "python"); |
849 | + |
850 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
851 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
852 | + g_object_unref (lwin); |
853 | + |
854 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
855 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win)); |
856 | + |
857 | + g_assert_cmpstr (bamf_view_get_name (BAMF_VIEW (application)), ==, "window"); |
858 | + g_assert_cmpstr (bamf_view_get_icon (BAMF_VIEW (application)), ==, "test-bamf-icon"); |
859 | + |
860 | + g_object_unref (dialog); |
861 | + g_object_unref (win); |
862 | + g_object_unref (application); |
863 | +} |
864 | + |
865 | +static void |
866 | +test_app_main_child_on_window_removal (void) |
867 | +{ |
868 | + BamfApplication *application; |
869 | + BamfLegacyWindowTest *lwin; |
870 | + BamfWindow *win1, *win2, *win3, *win4, *dialog; |
871 | + |
872 | + application = bamf_application_new (); |
873 | + lwin = bamf_legacy_window_test_new (10, "window1", NULL, "execution-binary"); |
874 | + win1 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
875 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win1)); |
876 | + g_object_unref (lwin); |
877 | + |
878 | + lwin = bamf_legacy_window_test_new (20, "window2", NULL, "execution-binary"); |
879 | + win2 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
880 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win2)); |
881 | + g_object_unref (lwin); |
882 | + |
883 | + lwin = bamf_legacy_window_test_new (21, "dialog", NULL, "execution-binary"); |
884 | + lwin->window_type = BAMF_WINDOW_DIALOG; |
885 | + dialog = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
886 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (dialog)); |
887 | + g_object_unref (lwin); |
888 | + |
889 | + lwin = bamf_legacy_window_test_new (30, "window3", NULL, "execution-binary"); |
890 | + win3 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
891 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win3)); |
892 | + g_object_unref (lwin); |
893 | + |
894 | + lwin = bamf_legacy_window_test_new (40, "window4", NULL, "execution-binary"); |
895 | + win4 = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
896 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win4)); |
897 | + g_object_unref (lwin); |
898 | + |
899 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1)); |
900 | + |
901 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win4)); |
902 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win1)); |
903 | + |
904 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win1)); |
905 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win2)); |
906 | + |
907 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win2)); |
908 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win3)); |
909 | + |
910 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win3)); |
911 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (dialog)); |
912 | + |
913 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (dialog)); |
914 | + g_assert (!bamf_application_get_main_child (application)); |
915 | + |
916 | + g_object_unref (win1); |
917 | + g_object_unref (win2); |
918 | + g_object_unref (win3); |
919 | + g_object_unref (win4); |
920 | + g_object_unref (dialog); |
921 | + g_object_unref (application); |
922 | +} |
923 | + |
924 | +static void |
925 | +test_app_main_child_on_window_replace_on_removal (void) |
926 | +{ |
927 | + BamfApplication *application; |
928 | + BamfLegacyWindowTest *lwin; |
929 | + BamfWindow *win; |
930 | + |
931 | + application = bamf_application_new (); |
932 | + lwin = bamf_legacy_window_test_new (20, "window", "test-bamf-icon", "execution-binary"); |
933 | + win = bamf_window_new (BAMF_LEGACY_WINDOW (lwin)); |
934 | + |
935 | + bamf_view_add_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
936 | + g_assert (bamf_application_get_main_child (application) == BAMF_VIEW (win)); |
937 | + bamf_view_remove_child (BAMF_VIEW (application), BAMF_VIEW (win)); |
938 | + g_assert (!bamf_application_get_main_child (application)); |
939 | + bamf_legacy_window_test_set_name (lwin, "don't crash here!"); |
940 | + |
941 | + g_object_unref (lwin); |
942 | + g_object_unref (win); |
943 | + g_object_unref (application); |
944 | } |
945 | |
946 | /* Initialize test suite */ |
947 | @@ -789,6 +1108,9 @@ |
948 | gdbus_connection = connection; |
949 | |
950 | g_test_add_func (DOMAIN"/Allocation", test_allocation); |
951 | + g_test_add_func (DOMAIN"/Type", test_type); |
952 | + g_test_add_func (DOMAIN"/Type/Set", test_type_set); |
953 | + g_test_add_func (DOMAIN"/Type/Set/Invalid", test_type_set_invalid); |
954 | g_test_add_func (DOMAIN"/DesktopFile", test_desktop_file); |
955 | g_test_add_func (DOMAIN"/DesktopFile/Icon", test_desktop_icon); |
956 | g_test_add_func (DOMAIN"/DesktopFile/Icon/Empty", test_desktop_icon_empty); |
957 | @@ -797,12 +1119,22 @@ |
958 | g_test_add_func (DOMAIN"/DesktopFile/Icon/FullPath/Invalid", test_icon_full_path_invalid); |
959 | g_test_add_func (DOMAIN"/DesktopFile/MimeTypes/Valid", test_get_mime_types); |
960 | g_test_add_func (DOMAIN"/DesktopFile/MimeTypes/None", test_get_mime_types_none); |
961 | + g_test_add_func (DOMAIN"/DesktopFile/MainChild", test_desktop_app_main_child); |
962 | + g_test_add_func (DOMAIN"/DesktopFile/MainChild/NotMatchEmblems", test_desktop_app_main_child_doesnt_match_emblems); |
963 | + g_test_add_func (DOMAIN"/DesktopFile/MainChild/NotUpdatesEmblems", test_desktop_app_main_child_doesnt_update_emblems); |
964 | g_test_add_func (DOMAIN"/DesktopLess/Icon/ClassName", test_icon_class_name); |
965 | g_test_add_func (DOMAIN"/DesktopLess/Icon/Exec", test_icon_exec_string); |
966 | g_test_add_func (DOMAIN"/DesktopLess/Icon/Embedded", test_icon_embedded); |
967 | g_test_add_func (DOMAIN"/DesktopLess/Icon/Priority", test_icon_priority); |
968 | g_test_add_func (DOMAIN"/DesktopLess/Icon/Generic/Class", test_icon_generic_class); |
969 | g_test_add_func (DOMAIN"/DesktopLess/Icon/Generic/Exec", test_icon_generic_exec); |
970 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild", test_app_main_child); |
971 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/MatchesEmblems", test_app_main_child_matches_emblems); |
972 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/UpdatesEmblems", test_app_main_child_updates_emblems); |
973 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/MultipleChildren", test_app_main_child_multiple_children); |
974 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/NormalPriority", test_app_main_child_normal_priority); |
975 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/Removal", test_app_main_child_on_window_removal); |
976 | + g_test_add_func (DOMAIN"/DesktopLess/MainChild/ReplaceOnRemoval", test_app_main_child_on_window_replace_on_removal); |
977 | g_test_add_func (DOMAIN"/ManagesXid", test_manages_xid); |
978 | g_test_add_func (DOMAIN"/GetWindow", test_get_window); |
979 | g_test_add_func (DOMAIN"/Xids", test_get_xids); |
980 | |
981 | === modified file 'tests/bamfdaemon/test-bamf.c' |
982 | --- tests/bamfdaemon/test-bamf.c 2013-06-21 20:58:53 +0000 |
983 | +++ tests/bamfdaemon/test-bamf.c 2013-07-16 16:30:44 +0000 |
984 | @@ -34,6 +34,20 @@ |
985 | |
986 | static int result = 1; |
987 | |
988 | +static gboolean |
989 | +not_fatal_log_handler (const gchar *log_domain, GLogLevelFlags log_level, |
990 | + const gchar *message, gpointer user_data) |
991 | +{ |
992 | + // Don't crash if used |
993 | + return FALSE; |
994 | +} |
995 | + |
996 | +void |
997 | +ignore_fatal_errors (void) |
998 | +{ |
999 | + g_test_log_set_fatal_handler (not_fatal_log_handler, NULL); |
1000 | +} |
1001 | + |
1002 | static void |
1003 | on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer data) |
1004 | { |
PASSED: Continuous integration, rev:609 jenkins. qa.ubuntu. com/job/ bamf-ci/ 72/ jenkins. qa.ubuntu. com/job/ bamf-saucy- amd64-ci/ 53 jenkins. qa.ubuntu. com/job/ bamf-saucy- armhf-ci/ 54
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ bamf-ci/ 72/rebuild
http://