about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-12-09 00:21:33 +0000
committerJames Booth <boothj5@gmail.com>2012-12-09 00:21:33 +0000
commit986967ef8909e894cd0c691c74da7f50c4b91b3e (patch)
tree7528c2e6ec50880a721ea7dc923d9de86e2bc069 /src
parent4c243722c6b17ccafffaaba47d9c4e1a7e00ab56 (diff)
downloadprofani-tty-986967ef8909e894cd0c691c74da7f50c4b91b3e.tar.gz
Added /theme list command
Diffstat (limited to 'src')
-rw-r--r--src/command.c11
-rw-r--r--src/theme.c21
-rw-r--r--src/theme.h1
-rw-r--r--src/ui.h1
-rw-r--r--src/windows.c16
5 files changed, 49 insertions, 1 deletions
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
@@ -1290,6 +1290,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)
 {
     cons_show("");