tint2conf: Sort applications correctly when additional desktop files from non-standard locations are found in the config
This commit is contained in:
@@ -2268,31 +2268,75 @@ void load_icons(GtkListStore *apps)
|
|||||||
|
|
||||||
void load_desktop_file(const char *file, gboolean selected)
|
void load_desktop_file(const char *file, gboolean selected)
|
||||||
{
|
{
|
||||||
DesktopEntry entry;
|
char *file_contracted = contract_tilde(file);
|
||||||
if (read_desktop_file(file, &entry)) {
|
|
||||||
GdkPixbuf *pixbuf = load_icon(entry.icon);
|
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;
|
GtkTreeIter iter;
|
||||||
gtk_list_store_append(selected ? launcher_apps : all_apps, &iter);
|
gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
|
||||||
gtk_list_store_set(selected ? launcher_apps :all_apps, &iter,
|
gtk_tree_path_free(path);
|
||||||
appsColIcon, pixbuf,
|
if (!found)
|
||||||
appsColText, g_strdup(entry.name),
|
break;
|
||||||
appsColPath, g_strdup(file),
|
|
||||||
appsColIconName, g_strdup(entry.icon),
|
gchar *app_path;
|
||||||
-1);
|
gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, appsColPath, &app_path, -1);
|
||||||
if (pixbuf)
|
char *contracted = contract_tilde(app_path);
|
||||||
g_object_unref(pixbuf);
|
if (strcmp(contracted, file_contracted) == 0) {
|
||||||
} else {
|
duplicate = TRUE;
|
||||||
printf("Could not load %s\n", file);
|
break;
|
||||||
GtkTreeIter iter;
|
}
|
||||||
gtk_list_store_append(selected ? launcher_apps : all_apps, &iter);
|
free(contracted);
|
||||||
gtk_list_store_set(selected ? launcher_apps :all_apps, &iter,
|
g_free(app_path);
|
||||||
appsColIcon, NULL,
|
|
||||||
appsColText, g_strdup(file),
|
|
||||||
appsColPath, g_strdup(file),
|
|
||||||
appsColIconName, g_strdup(""),
|
|
||||||
-1);
|
|
||||||
}
|
}
|
||||||
free_desktop_entry(&entry);
|
|
||||||
|
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_insert(store, &iter, index);
|
||||||
|
gtk_list_store_set(store, &iter,
|
||||||
|
appsColIcon, pixbuf,
|
||||||
|
appsColText, g_strdup(entry.name),
|
||||||
|
appsColPath, g_strdup(file),
|
||||||
|
appsColIconName, g_strdup(entry.icon),
|
||||||
|
-1);
|
||||||
|
if (pixbuf)
|
||||||
|
g_object_unref(pixbuf);
|
||||||
|
} else {
|
||||||
|
printf("Could not load %s\n", file);
|
||||||
|
GtkTreeIter iter;
|
||||||
|
gtk_list_store_append(store, &iter);
|
||||||
|
gtk_list_store_set(store, &iter,
|
||||||
|
appsColIcon, NULL,
|
||||||
|
appsColText, g_strdup(file),
|
||||||
|
appsColPath, g_strdup(file),
|
||||||
|
appsColIconName, g_strdup(""),
|
||||||
|
-1);
|
||||||
|
}
|
||||||
|
free_desktop_entry(&entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(file_contracted);
|
||||||
}
|
}
|
||||||
|
|
||||||
void populate_from_entries(GList *entries, gboolean selected)
|
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];
|
char real_path[65536];
|
||||||
#endif
|
#endif
|
||||||
if (realpath(file, real_path)) {
|
if (realpath(file, real_path)) {
|
||||||
fprintf(stderr, "SYMLINK %s -> %s in %s\n", file, real_path, path);
|
|
||||||
if (strstr(real_path, path) == real_path)
|
if (strstr(real_path, path) == real_path)
|
||||||
duplicate = TRUE;
|
duplicate = TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
const gchar *home = g_get_home_dir();
|
||||||
if (home && (strcmp(s, "~") == 0 || strstr(s, "~/") == s)) {
|
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();
|
const gchar *home = g_get_home_dir();
|
||||||
if (!home)
|
if (!home)
|
||||||
|
|||||||
@@ -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.
|
// 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.
|
// 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 opposite of expand_tilde: replaces the path to the user's home directory with "~".
|
||||||
// The caller takes ownership of the string.
|
// The caller takes ownership of the string.
|
||||||
char *contract_tilde(char *s);
|
char *contract_tilde(const char *s);
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
int hex_char_to_int(char c);
|
int hex_char_to_int(char c);
|
||||||
|
|||||||
Reference in New Issue
Block a user