From 986967ef8909e894cd0c691c74da7f50c4b91b3e Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 9 Dec 2012 00:21:33 +0000 Subject: Added /theme list command --- src/command.c | 11 ++++++++++- src/theme.c | 21 +++++++++++++++++++++ src/theme.h | 1 + src/ui.h | 1 + src/windows.c | 16 ++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index 2b0d14bc..c81a7618 100644 --- a/src/command.c +++ b/src/command.c @@ -1223,10 +1223,19 @@ _cmd_prefs(gchar **args, struct cmd_help_t help) static gboolean _cmd_theme(gchar **args, struct cmd_help_t help) { - if (theme_load(args[0])) { + // list themes + if (strcmp(args[0], "list") == 0) { + GSList *themes = theme_list(); + cons_show_themes(themes); + g_slist_free_full(themes, g_free); + + // load a theme + } else if (theme_load(args[0])) { ui_load_colours(); prefs_set_theme(args[0]); cons_show("Loaded theme: %s", args[0]); + + // theme not found } else { cons_show("Couldn't find theme: %s", args[0]); } diff --git a/src/theme.c b/src/theme.c index 47f678f4..6f222e6e 100644 --- a/src/theme.c +++ b/src/theme.c @@ -112,6 +112,27 @@ theme_init(const char * const theme_name) _load_colours(); } +GSList * +theme_list(void) +{ + GSList *result = NULL; + gchar *themes_dir = files_get_themes_dir(); + GDir *themes = g_dir_open(themes_dir, 0, NULL); + if (themes != NULL) { + const gchar *theme = g_dir_read_name(themes); + while (theme != NULL) { + result = g_slist_append(result, strdup(theme)); + theme = g_dir_read_name(themes); + } + + g_dir_close(themes); + return result; + + } else { + return NULL; + } +} + gboolean theme_load(const char * const theme_name) { diff --git a/src/theme.h b/src/theme.h index 8de1ace1..01bb5014 100644 --- a/src/theme.h +++ b/src/theme.h @@ -61,6 +61,7 @@ void theme_init(const char * const theme_name); void theme_init_colours(void); gboolean theme_load(const char * const theme_name); +GSList* theme_list(void); void theme_close(void); #endif diff --git a/src/ui.h b/src/ui.h index 262a51f4..8a1f4e23 100644 --- a/src/ui.h +++ b/src/ui.h @@ -154,6 +154,7 @@ void cons_show_contacts(GSList * list); void cons_check_version(gboolean not_available_msg); void cons_show_wins(void); void cons_show_status(const char * const contact); +void cons_show_themes(GSList *themes); // status bar actions void status_bar_refresh(void); diff --git a/src/windows.c b/src/windows.c index 2aee2ec5..7682cd5c 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1289,6 +1289,22 @@ cons_show_connection_prefs(void) } } +void +cons_show_themes(GSList *themes) +{ + cons_show(""); + + if (themes == NULL) { + cons_show("No available themes."); + } else { + cons_show("Available themes:"); + while (themes != NULL) { + cons_show(themes->data); + themes = g_slist_next(themes); + } + } +} + void cons_prefs(void) { -- cgit 1.4.1-2-gfad0