Commit 13c6790a authored by Florian Müllner's avatar Florian Müllner
Browse files

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
parent 37010e03
......@@ -6,11 +6,6 @@
<Name>Applications</Name>
<Directory>X-GNOME-Menu-Applications.directory</Directory>
<!-- Scan legacy dirs first, as later items take priority -->
<KDELegacyDirs/>
<LegacyDir>/etc/X11/applnk</LegacyDir>
<LegacyDir>/usr/share/gnome/apps</LegacyDir>
<!-- Read standard .directory and .desktop file locations -->
<DefaultAppDirs/>
<DefaultDirectoryDirs/>
......
......@@ -631,43 +631,6 @@ desktop_entry_has_category (DesktopEntry *entry,
return FALSE;
}
void
desktop_entry_add_legacy_category (DesktopEntry *entry)
{
GQuark *categories;
int i;
DesktopEntryDesktop *desktop_entry;
g_return_if_fail (entry->type == DESKTOP_ENTRY_DESKTOP);
desktop_entry = (DesktopEntryDesktop*) entry;
menu_verbose ("Adding Legacy category to \"%s\"\n",
entry->basename);
if (desktop_entry->categories != NULL)
{
i = 0;
for (; desktop_entry->categories[i]; i++);
categories = g_new0 (GQuark, i + 2);
i = 0;
for (; desktop_entry->categories[i]; i++)
categories[i] = desktop_entry->categories[i];
}
else
{
categories = g_new0 (GQuark, 2);
i = 0;
}
categories[i] = g_quark_from_string ("Legacy");
g_free (desktop_entry->categories);
desktop_entry->categories = categories;
}
/*
* Entry sets
*/
......
......@@ -55,8 +55,6 @@ gboolean desktop_entry_has_categories (DesktopEntry *entry);
gboolean desktop_entry_has_category (DesktopEntry *entry,
const char *category);
void desktop_entry_add_legacy_category (DesktopEntry *src);
typedef struct DesktopEntrySet DesktopEntrySet;
......
......@@ -34,10 +34,8 @@ typedef struct CachedDirMonitor CachedDirMonitor;
struct EntryDirectory
{
CachedDir *dir;
char *legacy_prefix;
guint entry_type : 2;
guint is_legacy : 1;
guint refcount : 24;
};
......@@ -759,18 +757,14 @@ cached_dir_remove_reference (CachedDir *dir)
* Entry directories
*/
static EntryDirectory *
entry_directory_new_full (DesktopEntryType entry_type,
const char *path,
gboolean is_legacy,
const char *legacy_prefix)
EntryDirectory *
entry_directory_new (DesktopEntryType entry_type,
const char *path)
{
EntryDirectory *ed;
char *canonical;
menu_verbose ("Loading entry directory \"%s\" (legacy %s)\n",
path,
is_legacy ? "<yes>" : "<no>");
menu_verbose ("Loading entry directory \"%s\"\n", path);
canonical = menu_canonicalize_file_name (path, FALSE);
if (canonical == NULL)
......@@ -788,9 +782,7 @@ entry_directory_new_full (DesktopEntryType entry_type,
cached_dir_add_reference (ed->dir);
cached_dir_load_entries_recursive (ed->dir, canonical);
ed->legacy_prefix = g_strdup (legacy_prefix);
ed->entry_type = entry_type;
ed->is_legacy = is_legacy != FALSE;
ed->refcount = 1;
g_free (canonical);
......@@ -798,21 +790,6 @@ entry_directory_new_full (DesktopEntryType entry_type,
return ed;
}
EntryDirectory *
entry_directory_new (DesktopEntryType entry_type,
const char *path)
{
return entry_directory_new_full (entry_type, path, FALSE, NULL);
}
EntryDirectory *
entry_directory_new_legacy (DesktopEntryType entry_type,
const char *path,
const char *legacy_prefix)
{
return entry_directory_new_full (entry_type, path, TRUE, legacy_prefix);
}
EntryDirectory *
entry_directory_ref (EntryDirectory *ed)
{
......@@ -836,10 +813,6 @@ entry_directory_unref (EntryDirectory *ed)
ed->dir = NULL;
ed->entry_type = DESKTOP_ENTRY_INVALID;
ed->is_legacy = FALSE;
g_free (ed->legacy_prefix);
ed->legacy_prefix = NULL;
g_free (ed);
}
......@@ -888,26 +861,7 @@ get_desktop_file_id_from_path (EntryDirectory *ed,
if (entry_type == DESKTOP_ENTRY_DESKTOP)
{
if (!ed->is_legacy)
{
retval = g_strdelimit (g_strdup (relative_path), "/", '-');
}
else
{
char *basename;
basename = g_path_get_basename (relative_path);
if (ed->legacy_prefix)
{
retval = g_strjoin ("-", ed->legacy_prefix, basename, NULL);
g_free (basename);
}
else
{
retval = basename;
}
}
retval = g_strdelimit (g_strdup (relative_path), "/", '-');
}
else
{
......@@ -1215,15 +1169,7 @@ get_all_func (EntryDirectory *ed,
DesktopEntrySet *set,
gpointer user_data)
{
if (ed->is_legacy && !desktop_entry_has_categories (entry))
{
entry = desktop_entry_copy (entry);
desktop_entry_add_legacy_category (entry);
}
else
{
entry = desktop_entry_ref (entry);
}
entry = desktop_entry_ref (entry);
desktop_entry_set_add_entry (set, entry, file_id);
desktop_entry_unref (entry);
......
......@@ -30,9 +30,6 @@ typedef void (*EntryDirectoryChangedFunc) (EntryDirectory *ed,
EntryDirectory *entry_directory_new (DesktopEntryType entry_type,
const char *path);
EntryDirectory *entry_directory_new_legacy (DesktopEntryType entry_type,
const char *path,
const char *legacy_prefix);
EntryDirectory *entry_directory_ref (EntryDirectory *ed);
void entry_directory_unref (EntryDirectory *ed);
......
......@@ -2343,250 +2343,6 @@ resolve_default_merge_dirs (GMenuTree *tree,
menu_layout_node_unlink (layout);
}
static void
add_filename_include (const char *desktop_file_id,
DesktopEntry *entry,
MenuLayoutNode *include)
{
if (!desktop_entry_has_categories (entry))
{
MenuLayoutNode *node;
node = menu_layout_node_new (MENU_LAYOUT_NODE_FILENAME);
menu_layout_node_set_content (node, desktop_file_id);
menu_layout_node_append_child (include, node);
menu_layout_node_unref (node);
}
}
static void
is_dot_directory (const char *basename,
DesktopEntry *entry,
gboolean *has_dot_directory)
{
if (!strcmp (basename, ".directory"))
*has_dot_directory = TRUE;
}
static gboolean
add_menu_for_legacy_dir (MenuLayoutNode *parent,
const char *legacy_dir,
const char *relative_path,
const char *legacy_prefix,
const char *menu_name)
{
EntryDirectory *ed;
DesktopEntrySet *desktop_entries;
DesktopEntrySet *directory_entries;
GSList *subdirs;
gboolean menu_added;
gboolean has_dot_directory;
ed = entry_directory_new_legacy (DESKTOP_ENTRY_INVALID, legacy_dir, legacy_prefix);
if (!ed)
return FALSE;
subdirs = NULL;
desktop_entries = desktop_entry_set_new ();
directory_entries = desktop_entry_set_new ();
entry_directory_get_flat_contents (ed,
desktop_entries,
directory_entries,
&subdirs);
entry_directory_unref (ed);
has_dot_directory = FALSE;
desktop_entry_set_foreach (directory_entries,
(DesktopEntrySetForeachFunc) is_dot_directory,
&has_dot_directory);
desktop_entry_set_unref (directory_entries);
menu_added = FALSE;
if (desktop_entry_set_get_count (desktop_entries) > 0 || subdirs)
{
MenuLayoutNode *menu;
MenuLayoutNode *node;
GString *subdir_path;
GString *subdir_relative;
GSList *tmp;
int legacy_dir_len;
int relative_path_len;
menu = menu_layout_node_new (MENU_LAYOUT_NODE_MENU);
menu_layout_node_append_child (parent, menu);
menu_added = TRUE;
g_assert (menu_name != NULL);
node = menu_layout_node_new (MENU_LAYOUT_NODE_NAME);
menu_layout_node_set_content (node, menu_name);
menu_layout_node_append_child (menu, node);
menu_layout_node_unref (node);
if (has_dot_directory)
{
node = menu_layout_node_new (MENU_LAYOUT_NODE_DIRECTORY);
if (relative_path != NULL)
{
char *directory_entry_path;
directory_entry_path = g_strdup_printf ("%s/.directory", relative_path);
menu_layout_node_set_content (node, directory_entry_path);
g_free (directory_entry_path);
}
else
{
menu_layout_node_set_content (node, ".directory");
}
menu_layout_node_append_child (menu, node);
menu_layout_node_unref (node);
}
if (desktop_entry_set_get_count (desktop_entries) > 0)
{
MenuLayoutNode *include;
include = menu_layout_node_new (MENU_LAYOUT_NODE_INCLUDE);
menu_layout_node_append_child (menu, include);
desktop_entry_set_foreach (desktop_entries,
(DesktopEntrySetForeachFunc) add_filename_include,
include);
menu_layout_node_unref (include);
}
subdir_path = g_string_new (legacy_dir);
legacy_dir_len = strlen (legacy_dir);
subdir_relative = g_string_new (relative_path);
relative_path_len = relative_path ? strlen (relative_path) : 0;
tmp = subdirs;
while (tmp != NULL)
{
const char *subdir = tmp->data;
g_string_append_c (subdir_path, G_DIR_SEPARATOR);
g_string_append (subdir_path, subdir);
if (relative_path_len)
{
g_string_append_c (subdir_relative, G_DIR_SEPARATOR);
}
g_string_append (subdir_relative, subdir);
add_menu_for_legacy_dir (menu,
subdir_path->str,
subdir_relative->str,
legacy_prefix,
subdir);
g_string_truncate (subdir_relative, relative_path_len);
g_string_truncate (subdir_path, legacy_dir_len);
tmp = tmp->next;
}
g_string_free (subdir_path, TRUE);
g_string_free (subdir_relative, TRUE);
menu_layout_node_unref (menu);
}
desktop_entry_set_unref (desktop_entries);
g_slist_foreach (subdirs, (GFunc) g_free, NULL);
g_slist_free (subdirs);
return menu_added;
}
static void
resolve_legacy_dir (GMenuTree *tree,
GHashTable *loaded_menu_files,
MenuLayoutNode *legacy)
{
MenuLayoutNode *to_merge;
MenuLayoutNode *menu;
to_merge = menu_layout_node_new (MENU_LAYOUT_NODE_ROOT);
menu = menu_layout_node_get_parent (legacy);
g_assert (menu_layout_node_get_type (menu) == MENU_LAYOUT_NODE_MENU);
if (add_menu_for_legacy_dir (to_merge,
menu_layout_node_get_content (legacy),
NULL,
menu_layout_node_legacy_dir_get_prefix (legacy),
menu_layout_node_menu_get_name (menu)))
{
merge_resolved_children (tree, loaded_menu_files, legacy, to_merge);
}
menu_layout_node_unref (to_merge);
}
static MenuLayoutNode *
add_legacy_dir (GMenuTree *tree,
GHashTable *loaded_menu_files,
MenuLayoutNode *before,
const char *data_dir)
{
MenuLayoutNode *legacy;
char *dirname;
dirname = g_build_filename (data_dir, "applnk", NULL);
legacy = menu_layout_node_new (MENU_LAYOUT_NODE_LEGACY_DIR);
menu_layout_node_set_content (legacy, dirname);
menu_layout_node_legacy_dir_set_prefix (legacy, "kde");
menu_layout_node_insert_before (before, legacy);
menu_layout_node_unref (before);
menu_verbose ("Adding <LegacyDir>%s</LegacyDir> in <KDELegacyDirs/>\n",
dirname);
resolve_legacy_dir (tree, loaded_menu_files, legacy);
g_free (dirname);
return legacy;
}
static void
resolve_kde_legacy_dirs (GMenuTree *tree,
GHashTable *loaded_menu_files,
MenuLayoutNode *layout)
{
MenuLayoutNode *before;
const char * const *system_data_dirs;
int i;
system_data_dirs = g_get_system_data_dirs ();
before = add_legacy_dir (tree,
loaded_menu_files,
menu_layout_node_ref (layout),
g_get_user_data_dir ());
i = 0;
while (system_data_dirs[i] != NULL)
{
before = add_legacy_dir (tree, loaded_menu_files, before, system_data_dirs[i]);
++i;
}
menu_layout_node_unref (before);
/* remove the now-replaced node */
menu_layout_node_unlink (layout);
}
static void
gmenu_tree_resolve_files (GMenuTree *tree,
GHashTable *loaded_menu_files,
......@@ -2620,11 +2376,11 @@ gmenu_tree_resolve_files (GMenuTree *tree,
break;
case MENU_LAYOUT_NODE_LEGACY_DIR:
resolve_legacy_dir (tree, loaded_menu_files, layout);
menu_verbose ("Ignoring obsolete legacy dir");
break;
case MENU_LAYOUT_NODE_KDE_LEGACY_DIRS:
resolve_kde_legacy_dirs (tree, loaded_menu_files, layout);
menu_verbose ("Ignoring obsolete KDE legacy dirs");
break;
case MENU_LAYOUT_NODE_PASSTHROUGH:
......
......@@ -730,40 +730,6 @@ ensure_dir_lists (MenuLayoutNodeMenu *nm)
g_free (path);
}
if (iter->type == MENU_LAYOUT_NODE_LEGACY_DIR)
{
MenuLayoutNodeLegacyDir *legacy = (MenuLayoutNodeLegacyDir *) iter;
char *path;
path = menu_layout_node_get_content_as_path (iter);
if (app_dirs != NULL) /* we're loading app dirs */
{
ed = entry_directory_new_legacy (DESKTOP_ENTRY_DESKTOP,
path,
legacy->prefix);
if (ed != NULL)
{
entry_directory_list_prepend (app_dirs, ed);
entry_directory_unref (ed);
}
}
if (dir_dirs != NULL) /* we're loading dir dirs */
{
ed = entry_directory_new_legacy (DESKTOP_ENTRY_DIRECTORY,
path,
legacy->prefix);
if (ed != NULL)
{
entry_directory_list_prepend (dir_dirs, ed);
entry_directory_unref (ed);
}
}
g_free (path);
}
iter = node_next (iter);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment