1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Added /theme list command

This commit is contained in:
James Booth 2012-12-09 00:21:33 +00:00
parent 4c243722c6
commit 986967ef89
5 changed files with 49 additions and 1 deletions

View File

@ -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]);
}

View File

@ -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)
{

View File

@ -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

View File

@ -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);

View File

@ -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)
{