all repos — tint2 @ c4d1614cc3708046c26d7451b7696ad052b22da0

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

tint2conf: Sort icon themes in list
o9000 mrovi9000@gmail.com
commit

c4d1614cc3708046c26d7451b7696ad052b22da0

parent

46e386a6f83fa9fe43db46837e829f5b7dd97d42

3 files changed, 46 insertions(+), 21 deletions(-)

jump to
M src/launcher/icon-theme-common.csrc/launcher/icon-theme-common.c

@@ -279,6 +279,8 @@ if (!theme)

return; free(theme->name); theme->name = NULL; + free(theme->description); + theme->description = NULL; for (GSList *l_inherits = theme->list_inherits; l_inherits; l_inherits = l_inherits->next) { free(l_inherits->data); }
M src/launcher/icon-theme-common.hsrc/launcher/icon-theme-common.h

@@ -17,6 +17,7 @@ } IconThemeWrapper;

typedef struct IconTheme { char *name; + char *description; GSList *list_inherits; // each item is a char* (theme name) GSList *list_directories; // each item is an IconThemeDir* } IconTheme;

@@ -31,6 +32,7 @@ // inherited themes, the hicolor theme and possibly fallback themes.

IconThemeWrapper *load_themes(const char *icon_theme_name); void free_themes(IconThemeWrapper *themes); +void free_icon_theme(IconTheme *theme); #define DEFAULT_ICON "application-x-executable"
M src/tint2conf/properties.csrc/tint2conf/properties.c

@@ -2294,8 +2294,7 @@ }

void populate_from_entries(GList *entries, gboolean selected) { - GList *l; - for (l = entries; l; l = l->next) { + for (GList *l = entries; l; l = l->next) { DesktopEntry *entry = (DesktopEntry *)l->data; GdkPixbuf *pixbuf = load_icon(entry->icon); GtkTreeIter iter;

@@ -2367,9 +2366,17 @@ }

g_list_free(files); } -void load_theme_file(const char *file_name, const char *theme) +static gint compare_themes(gconstpointer a, gconstpointer b) { - if (!file_name || !theme) { + gint result = strnatcasecmp(((IconTheme*)a)->description, ((IconTheme*)b)->description); + if (result) + return result; + return strnatcasecmp(((IconTheme*)a)->name, ((IconTheme*)b)->name); +} + +void load_theme_file(const char *file_name, const char *theme_name, GList **themes) +{ + if (!file_name || !theme_name) { return; }

@@ -2397,13 +2404,12 @@ continue;

if (parse_theme_line(line, &key, &value)) { if (strcmp(key, "Name") == 0) { - // value is like Tango - GtkTreeIter iter; - gtk_list_store_append(icon_themes, &iter); - gtk_list_store_set(icon_themes, &iter, - iconsColName, g_strdup(theme), - iconsColDescr, g_strdup(value), - -1); + IconTheme *theme = calloc(1, sizeof(IconTheme)); + theme->name = strdup(theme_name); + theme->description = strdup(value); + fprintf(stderr, "THEME %s %s %s\n", theme_name, value, file_name); + *themes = g_list_append(*themes, theme); + break; } }

@@ -2415,7 +2421,7 @@ fclose(f);

free(line); } -void load_icon_themes(const gchar *path, const gchar *parent) +void load_icon_themes(const gchar *path, const gchar *parent, GList **themes) { GDir *d = g_dir_open(path, 0, NULL); if (!d)

@@ -2426,9 +2432,9 @@ gchar *file = g_build_filename(path, name, NULL);

if (parent && g_file_test(file, G_FILE_TEST_IS_REGULAR) && g_str_equal(name, "index.theme")) { - load_theme_file(file, parent); + load_theme_file(file, parent, themes); } else if (g_file_test(file, G_FILE_TEST_IS_DIR)) { - load_icon_themes(file, name); + load_icon_themes(file, name, themes); } g_free(file); }

@@ -2796,18 +2802,34 @@ gtk_tooltips_set_tip(tooltips, launcher_tooltip, _("If enabled, shows a tooltip with the application name when the mouse is moved over an application launcher."), NULL);

change_paragraph(parent); + fprintf(stderr, "Loading icon themes\n"); + GList *themes = NULL; + const GSList *location; + for (location = get_icon_locations(); location; location = g_slist_next(location)) { + const gchar *path = (gchar*) location->data; + load_icon_themes(path, NULL, &themes); + } + themes = g_list_sort(themes, compare_themes); + GtkTreeIter iter; gtk_list_store_append(icon_themes, &iter); gtk_list_store_set(icon_themes, &iter, 0, "", -1); + for (GList *l = themes; l; l = l->next) { + IconTheme *theme = (IconTheme*)l->data; + GtkTreeIter iter; + gtk_list_store_append(icon_themes, &iter); + gtk_list_store_set(icon_themes, &iter, + iconsColName, g_strdup(theme->name), + iconsColDescr, g_strdup(theme->description), + -1); + } - fprintf(stderr, "Loading icon themes\n"); - const GSList *location; - for (location = get_icon_locations(); location; location = g_slist_next(location)) { - const gchar *path = (gchar*) location->data; - load_icon_themes(path, NULL); + for (GList *l = themes; l; l = l->next) { + free_icon_theme((IconTheme*)l->data); } + g_list_free(themes); fprintf(stderr, "Icon themes loaded\n"); fprintf(stderr, "Loading .desktop files\n");

@@ -2819,8 +2841,7 @@ load_desktop_entries(path, &entries);

entries = g_list_sort(entries, compare_entries); populate_from_entries(entries, FALSE); - GList *l; - for (l = entries; l; l = l->next) { + for (GList *l = entries; l; l = l->next) { free_desktop_entry((DesktopEntry*)l->data); } g_list_free(entries);