gui: Allow selecting a startup theme.
authorAndre Noll <maan@systemlinux.org>
Mon, 17 Jan 2011 22:00:40 +0000 (23:00 +0100)
committerAndre Noll <maan@systemlinux.org>
Fri, 11 Feb 2011 10:25:07 +0000 (11:25 +0100)
This implements the --theme option which allows to start para_gui
with a theme different than the default theme.

ggo/gui.m4
gui.c
gui.h
gui_theme.c

index 3f31dc1a202ee0eb61d5b8373531b6a80234a6a6..3a59807f6419c00f4bc9ccc26140e8cce893f0c1 100644 (file)
@@ -19,6 +19,17 @@ option "timeout" t
        default="30"
        optional
 
        default="30"
        optional
 
+option "theme" T
+#~~~~~~~~~~~~~~~
+"select startup theme"
+       string typestr = "name"
+       optional
+       details = "
+       If this option is not given the default theme is used.
+       If the given name is not a valid theme name, the list of
+       available themes is printed and the program terminates.
+"
+
 option "stat_cmd" s
 #~~~~~~~~~~~~~~~~~~
 "command to read server and audiod status
 option "stat_cmd" s
 #~~~~~~~~~~~~~~~~~~
 "command to read server and audiod status
diff --git a/gui.c b/gui.c
index 8e70dd93b4d3a5d3d7b35a3c7ec65723d7639f24..5b25c51bee99fa5ad3707a72fa012e4479983dee 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -1399,8 +1399,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
        HANDLE_VERSION_FLAG("gui", conf);
                exit(EXIT_FAILURE);
        }
        HANDLE_VERSION_FLAG("gui", conf);
-       init_theme(0, &theme);
-       top.lines = theme.top_lines_default;
        if (check_key_map_args() < 0) {
                fprintf(stderr, "invalid key map\n");
                exit(EXIT_FAILURE);
        if (check_key_map_args() < 0) {
                fprintf(stderr, "invalid key map\n");
                exit(EXIT_FAILURE);
@@ -1425,6 +1423,8 @@ int main(int argc, char *argv[])
                fprintf(stderr, "invalid key map in config file\n");
                exit(EXIT_FAILURE);
        }
                fprintf(stderr, "invalid key map in config file\n");
                exit(EXIT_FAILURE);
        }
+       init_theme_or_die(conf.theme_arg, &theme);
+       top.lines = theme.top_lines_default;
        setup_signal_handling();
        bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);
        initscr(); /* needed only once, always successful */
        setup_signal_handling();
        bot_win_rb = ringbuffer_new(RINGBUFFER_SIZE);
        initscr(); /* needed only once, always successful */
diff --git a/gui.h b/gui.h
index f8c6712b4d6870003cac507ed429dec47abdeca7..aad2048874468f9bf18ef10d1b18b3303747b91f 100644 (file)
--- a/gui.h
+++ b/gui.h
@@ -30,7 +30,7 @@ struct gui_theme {
        struct stat_item_data data[NUM_STAT_ITEMS];
 };
 
        struct stat_item_data data[NUM_STAT_ITEMS];
 };
 
-void init_theme(int i, struct gui_theme *);
+void init_theme_or_die(const char *name, struct gui_theme *t);
 void next_theme(struct gui_theme *);
 void prev_theme(struct gui_theme *);
 #define LEFT 1
 void next_theme(struct gui_theme *);
 void prev_theme(struct gui_theme *);
 #define LEFT 1
index ffb47d43302773f838f1fc6d0e6ca4958b2e871b..5976a0e73f1072d963ca5c325a8f2299b5b25fff 100644 (file)
@@ -4,19 +4,14 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
+#include <stdbool.h>
 #include "para.h"
 #include "gui.h"
 #include <curses.h>
 
 #include "para.h"
 #include "gui.h"
 #include <curses.h>
 
-#define NUM_THEMES 2
-
-
-static int current_theme_num;
-
 static void init_theme_simple(struct gui_theme *t)
 {
        struct stat_item_data *d = t->data;
 static void init_theme_simple(struct gui_theme *t)
 {
        struct stat_item_data *d = t->data;
-       t->name = "simple";
        t->author = "Andre Noll";
        t->lines_min = 5;
        t->top_lines_min = 2;
        t->author = "Andre Noll";
        t->lines_min = 5;
        t->top_lines_min = 2;
@@ -72,7 +67,6 @@ static void init_theme_simple(struct gui_theme *t)
 static void init_theme_colorful_blackness(struct gui_theme *t)
 {
        struct stat_item_data *d = t->data;
 static void init_theme_colorful_blackness(struct gui_theme *t)
 {
        struct stat_item_data *d = t->data;
-       t->name = "colorful blackness";
        t->author = "Andre Noll";
        /* minimal number of lines that is needed to display all
         * information provided by this theme
        t->author = "Andre Noll";
        /* minimal number of lines that is needed to display all
         * information provided by this theme
@@ -363,24 +357,59 @@ static void init_theme_colorful_blackness(struct gui_theme *t)
        d[SI_DIRECTORY].len = 100;
 }
 
        d[SI_DIRECTORY].len = 100;
 }
 
-void init_theme(int num, struct gui_theme *t)
+struct theme_description {
+       const char *name;
+       void (*init)(struct gui_theme *t);
+};
+
+struct theme_description themes[] = {
+       {
+               .name = "colorful blackness",
+               .init = init_theme_colorful_blackness,
+       },
+       {
+               .name = "simple",
+               .init = init_theme_simple,
+       },
+};
+
+#define NUM_THEMES (ARRAY_SIZE(themes))
+
+static int current_theme_num;
+
+void set_theme(int num, struct gui_theme *t)
 {
        int i;
        FOR_EACH_STATUS_ITEM(i)
                t->data[i].len = 0;
 {
        int i;
        FOR_EACH_STATUS_ITEM(i)
                t->data[i].len = 0;
+       num %= NUM_THEMES;
+       t->name = themes[num].name;
+       themes[num].init(t);
        current_theme_num = num;
        current_theme_num = num;
+}
+
+void init_theme_or_die(const char *name, struct gui_theme *t)
+{
+       int i;
 
 
-       return (num % NUM_THEMES)?
-               init_theme_simple(t) : init_theme_colorful_blackness(t);
+       if (!name)
+               return set_theme(0, t);
+       for (i = 0; i < NUM_THEMES; i++)
+               if (strcmp(name, themes[i].name) == 0)
+                       return set_theme(i, t);
+       fprintf(stderr, "Available themes:\n");
+       for (i = 0; i < NUM_THEMES; i++)
+               fprintf(stderr, "\t%s\n", themes[i].name);
+       exit(EXIT_FAILURE);
 }
 
 void prev_theme(struct gui_theme *t)
 {
 }
 
 void prev_theme(struct gui_theme *t)
 {
-       return init_theme(++current_theme_num, t);
+       return set_theme(++current_theme_num, t);
 }
 
 void next_theme(struct gui_theme *t)
 {
 }
 
 void next_theme(struct gui_theme *t)
 {
-       return init_theme(--current_theme_num, t);
+       return set_theme(--current_theme_num, t);
 }
 
 }