Merge lp:~3v1n0/bamf/javaws-matching-0.2 into lp:bamf/0.2

Proposed by Marco Trevisan (Treviño) on 2013-01-10
Status: Merged
Approved by: Brandon Schaefer on 2013-01-10
Approved revision: 495
Merged at revision: 489
Proposed branch: lp:~3v1n0/bamf/javaws-matching-0.2
Merge into: lp:bamf/0.2
Diff against target: 1011 lines (+448/-211)
9 files modified
src/bamf-legacy-screen.c (+8/-27)
src/bamf-legacy-window.c (+2/-2)
src/bamf-matcher-private.h (+1/-0)
src/bamf-matcher.c (+193/-182)
tests/bamfdaemon/Makefile.am (+1/-0)
tests/bamfdaemon/data/gnome-control-center.desktop (+9/-0)
tests/bamfdaemon/data/gnome-display-panel.desktop (+10/-0)
tests/bamfdaemon/data/gnome-mouse-panel.desktop (+10/-0)
tests/bamfdaemon/test-matcher.c (+214/-0)
To merge this branch: bzr merge lp:~3v1n0/bamf/javaws-matching-0.2
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) 2013-01-10 Approve on 2013-01-10
Review via email: mp+142619@code.launchpad.net

Commit message

BamfMatcher: Don't associate .desktopless applications with different exec string, fix JavaWS apps

Description of the change

Don't associate to the similar application, windows that have different execution path. Also add some rules to fix Java Web Start applications matching.

To post a comment you must log in.
Brandon Schaefer (brandontschaefer) wrote :

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bamf-legacy-screen.c'
--- src/bamf-legacy-screen.c 2012-07-30 03:00:43 +0000
+++ src/bamf-legacy-screen.c 2013-01-10 00:14:24 +0000
@@ -210,7 +210,6 @@
210 BamfLegacyScreen *self;210 BamfLegacyScreen *self;
211 GList *l;211 GList *l;
212 guint xid_a, xid_b;212 guint xid_a, xid_b;
213 guint idx_a, idx_b;
214213
215 g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (data), 1);214 g_return_val_if_fail (BAMF_IS_LEGACY_SCREEN (data), 1);
216 self = BAMF_LEGACY_SCREEN (data);215 self = BAMF_LEGACY_SCREEN (data);
@@ -218,36 +217,18 @@
218 xid_a = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (a));217 xid_a = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (a));
219 xid_b = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (b));218 xid_b = bamf_legacy_window_get_xid (BAMF_LEGACY_WINDOW (b));
220219
221 gboolean idx_a_found = FALSE;
222 gboolean idx_b_found = FALSE;
223 idx_a = 0;
224 idx_b = 0;
225
226 for (l = wnck_screen_get_windows_stacked (self->priv->legacy_screen); l; l = l->next)220 for (l = wnck_screen_get_windows_stacked (self->priv->legacy_screen); l; l = l->next)
227 {221 {
228 gulong legacy_xid = wnck_window_get_xid (WNCK_WINDOW (l->data));222 gulong legacy_xid = wnck_window_get_xid (WNCK_WINDOW (l->data));
229223
230 if (!idx_a_found)224 if (legacy_xid == xid_a)
231 {225 return -1;
232 if (xid_a != legacy_xid)226
233 idx_a++;227 if (legacy_xid == xid_b)
234 else228 return 1;
235 idx_a_found = TRUE;
236 }
237
238 if (!idx_b_found)
239 {
240 if (xid_b != legacy_xid)
241 idx_b++;
242 else
243 idx_b_found = TRUE;
244 }
245
246 if (idx_a_found && idx_b_found)
247 break;
248 }229 }
249230
250 return (idx_a < idx_b) ? -1 : 1;231 return 0;
251}232}
252233
253static void234static void
@@ -300,11 +281,11 @@
300 }281 }
301 }282 }
302283
303 WnckWindow *legacy_window = wnck_window_get(xid);284 WnckWindow *legacy_window = wnck_window_get (xid);
304285
305 if (WNCK_IS_WINDOW (legacy_window))286 if (WNCK_IS_WINDOW (legacy_window))
306 {287 {
307 handle_window_opened(NULL, legacy_window, self);288 handle_window_opened (NULL, legacy_window, self);
308 }289 }
309}290}
310291
311292
=== modified file 'src/bamf-legacy-window.c'
--- src/bamf-legacy-window.c 2012-10-10 17:36:21 +0000
+++ src/bamf-legacy-window.c 2013-01-10 00:14:24 +0000
@@ -498,9 +498,9 @@
498 guint xid = bamf_legacy_window_get_xid (self);498 guint xid = bamf_legacy_window_get_xid (self);
499499
500 /* Adding a weak ref to this object, causes to get notified after the object500 /* Adding a weak ref to this object, causes to get notified after the object
501 * destruction, so once this BamfLegacyWindow has been closed and drestroyed501 * destruction, so once this BamfLegacyWindow has been closed and destroyed
502 * the handle_destroy_notify() function will be called, and that will502 * the handle_destroy_notify() function will be called, and that will
503 * provide to iniject another window like this one to the BamfLegacyScreen */503 * provide to inject another window like this one to the BamfLegacyScreen */
504 g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify,504 g_object_weak_ref (G_OBJECT (self), (GWeakNotify) handle_destroy_notify,
505 GUINT_TO_POINTER (xid));505 GUINT_TO_POINTER (xid));
506506
507507
=== modified file 'src/bamf-matcher-private.h'
--- src/bamf-matcher-private.h 2012-07-27 18:38:22 +0000
+++ src/bamf-matcher-private.h 2013-01-10 00:14:24 +0000
@@ -46,5 +46,6 @@
4646
47BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file);47BamfApplication * bamf_matcher_get_application_by_desktop_file (BamfMatcher *self, const char *desktop_file);
48BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid);48BamfApplication * bamf_matcher_get_application_by_xid (BamfMatcher *self, guint xid);
49char * bamf_matcher_get_trimmed_exec (BamfMatcher *self, const char *exec);
4950
50#endif51#endif
5152
=== modified file 'src/bamf-matcher.c'
--- src/bamf-matcher.c 2012-10-10 17:36:21 +0000
+++ src/bamf-matcher.c 2013-01-10 00:14:24 +0000
@@ -48,6 +48,22 @@
48static BamfMatcher *static_matcher;48static BamfMatcher *static_matcher;
49static guint matcher_signals[LAST_SIGNAL] = { 0 };49static guint matcher_signals[LAST_SIGNAL] = { 0 };
5050
51// Prefixes to be ignored in exec strings
52const gchar* EXEC_BAD_PREFIXES[] =
53{
54 "^gksu(do)?$", "^sudo$", "^su-to-root$", "^amdxdg-su$", "^java(ws)?$",
55 "^mono$", "^ruby$", "^padsp$", "^aoss$", "^python(\\d.\\d)?$", "^(ba)?sh$",
56 "^perl$", "^env$", "^xdg-open$",
57 /* javaws strings: */ "^net\\.sourceforge\\.jnlp\\.runtime\\.Boot$", "^rt.jar$"
58};
59
60// Prefixes that must be considered starting point of exec strings
61const gchar* EXEC_GOOD_PREFIXES[] =
62{
63 "^gnome-control-center$", "^libreoffice$", "^ooffice$", "^wine$", "^steam$",
64 "^sol$"
65};
66
51static void67static void
52on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher)68on_view_active_changed (BamfView *view, gboolean active, BamfMatcher *matcher)
53{69{
@@ -211,7 +227,8 @@
211 return FALSE;227 return FALSE;
212}228}
213229
214static void bamf_matcher_prepare_path_change (BamfMatcher *self, const gchar *desktop_file, ViewChangeType change_type)230static void
231bamf_matcher_prepare_path_change (BamfMatcher *self, const gchar *desktop_file, ViewChangeType change_type)
215{232{
216 BamfMatcherPrivate *priv;233 BamfMatcherPrivate *priv;
217 BamfApplication *app;234 BamfApplication *app;
@@ -248,12 +265,6 @@
248}265}
249266
250static void267static void
251on_view_closed (BamfView *view, BamfMatcher *self)
252{
253 bamf_matcher_unregister_view (self, view);
254}
255
256static void
257bamf_matcher_register_view_stealing_ref (BamfMatcher *self, BamfView *view)268bamf_matcher_register_view_stealing_ref (BamfMatcher *self, BamfView *view)
258{269{
259 const char *path, *type;270 const char *path, *type;
@@ -264,8 +275,8 @@
264 path = bamf_view_export_on_bus (view, connection);275 path = bamf_view_export_on_bus (view, connection);
265 type = bamf_view_get_view_type (view);276 type = bamf_view_get_view_type (view);
266277
267 g_signal_connect (G_OBJECT (view), "closed-internal",278 g_signal_connect_swapped (G_OBJECT (view), "closed-internal",
268 (GCallback) on_view_closed, self);279 (GCallback) bamf_matcher_unregister_view, self);
269 g_signal_connect (G_OBJECT (view), "active-changed",280 g_signal_connect (G_OBJECT (view), "active-changed",
270 (GCallback) on_view_active_changed, self);281 (GCallback) on_view_active_changed, self);
271282
@@ -296,7 +307,7 @@
296307
297 g_signal_emit_by_name (self, "view-closed", path, type);308 g_signal_emit_by_name (self, "view-closed", path, type);
298309
299 g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_closed, self);310 g_signal_handlers_disconnect_by_func (G_OBJECT (view), bamf_matcher_unregister_view, self);
300 g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_active_changed, self);311 g_signal_handlers_disconnect_by_func (G_OBJECT (view), on_view_active_changed, self);
301312
302 if (BAMF_IS_APPLICATION (view))313 if (BAMF_IS_APPLICATION (view))
@@ -348,7 +359,7 @@
348 else if (g_str_has_suffix (name, "LibreOffice Calc"))359 else if (g_str_has_suffix (name, "LibreOffice Calc"))
349 {360 {
350 binary = "libreoffice";361 binary = "libreoffice";
351 parameter = "calc";362 parameter = "calc";
352 }363 }
353 else if (g_str_has_suffix (name, "LibreOffice Impress"))364 else if (g_str_has_suffix (name, "LibreOffice Impress"))
354 {365 {
@@ -466,60 +477,72 @@
466 if (!binary)477 if (!binary)
467 return NULL;478 return NULL;
468479
469 const char *sufix = NULL;480 GList *l = NULL;
470481
471 if (g_strcmp0 (binary, "libreoffice") == 0)482 if (parameter)
472 sufix = " %U";
473 else if (g_strcmp0 (binary, "ooffice") == 0)
474 sufix = " %F";
475
476 GList *l;
477 if (!parameter)
478 exec = g_strconcat (binary, sufix, NULL);
479 else
480 exec = g_strconcat (binary, " --", parameter, sufix, NULL);
481
482 l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
483 g_free (exec);
484
485 if (!l && parameter)
486 {483 {
487 exec = g_strconcat (binary, " -", parameter, sufix, NULL);484 exec = g_strconcat (binary, " --", parameter, NULL);
488
489 l = g_hash_table_lookup (self->priv->desktop_file_table, exec);485 l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
490 g_free (exec);486 g_free (exec);
487
488 if (!l)
489 {
490 exec = g_strconcat (binary, " -", parameter, NULL);
491 l = g_hash_table_lookup (self->priv->desktop_file_table, exec);
492 g_free (exec);
493
494 if (!l)
495 {
496 exec = g_strconcat (binary, "-", parameter, NULL);
497 l = g_hash_table_lookup (self->priv->desktop_id_table, exec);
498 g_free (exec);
499 }
500 }
501 }
502 else
503 {
504 l = g_hash_table_lookup (self->priv->desktop_file_table, binary);
491 }505 }
492506
493 return (l ? (char *) l->data : NULL);507 return (l ? (char *) l->data : NULL);
494}508}
495509
496/* Attempts to return the binary name for a particular execution string */510/* Attempts to return the binary name for a particular execution string */
497static char *511char *
498trim_exec_string (BamfMatcher * self, char * execString)512bamf_matcher_get_trimmed_exec (BamfMatcher * self, const char * exec_string)
499{513{
500 gchar *result = NULL, *exec = NULL, *part = NULL, *tmp = NULL;514 gchar *result = NULL, *part, *tmp;
501 gchar **parts;515 gchar **parts;
502 gint i, j;516 gint i, j, parts_size;
503 gboolean regexFail;517 gboolean bad_prefix;
504 gboolean goodPrefix = FALSE;518 gboolean good_prefix = FALSE;
519 gboolean double_parsed = FALSE;
505 GRegex *regex;520 GRegex *regex;
506521
507 if (!execString || (execString && execString[0] == '\0'))522 if (!exec_string || exec_string[0] == '\0')
508 return NULL;523 return NULL;
509524
510 exec = g_utf8_casefold (execString, -1);525 if (!g_shell_parse_argv (exec_string, &parts_size, &parts, NULL))
511 parts = g_strsplit (exec, " ", 0);526 return g_strdup (exec_string);
512527
513 i = 0;528 for (i = 0; i < parts_size; ++i)
514 while (parts[i] != NULL)
515 {529 {
516 part = parts[i];530 part = parts[i];
531 if (*part == '%' || g_utf8_strrchr (part, -1, '='))
532 continue;
517533
518 if (part[0] != '-')534 if (*part != '-' || good_prefix)
519 {535 {
520 if (goodPrefix)536 if (!result)
521 {537 {
522 gchar *tmp = g_strconcat (result, " ", part, NULL);538 tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR);
539 if (tmp)
540 part = tmp + 1;
541 }
542
543 if (good_prefix)
544 {
545 tmp = g_strconcat (result, " ", part, NULL);
523 g_free (result);546 g_free (result);
524 result = tmp;547 result = tmp;
525 }548 }
@@ -530,113 +553,81 @@
530 regex = g_array_index (self->priv->good_prefixes, GRegex *, j);553 regex = g_array_index (self->priv->good_prefixes, GRegex *, j);
531 if (g_regex_match (regex, part, 0, NULL))554 if (g_regex_match (regex, part, 0, NULL))
532 {555 {
533 goodPrefix = TRUE;556 good_prefix = TRUE;
534 result = g_strdup (part);557 result = g_ascii_strdown (part, -1);
535 break;558 break;
536 }559 }
537 }560 }
538 }561
539562 if (good_prefix)
540 if (!goodPrefix)563 continue;
541 {564
542 tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR);565 bad_prefix = FALSE;
543 if (tmp)
544 part = tmp + 1;
545
546 regexFail = FALSE;
547 for (j = 0; j < self->priv->bad_prefixes->len; j++)566 for (j = 0; j < self->priv->bad_prefixes->len; j++)
548 {567 {
549 regex = g_array_index (self->priv->bad_prefixes, GRegex *, j);568 regex = g_array_index (self->priv->bad_prefixes, GRegex *, j);
550 if (g_regex_match (regex, part, 0, NULL))569 if (g_regex_match (regex, part, 0, NULL))
551 {570 {
552 regexFail = TRUE;571 bad_prefix = TRUE;
553 break;572 break;
554 }573 }
555 }574 }
556575
557 if (!regexFail)576 if (!bad_prefix)
558 {577 {
559 result = g_strdup (part);578 if (!double_parsed && g_utf8_strrchr (part, -1, ' '))
579 {
580 /* If the current exec_string has an empty char,
581 * we double check it again to parse scripts:
582 * For example strings like 'sh -c "foo || bar"' */
583 gchar **old_parts = parts;
584
585 if (g_shell_parse_argv (part, &parts_size, &parts, NULL))
586 {
587 // Make the loop to restart!
588 g_strfreev (old_parts);
589 i = -1;
590 continue;
591 }
592
593 double_parsed = TRUE;
594 }
595
596 result = g_ascii_strdown (part, -1);
560 break;597 break;
561 }598 }
562 }599 }
563 }600 }
564 else if (goodPrefix)
565 {
566 break;
567 }
568
569 i++;
570 }601 }
571602
572 if (!result)603 if (!result)
573 {604 {
574 result = g_strdup (execString);605 if (parts_size > 0)
606 {
607 tmp = g_utf8_strrchr (parts[0], -1, G_DIR_SEPARATOR);
608 if (tmp)
609 exec_string = tmp + 1;
610 }
611
612 result = g_strdup (exec_string);
575 }613 }
576 else614 else
577 {615 {
578 tmp = result;616 tmp = result;
579 617
580 regex = g_regex_new ("((\\.|-)bin|\\.py)$", 0, 0, NULL);618 regex = g_regex_new ("(\\.bin|\\.py|\\.pl)$", 0, 0, NULL);
581 result = g_regex_replace_literal (regex, result, -1, 0, "", 0, NULL);619 result = g_regex_replace_literal (regex, result, -1, 0, "", 0, NULL);
582 620
583 g_free (tmp);621 g_free (tmp);
584 g_regex_unref (regex);622 g_regex_unref (regex);
585 }623 }
586624
587 g_free (exec);
588 g_strfreev (parts);625 g_strfreev (parts);
589626
590 return result;627 return result;
591}628}
592629
593static GArray *630static GArray *
594bad_prefix_strings (void)
595{
596 GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *));
597
598 char *str = "^gksu(do)?$";
599 g_array_append_val (arr, str);
600
601 str = "^sudo$";
602 g_array_append_val (arr, str);
603
604 str = "^java$";
605 g_array_append_val (arr, str);
606
607 str = "^mono$";
608 g_array_append_val (arr, str);
609
610 str = "^ruby$";
611 g_array_append_val (arr, str);
612
613 str = "^padsp$";
614 g_array_append_val (arr, str);
615
616 str = "^aoss$";
617 g_array_append_val (arr, str);
618
619 str = "^python(\\d.\\d)?$";
620 g_array_append_val (arr, str);
621
622 str = "^(ba)?sh$";
623 g_array_append_val (arr, str);
624
625 return arr;
626}
627
628static GArray *
629good_prefix_strings (void)
630{
631 GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *));
632
633 char *str = "^gnome-control-center$";
634 g_array_append_val (arr, str);
635
636 return arr;
637}
638
639static GArray *
640pid_parent_tree (BamfMatcher *self, gint pid)631pid_parent_tree (BamfMatcher *self, gint pid)
641{632{
642 BamfMatcherPrivate *priv;633 BamfMatcherPrivate *priv;
@@ -678,15 +669,6 @@
678}669}
679670
680static gboolean671static gboolean
681exec_string_should_be_processed (const char *exec)
682{
683 if (!exec)
684 return TRUE;
685
686 return !g_str_has_prefix (exec, "ooffice") && !g_str_has_prefix (exec, "libreoffice");
687}
688
689static gboolean
690is_desktop_folder_item (const char *desktop_file_path, gssize max_len)672is_desktop_folder_item (const char *desktop_file_path, gssize max_len)
691{673{
692 gsize len;674 gsize len;
@@ -850,18 +832,15 @@
850 return;832 return;
851 }833 }
852834
853 if (exec_string_should_be_processed (exec))835 /**
854 {836 * Set of nasty hacks which should be removed some day. We wish to keep the full exec
855 /**837 * strings so we can do nasty matching hacks later. A very very evil thing indeed. However this
856 * Set of nasty hacks which should be removed some day. We wish to keep the full exec838 * helps hack around applications that run in the same process cross radically different instances.
857 * strings so we can do nasty matching hacks later. A very very evil thing indeed. However this839 * A better solution needs to be thought up, however at this time it is not known.
858 * helps hack around applications that run in the same process cross radically different instances.840 **/
859 * A better solution needs to be thought up, however at this time it is not known.841 char *tmp = bamf_matcher_get_trimmed_exec (self, exec);
860 **/842 g_free (exec);
861 char *tmp = trim_exec_string (self, exec);843 exec = tmp;
862 g_free (exec);
863 exec = tmp;
864 }
865844
866 path = g_path_get_basename (file);845 path = g_path_get_basename (file);
867 desktop_id = g_string_new (path);846 desktop_id = g_string_new (path);
@@ -958,16 +937,12 @@
958 GString *desktop_id;937 GString *desktop_id;
959938
960 gchar **parts = g_strsplit (line, "\t", 3);939 gchar **parts = g_strsplit (line, "\t", 3);
940
941 char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]);
942 g_free (parts[1]);
943 parts[1] = tmp;
961 exec = parts[1];944 exec = parts[1];
962945
963 if (exec_string_should_be_processed (exec))
964 {
965 char *tmp = trim_exec_string (self, exec);
966 g_free (parts[1]);
967 parts[1] = tmp;
968 exec = parts[1];
969 }
970
971 filename = g_build_filename (directory, parts[0], NULL);946 filename = g_build_filename (directory, parts[0], NULL);
972947
973 desktop_id = g_string_new (parts[0]);948 desktop_id = g_string_new (parts[0]);
@@ -1172,7 +1147,7 @@
1172 free_func (l->data);1147 free_func (l->data);
11731148
1174 /* If the target is the first element of the list (and thanks to1149 /* If the target is the first element of the list (and thanks to
1175- * the previous check we're also sure that it's not the only one),1150 * the previous check we're also sure that it's not the only one),
1176 * simply switch it with its follower, not to change the first1151 * simply switch it with its follower, not to change the first
1177 * pointer and the hash table value for key1152 * pointer and the hash table value for key
1178 */1153 */
@@ -1301,15 +1276,25 @@
1301}1276}
13021277
1303static void1278static void
1304bamf_add_new_monitored_directory (BamfMatcher * self, const gchar *directory)1279bamf_matcher_add_new_monitored_directory (BamfMatcher * self, const gchar *directory)
1305{1280{
1306 g_return_if_fail (BAMF_IS_MATCHER (self));1281 g_return_if_fail (BAMF_IS_MATCHER (self));
13071282
1308 GFile *file;1283 GFile *file;
1309 GFileMonitor *monitor;1284 GFileMonitor *monitor;
1285 GError *error = NULL;
13101286
1311 file = g_file_new_for_path (directory);1287 file = g_file_new_for_path (directory);
1312 monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);1288 monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, &error);
1289
1290 if (error)
1291 {
1292 g_warning ("Error monitoring %s: %s\n", directory, error->message);
1293 g_error_free (error);
1294 g_object_unref (file);
1295 return;
1296 }
1297
1313 g_file_monitor_set_rate_limit (monitor, 1000);1298 g_file_monitor_set_rate_limit (monitor, 1000);
1314 g_object_set_data_full (G_OBJECT (monitor), "root", g_strdup (directory), g_free);1299 g_object_set_data_full (G_OBJECT (monitor), "root", g_strdup (directory), g_free);
1315 g_signal_connect (monitor, "changed", (GCallback) on_monitor_changed, self);1300 g_signal_connect (monitor, "changed", (GCallback) on_monitor_changed, self);
@@ -1338,7 +1323,7 @@
1338 if (!g_file_test (directory, G_FILE_TEST_IS_DIR))1323 if (!g_file_test (directory, G_FILE_TEST_IS_DIR))
1339 continue;1324 continue;
13401325
1341 bamf_add_new_monitored_directory (self, directory);1326 bamf_matcher_add_new_monitored_directory (self, directory);
13421327
1343 bamf_file = g_build_filename (directory, "bamf.index", NULL);1328 bamf_file = g_build_filename (directory, "bamf.index", NULL);
13441329
@@ -1492,8 +1477,7 @@
1492 1477
1493 if (exec_string)1478 if (exec_string)
1494 {1479 {
1495 trimmed = trim_exec_string (self, exec_string);1480 trimmed = bamf_matcher_get_trimmed_exec (self, exec_string);
1496
1497 if (trimmed)1481 if (trimmed)
1498 {1482 {
1499 if (trimmed[0] != '\0')1483 if (trimmed[0] != '\0')
@@ -1882,6 +1866,7 @@
1882 /* secondary matching */1866 /* secondary matching */
1883 GList *a;1867 GList *a;
1884 BamfView *view;1868 BamfView *view;
1869
1885 const gchar *app_desktop_class;1870 const gchar *app_desktop_class;
18861871
1887 for (a = self->priv->views; a; a = a->next)1872 for (a = self->priv->views; a; a = a->next)
@@ -1892,10 +1877,41 @@
1892 continue;1877 continue;
18931878
1894 app = BAMF_APPLICATION (view);1879 app = BAMF_APPLICATION (view);
1895 app_desktop_class = bamf_application_get_wmclass (app);
18961880
1897 if (bamf_application_contains_similar_to_window (app, bamf_window))1881 if (bamf_application_contains_similar_to_window (app, bamf_window))
1898 {1882 {
1883 char *exec_string = bamf_legacy_window_get_exec_string (window);
1884 char *trimmed_exec = bamf_matcher_get_trimmed_exec (self, exec_string);
1885 g_free (exec_string);
1886
1887 GList *ll;
1888 gboolean found_exec = FALSE;
1889 for (ll = bamf_view_get_children (BAMF_VIEW (app)); ll && !found_exec; ll = ll->next)
1890 {
1891 if (!BAMF_IS_WINDOW (ll->data))
1892 continue;
1893
1894 BamfLegacyWindow *w = bamf_window_get_window (BAMF_WINDOW (ll->data));
1895 char *wexec = bamf_legacy_window_get_exec_string (w);
1896 char *wtrimmed = bamf_matcher_get_trimmed_exec (self, wexec);
1897 g_free (wexec);
1898
1899 if (g_strcmp0 (trimmed_exec, wtrimmed) == 0)
1900 {
1901 best = BAMF_APPLICATION (view);
1902 found_exec = TRUE;
1903 }
1904
1905 g_free (wtrimmed);
1906 }
1907
1908 g_free (trimmed_exec);
1909
1910 if (!found_exec)
1911 continue;
1912
1913 app_desktop_class = bamf_application_get_wmclass (app);
1914
1899 if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)1915 if (target_class && g_strcmp0 (target_class, app_desktop_class) == 0)
1900 {1916 {
1901 best = app;1917 best = app;
@@ -2068,26 +2084,26 @@
2068get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window)2084get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
2069{2085{
2070 gchar *role;2086 gchar *role;
2071 gchar *exec;
2072 GHashTable *desktopFileTable;
2073 GList *list;2087 GList *list;
20742088
2075 g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);2089 g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
2076 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);2090 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
20772091
2092 list = NULL;
2078 role = bamf_legacy_window_get_hint (window, WM_WINDOW_ROLE);2093 role = bamf_legacy_window_get_hint (window, WM_WINDOW_ROLE);
2079 exec = g_strconcat ("gnome-control-center", (role ? " " : NULL), role, NULL);2094
20802095 if (role)
2081 desktopFileTable = self->priv->desktop_file_table;2096 {
2082 list = g_hash_table_lookup (desktopFileTable, exec);2097 gchar *exec = g_strconcat ("gnome-control-center ", role, NULL);
20832098 list = g_hash_table_lookup (self->priv->desktop_file_table, exec);
2084 if (!list && g_strcmp0 ("gnome-control-center", exec) != 0)2099 g_free (exec);
2085 {2100 g_free (role);
2086 list = g_hash_table_lookup (desktopFileTable, "gnome-control-center");2101 }
2087 }2102
20882103 if (!role || !list)
2089 g_free (exec);2104 {
2090 g_free (role);2105 list = g_hash_table_lookup (self->priv->desktop_id_table, "gnome-control-center");
2106 }
20912107
2092 return (list ? (char *) list->data : NULL);2108 return (list ? (char *) list->data : NULL);
2093}2109}
@@ -2125,7 +2141,8 @@
2125 g_return_if_fail (BAMF_IS_MATCHER (self));2141 g_return_if_fail (BAMF_IS_MATCHER (self));
2126 g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));2142 g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
21272143
2128 if (bamf_legacy_window_get_window_type (window) == BAMF_WINDOW_DESKTOP)2144 BamfWindowType win_type = bamf_legacy_window_get_window_type (window);
2145 if (win_type == BAMF_WINDOW_DESKTOP)
2129 {2146 {
2130 BamfWindow *bamfwindow = bamf_window_new (window);2147 BamfWindow *bamfwindow = bamf_window_new (window);
2131 bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamfwindow));2148 bamf_matcher_register_view_stealing_ref (self, BAMF_VIEW (bamfwindow));
@@ -2135,8 +2152,6 @@
21352152
2136 if (is_open_office_window (self, window))2153 if (is_open_office_window (self, window))
2137 {2154 {
2138 BamfWindowType win_type = bamf_legacy_window_get_window_type (window);
2139
2140 if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR)2155 if (win_type == BAMF_WINDOW_SPLASHSCREEN || win_type == BAMF_WINDOW_TOOLBAR)
2141 {2156 {
2142 return;2157 return;
@@ -2895,34 +2910,29 @@
2895 BamfMatcherPrivate *priv;2910 BamfMatcherPrivate *priv;
2896 BamfLegacyScreen *screen;2911 BamfLegacyScreen *screen;
2897 BamfIndicatorSource *approver;2912 BamfIndicatorSource *approver;
2898 GArray *prefixstrings;
2899 int i;2913 int i;
29002914
2901 priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self);2915 priv = self->priv = BAMF_MATCHER_GET_PRIVATE (self);
29022916
2903 priv->known_pids = g_array_new (FALSE, TRUE, sizeof (gint));2917 priv->known_pids = g_array_new (FALSE, TRUE, sizeof (gint));
2904 priv->bad_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *));2918 priv->bad_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *),
2905 priv->good_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *));2919 G_N_ELEMENTS (EXEC_BAD_PREFIXES));
2920 priv->good_prefixes = g_array_sized_new (FALSE, TRUE, sizeof (GRegex *),
2921 G_N_ELEMENTS (EXEC_GOOD_PREFIXES));
2906 priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal,2922 priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal,
2907 NULL, g_free);2923 NULL, g_free);
29082924
2909 prefixstrings = bad_prefix_strings ();2925 for (i = 0; i < G_N_ELEMENTS (EXEC_BAD_PREFIXES); ++i)
2910 for (i = 0; i < prefixstrings->len; i++)
2911 {2926 {
2912 char *str = g_array_index (prefixstrings, char *, i);2927 GRegex *regex = g_regex_new (EXEC_BAD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL);
2913 GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL);
2914 g_array_append_val (priv->bad_prefixes, regex);2928 g_array_append_val (priv->bad_prefixes, regex);
2915 }2929 }
2916 g_array_free (prefixstrings, TRUE);
29172930
2918 prefixstrings = good_prefix_strings ();2931 for (i = 0; i < G_N_ELEMENTS (EXEC_GOOD_PREFIXES); ++i)
2919 for (i = 0; i < prefixstrings->len; i++)
2920 {2932 {
2921 char *str = g_array_index (prefixstrings, char *, i);2933 GRegex *regex = g_regex_new (EXEC_GOOD_PREFIXES[i], G_REGEX_OPTIMIZE, 0, NULL);
2922 GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL);
2923 g_array_append_val (priv->good_prefixes, regex);2934 g_array_append_val (priv->good_prefixes, regex);
2924 }2935 }
2925 g_array_free (prefixstrings, TRUE);
29262936
2927 create_desktop_file_table (self, &(priv->desktop_file_table),2937 create_desktop_file_table (self, &(priv->desktop_file_table),
2928 &(priv->desktop_id_table),2938 &(priv->desktop_id_table),
@@ -3046,6 +3056,7 @@
3046 g_signal_handlers_disconnect_by_func (G_OBJECT (l->data), 3056 g_signal_handlers_disconnect_by_func (G_OBJECT (l->data),
3047 (GCallback) on_monitor_changed, self);3057 (GCallback) on_monitor_changed, self);
3048 }3058 }
3059
3049 g_list_free_full (priv->monitors, g_object_unref);3060 g_list_free_full (priv->monitors, g_object_unref);
3050 priv->monitors = NULL;3061 priv->monitors = NULL;
30513062
30523063
=== modified file 'tests/bamfdaemon/Makefile.am'
--- tests/bamfdaemon/Makefile.am 2012-11-28 12:16:12 +0000
+++ tests/bamfdaemon/Makefile.am 2013-01-10 00:14:24 +0000
@@ -119,6 +119,7 @@
119 export LOG_PATH=$(LOG_PATH); \119 export LOG_PATH=$(LOG_PATH); \
120 export XVFB_PATH=$(XVFB); \120 export XVFB_PATH=$(XVFB); \
121 export DISPLAY=""; \121 export DISPLAY=""; \
122 export XDG_CURRENT_DESKTOP="Unity"; \
122 source $(XVFB_RUN); \123 source $(XVFB_RUN); \
123 \124 \
124 $(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \125 $(DBUS_LAUNCH) > $(LOG_PATH)/sessionbus.sh; \
125126
=== added file 'tests/bamfdaemon/data/gnome-control-center.desktop'
--- tests/bamfdaemon/data/gnome-control-center.desktop 1970-01-01 00:00:00 +0000
+++ tests/bamfdaemon/data/gnome-control-center.desktop 2013-01-10 00:14:24 +0000
@@ -0,0 +1,9 @@
1[Desktop Entry]
2Name=System Settings
3Icon=preferences-system
4Exec=gnome-control-center --overview
5Terminal=false
6Type=Application
7StartupNotify=true
8Categories=GNOME;GTK;System;
9OnlyShowIn=GNOME;Unity;
010
=== added file 'tests/bamfdaemon/data/gnome-display-panel.desktop'
--- tests/bamfdaemon/data/gnome-display-panel.desktop 1970-01-01 00:00:00 +0000
+++ tests/bamfdaemon/data/gnome-display-panel.desktop 2013-01-10 00:14:24 +0000
@@ -0,0 +1,10 @@
1[Desktop Entry]
2Name=Displays
3Comment=Change resolution and position of monitors and projectors
4Exec=gnome-control-center display
5Icon=preferences-desktop-display
6Terminal=false
7Type=Application
8StartupNotify=true
9Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;
10OnlyShowIn=GNOME;Unity;
011
=== added file 'tests/bamfdaemon/data/gnome-mouse-panel.desktop'
--- tests/bamfdaemon/data/gnome-mouse-panel.desktop 1970-01-01 00:00:00 +0000
+++ tests/bamfdaemon/data/gnome-mouse-panel.desktop 2013-01-10 00:14:24 +0000
@@ -0,0 +1,10 @@
1[Desktop Entry]
2Name=Mouse and Touchpad
3Comment=Set your mouse and touchpad preferences
4Exec=gnome-control-center mouse
5Icon=input-mouse
6Terminal=false
7Type=Application
8StartupNotify=true
9Categories=GNOME;GTK;Settings;HardwareSettings;X-GNOME-Settings-Panel;
10OnlyShowIn=GNOME;Unity;
011
=== modified file 'tests/bamfdaemon/test-matcher.c'
--- tests/bamfdaemon/test-matcher.c 2012-10-10 17:36:21 +0000
+++ tests/bamfdaemon/test-matcher.c 2013-01-10 00:14:24 +0000
@@ -32,7 +32,10 @@
32static void test_match_desktopless_application (void);32static void test_match_desktopless_application (void);
33static void test_match_desktop_application (void);33static void test_match_desktop_application (void);
34static void test_match_libreoffice_windows (void);34static void test_match_libreoffice_windows (void);
35static void test_match_gnome_control_center_panels (void);
36static void test_match_javaws_windows (void);
35static void test_new_desktop_matches_unmatched_windows (void);37static void test_new_desktop_matches_unmatched_windows (void);
38static void test_trim_exec_string (void);
3639
37static GDBusConnection *gdbus_connection = NULL;40static GDBusConnection *gdbus_connection = NULL;
3841
@@ -51,7 +54,10 @@
51 g_test_add_func (DOMAIN"/Matching/Application/DesktopLess", test_match_desktopless_application);54 g_test_add_func (DOMAIN"/Matching/Application/DesktopLess", test_match_desktopless_application);
52 g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);55 g_test_add_func (DOMAIN"/Matching/Application/Desktop", test_match_desktop_application);
53 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);56 g_test_add_func (DOMAIN"/Matching/Application/LibreOffice", test_match_libreoffice_windows);
57 g_test_add_func (DOMAIN"/Matching/Application/GnomeControlCenter", test_match_gnome_control_center_panels);
58 g_test_add_func (DOMAIN"/Matching/Application/JavaWebStart", test_match_javaws_windows);
54 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);59 g_test_add_func (DOMAIN"/Matching/Windows/UnmatchedOnNewDesktop", test_new_desktop_matches_unmatched_windows);
60 g_test_add_func (DOMAIN"/ExecStringTrimming", test_trim_exec_string);
55}61}
5662
57static void63static void
@@ -480,3 +486,211 @@
480 g_object_unref (screen);486 g_object_unref (screen);
481}487}
482488
489static void
490test_match_gnome_control_center_panels (void)
491{
492 BamfMatcher *matcher;
493 BamfWindow *window;
494 BamfLegacyScreen *screen;
495 BamfLegacyWindowTest *test_win;
496 BamfApplication *app;
497 char *hint;
498
499 screen = bamf_legacy_screen_get_default ();
500 matcher = bamf_matcher_get_default ();
501 guint xid = g_random_int ();
502 const char *exec = "gnome-control-center";
503 const char *class_name = "Gnome-control-center";
504 const char *class_instance = "gnome-control-center";
505
506 cleanup_matcher_tables (matcher);
507 export_matcher_on_bus (matcher);
508
509 bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop");
510 bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop");
511 bamf_matcher_load_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop");
512
513 test_win = bamf_legacy_window_test_new (xid, "System Settings", NULL, exec);
514 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
515 bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, NULL);
516 _bamf_legacy_screen_open_test_window (screen, test_win);
517
518 hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
519 g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-control-center.desktop");
520 g_free (hint);
521 app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop");
522 g_assert (find_window_in_app (app, BAMF_LEGACY_WINDOW (test_win)));
523
524 bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "display");
525 bamf_legacy_window_test_set_name (test_win, "Displays");
526 g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop"));
527 app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop");
528 g_assert (app);
529 window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
530 test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
531 hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
532 g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-display-panel.desktop");
533 g_free (hint);
534
535 bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "mouse");
536 bamf_legacy_window_test_set_name (test_win, "Mouse and Touchpad");
537 g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-display-panel.desktop"));
538 app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop");
539 g_assert (app);
540 window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
541 test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
542 hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
543 g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-mouse-panel.desktop");
544 g_free (hint);
545
546 bamf_legacy_window_set_hint (BAMF_LEGACY_WINDOW (test_win), WM_WINDOW_ROLE, "invalid-role");
547 bamf_legacy_window_test_set_name (test_win, "Invalid Panel");
548 g_assert (!bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-mouse-panel.desktop"));
549 app = bamf_matcher_get_application_by_desktop_file (matcher, DATA_DIR"/gnome-control-center.desktop");
550 g_assert (app);
551 window = BAMF_WINDOW (bamf_view_get_children (BAMF_VIEW (app))->data);
552 test_win = BAMF_LEGACY_WINDOW_TEST (bamf_window_get_window (window));
553 hint = bamf_legacy_window_get_hint (BAMF_LEGACY_WINDOW (test_win), _NET_WM_DESKTOP_FILE);
554 g_assert_cmpstr (hint, ==, DATA_DIR"/gnome-control-center.desktop");
555 g_free (hint);
556
557 g_object_unref (matcher);
558 g_object_unref (screen);
559}
560
561static void
562test_match_javaws_windows (void)
563{
564 BamfMatcher *matcher;
565 BamfLegacyScreen *screen;
566 BamfLegacyWindowTest *test_win;
567 BamfApplication *app1, *app2, *app3;
568 GList *app_children;
569
570 screen = bamf_legacy_screen_get_default ();
571 matcher = bamf_matcher_get_default ();
572 const char *exec_prefix = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
573 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
574 "-Xms8m -Djava.security.manager " \
575 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
576 "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
577 "-Dicedtea-web.bin.name=javaws " \
578 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
579 "net.sourceforge.jnlp.runtime.Boot";
580 const char *class_name = "sun-awt-X11-XFramePeer";
581 const char *class_instance = "net-sourceforge-jnlp-runtime-Boot";
582
583 cleanup_matcher_tables (matcher);
584 export_matcher_on_bus (matcher);
585
586 guint xid = g_random_int ();
587 char *exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
588 test_win = bamf_legacy_window_test_new (xid, "Notepad", NULL, exec);
589 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
590 _bamf_legacy_screen_open_test_window (screen, test_win);
591 g_free (exec);
592 app1 = bamf_matcher_get_application_by_xid (matcher, xid);
593 g_assert (BAMF_IS_APPLICATION (app1));
594 app_children = bamf_view_get_children (BAMF_VIEW (app1));
595 g_assert_cmpuint (g_list_length (app_children), ==, 1);
596 g_assert (find_window_in_app (app1, BAMF_LEGACY_WINDOW (test_win)));
597
598 xid = g_random_int ();
599 exec = g_strconcat (exec_prefix, " Draw.jnlp", NULL);
600 test_win = bamf_legacy_window_test_new (xid, "Draw", NULL, exec);
601 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
602 _bamf_legacy_screen_open_test_window (screen, test_win);
603 g_free (exec);
604 app2 = bamf_matcher_get_application_by_xid (matcher, xid);
605 g_assert (BAMF_IS_APPLICATION (app2));
606 g_assert (app1 != app2);
607 app_children = bamf_view_get_children (BAMF_VIEW (app2));
608 g_assert_cmpuint (g_list_length (app_children), ==, 1);
609 g_assert (find_window_in_app (app2, BAMF_LEGACY_WINDOW (test_win)));
610
611 xid = g_random_int ();
612 exec = g_strconcat (exec_prefix, " Notepad.jnlp", NULL);
613 test_win = bamf_legacy_window_test_new (xid, "Notepad Subwin", NULL, exec);
614 bamf_legacy_window_test_set_wmclass (test_win, class_name, class_instance);
615 _bamf_legacy_screen_open_test_window (screen, test_win);
616 g_free (exec);
617 app3 = bamf_matcher_get_application_by_xid (matcher, xid);
618 g_assert (app3 == app1);
619 g_assert (BAMF_IS_APPLICATION (app3));
620 app_children = bamf_view_get_children (BAMF_VIEW (app3));
621 g_assert_cmpuint (g_list_length (app_children), ==, 2);
622 g_assert (find_window_in_app (app3, BAMF_LEGACY_WINDOW (test_win)));
623
624 g_object_unref (matcher);
625 g_object_unref (screen);
626}
627
628static void
629test_trim_exec_string (void)
630{
631 BamfMatcher *matcher;
632 char *trimmed;
633
634 matcher = bamf_matcher_get_default ();
635
636 // Bad prefixes
637 trimmed = bamf_matcher_get_trimmed_exec (matcher, "gksudo bad-prefix-bin");
638 g_assert_cmpstr (trimmed, ==, "bad-prefix-bin");
639 g_free (trimmed);
640
641 trimmed = bamf_matcher_get_trimmed_exec (matcher, "sudo --opt val=X /usr/bin/bad-prefix-bin");
642 g_assert_cmpstr (trimmed, ==, "bad-prefix-bin");
643 g_free (trimmed);
644
645 trimmed = bamf_matcher_get_trimmed_exec (matcher, "python2.7 /home/foo/bad-prefix-script.py");
646 g_assert_cmpstr (trimmed, ==, "bad-prefix-script");
647 g_free (trimmed);
648
649 trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python3.1");
650 g_assert_cmpstr (trimmed, ==, "python3.1");
651 g_free (trimmed);
652
653 trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/python %u --option val=/path");
654 g_assert_cmpstr (trimmed, ==, "python");
655 g_free (trimmed);
656
657 trimmed = bamf_matcher_get_trimmed_exec (matcher, "sh -c \"binary --option --value %U || exec binary\"");
658 g_assert_cmpstr (trimmed, ==, "binary");
659 g_free (trimmed);
660
661 // Good prefixes
662 trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/libreoffice --writer %U");
663 g_assert_cmpstr (trimmed, ==, "libreoffice --writer");
664 g_free (trimmed);
665
666 trimmed = bamf_matcher_get_trimmed_exec (matcher, "/usr/bin/gnome-control-center");
667 g_assert_cmpstr (trimmed, ==, "gnome-control-center");
668 g_free (trimmed);
669
670 trimmed = bamf_matcher_get_trimmed_exec (matcher, "gnome-control-center foo-panel");
671 g_assert_cmpstr (trimmed, ==, "gnome-control-center foo-panel");
672 g_free (trimmed);
673
674 // Other exec strings
675 trimmed = bamf_matcher_get_trimmed_exec (matcher, "env FOOVAR=\"bar\" myprog");
676 g_assert_cmpstr (trimmed, ==, "myprog");
677 g_free (trimmed);
678
679 trimmed = bamf_matcher_get_trimmed_exec (matcher, "/opt/path/bin/myprog --option %U --foo=daa");
680 g_assert_cmpstr (trimmed, ==, "myprog");
681 g_free (trimmed);
682
683 const char *exec = "/usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java " \
684 "-Xbootclasspath/a:/usr/share/icedtea-web/netx.jar " \
685 "-Xms8m -Djava.security.manager " \
686 "-Djava.security.policy=/etc/icedtea-web/javaws.policy " \
687 "-classpath /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/rt.jar " \
688 "-Dicedtea-web.bin.name=javaws " \
689 "-Dicedtea-web.bin.location=/usr/bin/javaws "\
690 "net.sourceforge.jnlp.runtime.Boot Notepad.jnlp";
691 trimmed = bamf_matcher_get_trimmed_exec (matcher, exec);
692 g_assert_cmpstr (trimmed, ==, "notepad.jnlp");
693 g_free (trimmed);
694
695 g_object_unref (matcher);
696}

Subscribers

People subscribed via source and target branches