Package list cinnamon-menus / ce38c7b
libmenu: Remove support for legacy-dirs Those directories have been deprecated for over a decade and GIO's GDesktopAppInfo API already ignores them ... It's time to let go, simply ignore any <LegacyKDEDirs> and <LegacyDir> elements in menus. https://bugzilla.gnome.org/show_bug.cgi?id=760900 Florian Müllner authored 6 years ago Clement Lefebvre committed 4 years ago
7 changed file(s) with 8 addition(s) and 387 deletion(s). Raw diff Collapse all Expand all
44
55 <Name>Applications</Name>
66 <Directory>X-GNOME-Menu-Applications.directory</Directory>
7
8 <!-- Scan legacy dirs first, as later items take priority -->
9 <KDELegacyDirs/>
10 <LegacyDir>/etc/X11/applnk</LegacyDir>
11 <LegacyDir>/usr/share/gnome/apps</LegacyDir>
127
138 <!-- Read standard .directory and .desktop file locations -->
149 <DefaultAppDirs/>
679679 return FALSE;
680680 }
681681
682 void
683 desktop_entry_add_legacy_category (DesktopEntry *entry)
684 {
685 GQuark *categories;
686 int i;
687 DesktopEntryDesktop *desktop_entry;
688
689 g_return_if_fail (entry->type == DESKTOP_ENTRY_DESKTOP);
690
691 desktop_entry = (DesktopEntryDesktop*) entry;
692
693 menu_verbose ("Adding Legacy category to \"%s\"\n",
694 entry->basename);
695
696 if (desktop_entry->categories != NULL)
697 {
698 i = 0;
699 for (; desktop_entry->categories[i]; i++);
700
701 categories = g_new0 (GQuark, i + 2);
702
703 i = 0;
704 for (; desktop_entry->categories[i]; i++)
705 categories[i] = desktop_entry->categories[i];
706 }
707 else
708 {
709 categories = g_new0 (GQuark, 2);
710 i = 0;
711 }
712
713 categories[i] = g_quark_from_string ("Legacy");
714
715 g_free (desktop_entry->categories);
716 desktop_entry->categories = categories;
717 }
718
719682 /*
720683 * Entry sets
721684 */
6464 gboolean desktop_entry_has_category (DesktopEntry *entry,
6565 const char *category);
6666
67 void desktop_entry_add_legacy_category (DesktopEntry *src);
68
6967
7068 typedef struct DesktopEntrySet DesktopEntrySet;
7169
3535 struct EntryDirectory
3636 {
3737 CachedDir *dir;
38 char *legacy_prefix;
3938
4039 guint entry_type : 2;
41 guint is_legacy : 1;
4240 guint refcount : 24;
4341 };
4442
828826 * Entry directories
829827 */
830828
831 static EntryDirectory *
832 entry_directory_new_full (DesktopEntryType entry_type,
833 const char *path,
834 gboolean is_legacy,
835 const char *legacy_prefix)
829 EntryDirectory *
830 entry_directory_new (DesktopEntryType entry_type,
831 const char *path)
836832 {
837833 EntryDirectory *ed;
838834 char *canonical;
839835
840 menu_verbose ("Loading entry directory \"%s\" (legacy %s)\n",
841 path,
842 is_legacy ? "<yes>" : "<no>");
836 menu_verbose ("Loading entry directory \"%s\"\n", path);
843837
844838 canonical = menu_canonicalize_file_name (path, FALSE);
845839 if (canonical == NULL)
857851 cached_dir_add_reference (ed->dir);
858852 cached_dir_load_entries_recursive (ed->dir, canonical);
859853
860 ed->legacy_prefix = g_strdup (legacy_prefix);
861854 ed->entry_type = entry_type;
862 ed->is_legacy = is_legacy != FALSE;
863855 ed->refcount = 1;
864856
865857 g_free (canonical);
866858
867859 return ed;
868 }
869
870 EntryDirectory *
871 entry_directory_new (DesktopEntryType entry_type,
872 const char *path)
873 {
874 return entry_directory_new_full (entry_type, path, FALSE, NULL);
875 }
876
877 EntryDirectory *
878 entry_directory_new_legacy (DesktopEntryType entry_type,
879 const char *path,
880 const char *legacy_prefix)
881 {
882 return entry_directory_new_full (entry_type, path, TRUE, legacy_prefix);
883860 }
884861
885862 EntryDirectory *
905882
906883 ed->dir = NULL;
907884 ed->entry_type = DESKTOP_ENTRY_INVALID;
908 ed->is_legacy = FALSE;
909
910 g_free (ed->legacy_prefix);
911 ed->legacy_prefix = NULL;
912885
913886 g_free (ed);
914887 }
957930
958931 if (entry_type == DESKTOP_ENTRY_DESKTOP)
959932 {
960 if (!ed->is_legacy)
961 {
962 retval = g_strdelimit (g_strdup (relative_path), "/", '-');
963 }
964 else
965 {
966 char *basename;
967
968 basename = g_path_get_basename (relative_path);
969
970 if (ed->legacy_prefix)
971 {
972 retval = g_strjoin ("-", ed->legacy_prefix, basename, NULL);
973 g_free (basename);
974 }
975 else
976 {
977 retval = basename;
978 }
979 }
933 retval = g_strdelimit (g_strdup (relative_path), "/", '-');
980934 }
981935 else
982936 {
12841238 DesktopEntrySet *set,
12851239 gpointer user_data)
12861240 {
1287 if (ed->is_legacy && !desktop_entry_has_categories (entry))
1288 {
1289 entry = desktop_entry_copy (entry);
1290 desktop_entry_add_legacy_category (entry);
1291 }
1292 else
1293 {
1294 entry = desktop_entry_ref (entry);
1295 }
1241 entry = desktop_entry_ref (entry);
12961242
12971243 desktop_entry_set_add_entry (set, entry, file_id);
12981244 desktop_entry_unref (entry);
3131
3232 EntryDirectory *entry_directory_new (DesktopEntryType entry_type,
3333 const char *path);
34 EntryDirectory *entry_directory_new_legacy (DesktopEntryType entry_type,
35 const char *path,
36 const char *legacy_prefix);
3734
3835 EntryDirectory *entry_directory_ref (EntryDirectory *ed);
3936 void entry_directory_unref (EntryDirectory *ed);
23552355 }
23562356
23572357 static void
2358 add_filename_include (const char *desktop_file_id,
2359 DesktopEntry *entry,
2360 MenuLayoutNode *include)
2361 {
2362 if (!desktop_entry_has_categories (entry))
2363 {
2364 MenuLayoutNode *node;
2365
2366 node = menu_layout_node_new (MENU_LAYOUT_NODE_FILENAME);
2367 menu_layout_node_set_content (node, desktop_file_id);
2368
2369 menu_layout_node_append_child (include, node);
2370 menu_layout_node_unref (node);
2371 }
2372 }
2373
2374 static void
2375 is_dot_directory (const char *basename,
2376 DesktopEntry *entry,
2377 gboolean *has_dot_directory)
2378 {
2379 if (!strcmp (basename, ".directory"))
2380 *has_dot_directory = TRUE;
2381 }
2382
2383 static gboolean
2384 add_menu_for_legacy_dir (MenuLayoutNode *parent,
2385 const char *legacy_dir,
2386 const char *relative_path,
2387 const char *legacy_prefix,
2388 const char *menu_name)
2389 {
2390 EntryDirectory *ed;
2391 DesktopEntrySet *desktop_entries;
2392 DesktopEntrySet *directory_entries;
2393 GSList *subdirs;
2394 gboolean menu_added;
2395 gboolean has_dot_directory;
2396
2397 ed = entry_directory_new_legacy (DESKTOP_ENTRY_INVALID, legacy_dir, legacy_prefix);
2398 if (!ed)
2399 return FALSE;
2400
2401 subdirs = NULL;
2402 desktop_entries = desktop_entry_set_new ();
2403 directory_entries = desktop_entry_set_new ();
2404
2405 entry_directory_get_flat_contents (ed,
2406 desktop_entries,
2407 directory_entries,
2408 &subdirs);
2409 entry_directory_unref (ed);
2410
2411 has_dot_directory = FALSE;
2412 desktop_entry_set_foreach (directory_entries,
2413 (DesktopEntrySetForeachFunc) is_dot_directory,
2414 &has_dot_directory);
2415 desktop_entry_set_unref (directory_entries);
2416
2417 menu_added = FALSE;
2418 if (desktop_entry_set_get_count (desktop_entries) > 0 || subdirs)
2419 {
2420 MenuLayoutNode *menu;
2421 MenuLayoutNode *node;
2422 GString *subdir_path;
2423 GString *subdir_relative;
2424 GSList *tmp;
2425 int legacy_dir_len;
2426 int relative_path_len;
2427
2428 menu = menu_layout_node_new (MENU_LAYOUT_NODE_MENU);
2429 menu_layout_node_append_child (parent, menu);
2430
2431 menu_added = TRUE;
2432
2433 g_assert (menu_name != NULL);
2434
2435 node = menu_layout_node_new (MENU_LAYOUT_NODE_NAME);
2436 menu_layout_node_set_content (node, menu_name);
2437 menu_layout_node_append_child (menu, node);
2438 menu_layout_node_unref (node);
2439
2440 if (has_dot_directory)
2441 {
2442 node = menu_layout_node_new (MENU_LAYOUT_NODE_DIRECTORY);
2443 if (relative_path != NULL)
2444 {
2445 char *directory_entry_path;
2446
2447 directory_entry_path = g_strdup_printf ("%s/.directory", relative_path);
2448 menu_layout_node_set_content (node, directory_entry_path);
2449 g_free (directory_entry_path);
2450 }
2451 else
2452 {
2453 menu_layout_node_set_content (node, ".directory");
2454 }
2455 menu_layout_node_append_child (menu, node);
2456 menu_layout_node_unref (node);
2457 }
2458
2459 if (desktop_entry_set_get_count (desktop_entries) > 0)
2460 {
2461 MenuLayoutNode *include;
2462
2463 include = menu_layout_node_new (MENU_LAYOUT_NODE_INCLUDE);
2464 menu_layout_node_append_child (menu, include);
2465
2466 desktop_entry_set_foreach (desktop_entries,
2467 (DesktopEntrySetForeachFunc) add_filename_include,
2468 include);
2469
2470 menu_layout_node_unref (include);
2471 }
2472
2473 subdir_path = g_string_new (legacy_dir);
2474 legacy_dir_len = strlen (legacy_dir);
2475
2476 subdir_relative = g_string_new (relative_path);
2477 relative_path_len = relative_path ? strlen (relative_path) : 0;
2478
2479 tmp = subdirs;
2480 while (tmp != NULL)
2481 {
2482 const char *subdir = tmp->data;
2483
2484 g_string_append_c (subdir_path, G_DIR_SEPARATOR);
2485 g_string_append (subdir_path, subdir);
2486
2487 if (relative_path_len)
2488 {
2489 g_string_append_c (subdir_relative, G_DIR_SEPARATOR);
2490 }
2491 g_string_append (subdir_relative, subdir);
2492
2493 add_menu_for_legacy_dir (menu,
2494 subdir_path->str,
2495 subdir_relative->str,
2496 legacy_prefix,
2497 subdir);
2498
2499 g_string_truncate (subdir_relative, relative_path_len);
2500 g_string_truncate (subdir_path, legacy_dir_len);
2501
2502 tmp = tmp->next;
2503 }
2504
2505 g_string_free (subdir_path, TRUE);
2506 g_string_free (subdir_relative, TRUE);
2507
2508 menu_layout_node_unref (menu);
2509 }
2510
2511 desktop_entry_set_unref (desktop_entries);
2512
2513 g_slist_foreach (subdirs, (GFunc) g_free, NULL);
2514 g_slist_free (subdirs);
2515
2516 return menu_added;
2517 }
2518
2519 static void
2520 resolve_legacy_dir (GMenuTree *tree,
2521 GHashTable *loaded_menu_files,
2522 MenuLayoutNode *legacy)
2523 {
2524 MenuLayoutNode *to_merge;
2525 MenuLayoutNode *menu;
2526
2527 to_merge = menu_layout_node_new (MENU_LAYOUT_NODE_ROOT);
2528
2529 menu = menu_layout_node_get_parent (legacy);
2530 g_assert (menu_layout_node_get_type (menu) == MENU_LAYOUT_NODE_MENU);
2531
2532 if (add_menu_for_legacy_dir (to_merge,
2533 menu_layout_node_get_content (legacy),
2534 NULL,
2535 menu_layout_node_legacy_dir_get_prefix (legacy),
2536 menu_layout_node_menu_get_name (menu)))
2537 {
2538 merge_resolved_children (tree, loaded_menu_files, legacy, to_merge);
2539 }
2540
2541 menu_layout_node_unref (to_merge);
2542 }
2543
2544 static MenuLayoutNode *
2545 add_legacy_dir (GMenuTree *tree,
2546 GHashTable *loaded_menu_files,
2547 MenuLayoutNode *before,
2548 const char *data_dir)
2549 {
2550 MenuLayoutNode *legacy;
2551 char *dirname;
2552
2553 dirname = g_build_filename (data_dir, "applnk", NULL);
2554
2555 legacy = menu_layout_node_new (MENU_LAYOUT_NODE_LEGACY_DIR);
2556 menu_layout_node_set_content (legacy, dirname);
2557 menu_layout_node_legacy_dir_set_prefix (legacy, "kde");
2558 menu_layout_node_insert_before (before, legacy);
2559 menu_layout_node_unref (before);
2560
2561 menu_verbose ("Adding <LegacyDir>%s</LegacyDir> in <KDELegacyDirs/>\n",
2562 dirname);
2563
2564 resolve_legacy_dir (tree, loaded_menu_files, legacy);
2565
2566 g_free (dirname);
2567
2568 return legacy;
2569 }
2570
2571 static void
2572 resolve_kde_legacy_dirs (GMenuTree *tree,
2573 GHashTable *loaded_menu_files,
2574 MenuLayoutNode *layout)
2575 {
2576 MenuLayoutNode *before;
2577 const char * const *system_data_dirs;
2578 int i;
2579
2580 system_data_dirs = g_get_system_data_dirs ();
2581
2582 before = add_legacy_dir (tree,
2583 loaded_menu_files,
2584 menu_layout_node_ref (layout),
2585 g_get_user_data_dir ());
2586
2587 i = 0;
2588 while (system_data_dirs[i] != NULL)
2589 {
2590 before = add_legacy_dir (tree, loaded_menu_files, before, system_data_dirs[i]);
2591
2592 ++i;
2593 }
2594
2595 menu_layout_node_unref (before);
2596
2597 /* remove the now-replaced node */
2598 menu_layout_node_unlink (layout);
2599 }
2600
2601 static void
26022358 gmenu_tree_resolve_files (GMenuTree *tree,
26032359 GHashTable *loaded_menu_files,
26042360 MenuLayoutNode *layout)
26312387 break;
26322388
26332389 case MENU_LAYOUT_NODE_LEGACY_DIR:
2634 resolve_legacy_dir (tree, loaded_menu_files, layout);
2390 menu_verbose ("Ignoring obsolete legacy dir");
26352391 break;
26362392
26372393 case MENU_LAYOUT_NODE_KDE_LEGACY_DIRS:
2638 resolve_kde_legacy_dirs (tree, loaded_menu_files, layout);
2394 menu_verbose ("Ignoring obsolete KDE legacy dirs");
26392395 break;
26402396
26412397 case MENU_LAYOUT_NODE_PASSTHROUGH:
726726 {
727727 entry_directory_list_prepend (dir_dirs, ed);
728728 entry_directory_unref (ed);
729 }
730
731 g_free (path);
732 }
733
734 if (iter->type == MENU_LAYOUT_NODE_LEGACY_DIR)
735 {
736 MenuLayoutNodeLegacyDir *legacy = (MenuLayoutNodeLegacyDir *) iter;
737 char *path;
738
739 path = menu_layout_node_get_content_as_path (iter);
740
741 if (app_dirs != NULL) /* we're loading app dirs */
742 {
743 ed = entry_directory_new_legacy (DESKTOP_ENTRY_DESKTOP,
744 path,
745 legacy->prefix);
746 if (ed != NULL)
747 {
748 entry_directory_list_prepend (app_dirs, ed);
749 entry_directory_unref (ed);
750 }
751 }
752
753 if (dir_dirs != NULL) /* we're loading dir dirs */
754 {
755 ed = entry_directory_new_legacy (DESKTOP_ENTRY_DIRECTORY,
756 path,
757 legacy->prefix);
758 if (ed != NULL)
759 {
760 entry_directory_list_prepend (dir_dirs, ed);
761 entry_directory_unref (ed);
762 }
763729 }
764730
765731 g_free (path);