From: Andre Noll Date: Mon, 17 Jan 2011 22:00:40 +0000 (+0100) Subject: gui: Allow selecting a startup theme. X-Git-Tag: v0.4.6~39^2~9 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=7a115f007020abedf07ab71ef17d0d07df1a55f8;ds=sidebyside gui: Allow selecting a startup theme. This implements the --theme option which allows to start para_gui with a theme different than the default theme. --- diff --git a/ggo/gui.m4 b/ggo/gui.m4 index 3f31dc1a..3a59807f 100644 --- a/ggo/gui.m4 +++ b/ggo/gui.m4 @@ -19,6 +19,17 @@ option "timeout" t 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 diff --git a/gui.c b/gui.c index 8e70dd93..5b25c51b 100644 --- a/gui.c +++ b/gui.c @@ -1399,8 +1399,6 @@ int main(int argc, char *argv[]) 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); @@ -1425,6 +1423,8 @@ int main(int argc, char *argv[]) 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 */ diff --git a/gui.h b/gui.h index f8c6712b..aad20488 100644 --- a/gui.h +++ b/gui.h @@ -30,7 +30,7 @@ struct gui_theme { 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 diff --git a/gui_theme.c b/gui_theme.c index ffb47d43..5976a0e7 100644 --- a/gui_theme.c +++ b/gui_theme.c @@ -4,19 +4,14 @@ * Licensed under the GPL v2. For licencing details see COPYING. */ +#include #include "para.h" #include "gui.h" #include -#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; - t->name = "simple"; 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; - t->name = "colorful blackness"; 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; } -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; + num %= NUM_THEMES; + t->name = themes[num].name; + themes[num].init(t); 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) { - return init_theme(++current_theme_num, t); + return set_theme(++current_theme_num, t); } void next_theme(struct gui_theme *t) { - return init_theme(--current_theme_num, t); + return set_theme(--current_theme_num, t); }