tint2conf: Sort applications correctly when additional desktop files from non-standard locations are found in the config

This commit is contained in:
o9000 2016-02-28 13:41:19 +01:00
parent e8eae27029
commit edbf9f4437
3 changed files with 71 additions and 28 deletions

View file

@ -2268,12 +2268,53 @@ void load_icons(GtkListStore *apps)
void load_desktop_file(const char *file, gboolean selected)
{
char *file_contracted = contract_tilde(file);
GtkListStore *store = selected ? launcher_apps : all_apps;
gboolean duplicate = FALSE;
for (int index = 0; ; index++) {
GtkTreePath *path = gtk_tree_path_new_from_indices(index, -1);
GtkTreeIter iter;
gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
gtk_tree_path_free(path);
if (!found)
break;
gchar *app_path;
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, appsColPath, &app_path, -1);
char *contracted = contract_tilde(app_path);
if (strcmp(contracted, file_contracted) == 0) {
duplicate = TRUE;
break;
}
free(contracted);
g_free(app_path);
}
if (!duplicate) {
DesktopEntry entry;
if (read_desktop_file(file, &entry)) {
int index;
gboolean stop = FALSE;
for (index = 0; !stop; index++) {
GtkTreePath *path = gtk_tree_path_new_from_indices(index, -1);
GtkTreeIter iter;
gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
gtk_tree_path_free(path);
if (!found)
break;
gchar *app_name;
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, appsColText, &app_name, -1);
if (strnatcasecmp(app_name, entry.name) >= 0)
stop = TRUE;
g_free(app_name);
}
GdkPixbuf *pixbuf = load_icon(entry.icon);
GtkTreeIter iter;
gtk_list_store_append(selected ? launcher_apps : all_apps, &iter);
gtk_list_store_set(selected ? launcher_apps :all_apps, &iter,
gtk_list_store_insert(store, &iter, index);
gtk_list_store_set(store, &iter,
appsColIcon, pixbuf,
appsColText, g_strdup(entry.name),
appsColPath, g_strdup(file),
@ -2284,8 +2325,8 @@ void load_desktop_file(const char *file, gboolean selected)
} else {
printf("Could not load %s\n", file);
GtkTreeIter iter;
gtk_list_store_append(selected ? launcher_apps : all_apps, &iter);
gtk_list_store_set(selected ? launcher_apps :all_apps, &iter,
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter,
appsColIcon, NULL,
appsColText, g_strdup(file),
appsColPath, g_strdup(file),
@ -2293,6 +2334,9 @@ void load_desktop_file(const char *file, gboolean selected)
-1);
}
free_desktop_entry(&entry);
}
free(file_contracted);
}
void populate_from_entries(GList *entries, gboolean selected)
@ -2444,7 +2488,6 @@ void load_icon_themes(const gchar *path, const gchar *parent, GList **themes)
char real_path[65536];
#endif
if (realpath(file, real_path)) {
fprintf(stderr, "SYMLINK %s -> %s in %s\n", file, real_path, path);
if (strstr(real_path, path) == real_path)
duplicate = TRUE;
}

View file

@ -112,7 +112,7 @@ void tint_exec(const char *command)
}
}
char *expand_tilde(char *s)
char *expand_tilde(const char *s)
{
const gchar *home = g_get_home_dir();
if (home && (strcmp(s, "~") == 0 || strstr(s, "~/") == s)) {
@ -125,7 +125,7 @@ char *expand_tilde(char *s)
}
}
char *contract_tilde(char *s)
char *contract_tilde(const char *s)
{
const gchar *home = g_get_home_dir();
if (!home)

View file

@ -53,11 +53,11 @@ void tint_exec(const char *command);
// Returns a copy of s in which "~" is expanded to the path to the user's home directory.
// The caller takes ownership of the string.
char *expand_tilde(char *s);
char *expand_tilde(const char *s);
// The opposite of expand_tilde: replaces the path to the user's home directory with "~".
// The caller takes ownership of the string.
char *contract_tilde(char *s);
char *contract_tilde(const char *s);
// Color
int hex_char_to_int(char c);