tint2conf: Do not load desktop files marked as NoDisplay

This commit is contained in:
o9000 2016-02-28 15:50:32 +01:00
parent 1000cbf491
commit 734af1c025
3 changed files with 13 additions and 4 deletions

View file

@ -54,8 +54,8 @@ void expand_exec(DesktopEntry *entry, const char *path)
// %k -> path
if (entry->exec) {
char *exec2 = calloc(strlen(entry->exec) + (entry->name ? strlen(entry->name) : 1) +
(entry->icon ? strlen(entry->icon) : 1) + 100,
1);
(entry->icon ? strlen(entry->icon) : 1) + 100,
1);
char *p, *q;
// p will never point to an escaped char
for (p = entry->exec, q = exec2; *p; p++, q++) {
@ -112,13 +112,14 @@ int read_desktop_file(const char *path, DesktopEntry *entry)
entry->path = strdup(path);
entry->name = entry->icon = entry->exec = NULL;
entry->hidden_from_menus = FALSE;
if ((fp = fopen(path, "rt")) == NULL) {
fprintf(stderr, "Could not open file %s\n", path);
return 0;
}
const gchar **languages = (const gchar **)g_get_language_names();
const gchar **languages = (const gchar **)g_get_language_names();
// lang_index is the index of the language for the best Name key in the language vector
// lang_index_default is a constant that encodes the Name key without a language
int lang_index, lang_index_default;
@ -165,6 +166,8 @@ int read_desktop_file(const char *path, DesktopEntry *entry)
entry->exec = strdup(value);
} else if (!entry->icon && strcmp(key, "Icon") == 0) {
entry->icon = strdup(value);
} else if (!entry->icon && strcmp(key, "NoDisplay") == 0) {
entry->hidden_from_menus = strcasecmp(value, "true") == 0;
}
}
}
@ -205,7 +208,8 @@ const GSList *get_apps_locations()
apps_locations = load_locations_from_env(apps_locations, "XDG_DATA_HOME", "applications", NULL);
apps_locations = g_slist_append(apps_locations, g_build_filename(g_get_home_dir(), ".local/share/applications", NULL));
apps_locations =
g_slist_append(apps_locations, g_build_filename(g_get_home_dir(), ".local/share/applications", NULL));
apps_locations = load_locations_from_env(apps_locations, "XDG_DATA_DIRS", "applications", NULL);

View file

@ -14,6 +14,7 @@ typedef struct DesktopEntry {
char *exec;
char *icon;
char *path;
gboolean hidden_from_menus;
} DesktopEntry;
// Parses a line of the form "key = value". Modifies the line.

View file

@ -2367,6 +2367,10 @@ void load_desktop_entry(const char *file, GList **entries)
DesktopEntry *entry = calloc(1, sizeof(DesktopEntry));
if (!read_desktop_file(file, entry))
printf("Could not load %s\n", file);
if (entry->hidden_from_menus) {
free(entry);
return;
}
if (!entry->name)
entry->name = strdup(file);
if (!entry->icon)