tint2conf: Sort icon themes in list
This commit is contained in:
parent
46e386a6f8
commit
c4d1614cc3
3 changed files with 47 additions and 22 deletions
|
@ -279,6 +279,8 @@ void free_icon_theme(IconTheme *theme)
|
||||||
return;
|
return;
|
||||||
free(theme->name);
|
free(theme->name);
|
||||||
theme->name = NULL;
|
theme->name = NULL;
|
||||||
|
free(theme->description);
|
||||||
|
theme->description = NULL;
|
||||||
for (GSList *l_inherits = theme->list_inherits; l_inherits; l_inherits = l_inherits->next) {
|
for (GSList *l_inherits = theme->list_inherits; l_inherits; l_inherits = l_inherits->next) {
|
||||||
free(l_inherits->data);
|
free(l_inherits->data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ typedef struct IconThemeWrapper {
|
||||||
|
|
||||||
typedef struct IconTheme {
|
typedef struct IconTheme {
|
||||||
char *name;
|
char *name;
|
||||||
|
char *description;
|
||||||
GSList *list_inherits; // each item is a char* (theme name)
|
GSList *list_inherits; // each item is a char* (theme name)
|
||||||
GSList *list_directories; // each item is an IconThemeDir*
|
GSList *list_directories; // each item is an IconThemeDir*
|
||||||
} IconTheme;
|
} IconTheme;
|
||||||
|
@ -31,6 +32,7 @@ int parse_theme_line(char *line, char **key, char **value);
|
||||||
IconThemeWrapper *load_themes(const char *icon_theme_name);
|
IconThemeWrapper *load_themes(const char *icon_theme_name);
|
||||||
|
|
||||||
void free_themes(IconThemeWrapper *themes);
|
void free_themes(IconThemeWrapper *themes);
|
||||||
|
void free_icon_theme(IconTheme *theme);
|
||||||
|
|
||||||
#define DEFAULT_ICON "application-x-executable"
|
#define DEFAULT_ICON "application-x-executable"
|
||||||
|
|
||||||
|
|
|
@ -2294,8 +2294,7 @@ void load_desktop_file(const char *file, gboolean selected)
|
||||||
|
|
||||||
void populate_from_entries(GList *entries, gboolean selected)
|
void populate_from_entries(GList *entries, gboolean selected)
|
||||||
{
|
{
|
||||||
GList *l;
|
for (GList *l = entries; l; l = l->next) {
|
||||||
for (l = entries; l; l = l->next) {
|
|
||||||
DesktopEntry *entry = (DesktopEntry *)l->data;
|
DesktopEntry *entry = (DesktopEntry *)l->data;
|
||||||
GdkPixbuf *pixbuf = load_icon(entry->icon);
|
GdkPixbuf *pixbuf = load_icon(entry->icon);
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
@ -2367,9 +2366,17 @@ void load_desktop_entries(const char *path, GList **entries)
|
||||||
g_list_free(files);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2397,13 +2404,12 @@ void load_theme_file(const char *file_name, const char *theme)
|
||||||
|
|
||||||
if (parse_theme_line(line, &key, &value)) {
|
if (parse_theme_line(line, &key, &value)) {
|
||||||
if (strcmp(key, "Name") == 0) {
|
if (strcmp(key, "Name") == 0) {
|
||||||
// value is like Tango
|
IconTheme *theme = calloc(1, sizeof(IconTheme));
|
||||||
GtkTreeIter iter;
|
theme->name = strdup(theme_name);
|
||||||
gtk_list_store_append(icon_themes, &iter);
|
theme->description = strdup(value);
|
||||||
gtk_list_store_set(icon_themes, &iter,
|
fprintf(stderr, "THEME %s %s %s\n", theme_name, value, file_name);
|
||||||
iconsColName, g_strdup(theme),
|
*themes = g_list_append(*themes, theme);
|
||||||
iconsColDescr, g_strdup(value),
|
break;
|
||||||
-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2415,7 +2421,7 @@ void load_theme_file(const char *file_name, const char *theme)
|
||||||
free(line);
|
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);
|
GDir *d = g_dir_open(path, 0, NULL);
|
||||||
if (!d)
|
if (!d)
|
||||||
|
@ -2426,9 +2432,9 @@ void load_icon_themes(const gchar *path, const gchar *parent)
|
||||||
if (parent &&
|
if (parent &&
|
||||||
g_file_test(file, G_FILE_TEST_IS_REGULAR) &&
|
g_file_test(file, G_FILE_TEST_IS_REGULAR) &&
|
||||||
g_str_equal(name, "index.theme")) {
|
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)) {
|
} 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);
|
g_free(file);
|
||||||
}
|
}
|
||||||
|
@ -2796,18 +2802,34 @@ void create_launcher(GtkWidget *parent)
|
||||||
|
|
||||||
change_paragraph(parent);
|
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;
|
GtkTreeIter iter;
|
||||||
gtk_list_store_append(icon_themes, &iter);
|
gtk_list_store_append(icon_themes, &iter);
|
||||||
gtk_list_store_set(icon_themes, &iter,
|
gtk_list_store_set(icon_themes, &iter,
|
||||||
0, "",
|
0, "",
|
||||||
-1);
|
-1);
|
||||||
|
for (GList *l = themes; l; l = l->next) {
|
||||||
fprintf(stderr, "Loading icon themes\n");
|
IconTheme *theme = (IconTheme*)l->data;
|
||||||
const GSList *location;
|
GtkTreeIter iter;
|
||||||
for (location = get_icon_locations(); location; location = g_slist_next(location)) {
|
gtk_list_store_append(icon_themes, &iter);
|
||||||
const gchar *path = (gchar*) location->data;
|
gtk_list_store_set(icon_themes, &iter,
|
||||||
load_icon_themes(path, NULL);
|
iconsColName, g_strdup(theme->name),
|
||||||
|
iconsColDescr, g_strdup(theme->description),
|
||||||
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "Icon themes loaded\n");
|
||||||
|
|
||||||
fprintf(stderr, "Loading .desktop files\n");
|
fprintf(stderr, "Loading .desktop files\n");
|
||||||
|
@ -2819,8 +2841,7 @@ void create_launcher(GtkWidget *parent)
|
||||||
entries = g_list_sort(entries, compare_entries);
|
entries = g_list_sort(entries, compare_entries);
|
||||||
populate_from_entries(entries, FALSE);
|
populate_from_entries(entries, FALSE);
|
||||||
|
|
||||||
GList *l;
|
for (GList *l = entries; l; l = l->next) {
|
||||||
for (l = entries; l; l = l->next) {
|
|
||||||
free_desktop_entry((DesktopEntry*)l->data);
|
free_desktop_entry((DesktopEntry*)l->data);
|
||||||
}
|
}
|
||||||
g_list_free(entries);
|
g_list_free(entries);
|
||||||
|
|
Loading…
Reference in a new issue