gui: Get rid of do_select()'s mode parameter and call it only once.
[paraslash.git] / gui_theme.c
index 9345f0ed5e10c0860801d455977a00be0a29082e..3c9886d18a2a2a3cbae88a74f79b052391b64672 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2014 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -8,15 +8,9 @@
 #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;
-       t->name = "simple";
        t->author = "Andre Noll";
        t->lines_min = 5;
        t->top_lines_min = 2;
@@ -32,13 +26,11 @@ static void init_theme_simple(struct gui_theme *t)
        t->msg_fg = COLOR_YELLOW;
        t->err_msg_bg = COLOR_RED;
        t->err_msg_fg = COLOR_WHITE;
-       t->welcome_bg = COLOR_BLUE;
-       t->welcome_fg = COLOR_WHITE;
        t->sep_bg = COLOR_BLUE;
        t->sep_fg = COLOR_CYAN;
        t->default_fg = COLOR_WHITE;
        t->default_bg = COLOR_BLUE;
-       t->sep_str = "*";
+       t->sep_char = '*';
 
        d[SI_BASENAME].prefix = "";
        d[SI_BASENAME].postfix = "";
@@ -72,7 +64,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
@@ -92,11 +83,9 @@ static void init_theme_colorful_blackness(struct gui_theme *t)
        t->msg_fg = COLOR_WHITE;
        t->err_msg_bg = COLOR_RED;
        t->err_msg_fg = COLOR_WHITE;
-       t->welcome_bg = COLOR_BLUE;
-       t->welcome_fg = COLOR_WHITE;
        t->sep_bg = COLOR_BLACK; /* color of the separator */
        t->sep_fg = COLOR_BLUE;
-       t->sep_str = "-";
+       t->sep_char = 0; /* default (ACS_HLINE) */
        t->default_bg = COLOR_BLACK;
        t->default_fg = COLOR_MAGENTA;
 
@@ -281,32 +270,59 @@ static void init_theme_colorful_blackness(struct gui_theme *t)
        d[SI_AMPLIFICATION].y = 27;
        d[SI_AMPLIFICATION].len = 8;
 
-       d[SI_AUDIO_FILE_INFO].prefix = "";
-       d[SI_AUDIO_FILE_INFO].postfix = "";
-       d[SI_AUDIO_FILE_INFO].fg = COLOR_GREEN;
-       d[SI_AUDIO_FILE_INFO].bg = COLOR_BLACK;
-       d[SI_AUDIO_FILE_INFO].align = CENTER;
-       d[SI_AUDIO_FILE_INFO].x = 0;
-       d[SI_AUDIO_FILE_INFO].y = 43;
-       d[SI_AUDIO_FILE_INFO].len = 100;
-
-       d[SI_TAGINFO1].prefix = "";
-       d[SI_TAGINFO1].postfix = "";
-       d[SI_TAGINFO1].fg = COLOR_GREEN;
-       d[SI_TAGINFO1].bg = COLOR_BLACK;
-       d[SI_TAGINFO1].align = CENTER;
-       d[SI_TAGINFO1].x = 0;
-       d[SI_TAGINFO1].y = 53;
-       d[SI_TAGINFO1].len = 100;
-
-       d[SI_TAGINFO2].prefix = "";
-       d[SI_TAGINFO2].postfix = "";
-       d[SI_TAGINFO2].fg = COLOR_GREEN;
-       d[SI_TAGINFO2].bg = COLOR_BLACK;
-       d[SI_TAGINFO2].align = CENTER;
-       d[SI_TAGINFO2].x = 0;
-       d[SI_TAGINFO2].y = 63;
-       d[SI_TAGINFO2].len = 100;
+       d[SI_TECHINFO].prefix = "";
+       d[SI_TECHINFO].postfix = "";
+       d[SI_TECHINFO].fg = COLOR_GREEN;
+       d[SI_TECHINFO].bg = COLOR_BLACK;
+       d[SI_TECHINFO].align = CENTER;
+       d[SI_TECHINFO].x = 0;
+       d[SI_TECHINFO].y = 43;
+       d[SI_TECHINFO].len = 100;
+
+       d[SI_TITLE].prefix = "";
+       d[SI_TITLE].postfix = ",";
+       d[SI_TITLE].fg = COLOR_GREEN;
+       d[SI_TITLE].bg = COLOR_BLACK;
+       d[SI_TITLE].align = RIGHT;
+       d[SI_TITLE].x = 0;
+       d[SI_TITLE].y = 53;
+       d[SI_TITLE].len = 45;
+
+       d[SI_ARTIST].prefix = " by ";
+       d[SI_ARTIST].postfix = "";
+       d[SI_ARTIST].fg = COLOR_GREEN;
+       d[SI_ARTIST].bg = COLOR_BLACK;
+       d[SI_ARTIST].align = LEFT;
+       d[SI_ARTIST].x = 45;
+       d[SI_ARTIST].y = 53;
+       d[SI_ARTIST].len = 45;
+
+       d[SI_YEAR].prefix = "(";
+       d[SI_YEAR].postfix = ")";
+       d[SI_YEAR].fg = COLOR_GREEN;
+       d[SI_YEAR].bg = COLOR_BLACK;
+       d[SI_YEAR].align = RIGHT;
+       d[SI_YEAR].x = 90;
+       d[SI_YEAR].y = 53;
+       d[SI_YEAR].len = 10;
+
+       d[SI_ALBUM].prefix = "A: ";
+       d[SI_ALBUM].postfix = ",";
+       d[SI_ALBUM].fg = COLOR_GREEN;
+       d[SI_ALBUM].bg = COLOR_BLACK;
+       d[SI_ALBUM].align = RIGHT;
+       d[SI_ALBUM].x = 0;
+       d[SI_ALBUM].y = 63;
+       d[SI_ALBUM].len = 50;
+
+       d[SI_COMMENT].prefix = " C: ";
+       d[SI_COMMENT].postfix = "";
+       d[SI_COMMENT].fg = COLOR_GREEN;
+       d[SI_COMMENT].bg = COLOR_BLACK;
+       d[SI_COMMENT].align = LEFT;
+       d[SI_COMMENT].x = 50;
+       d[SI_COMMENT].y = 63;
+       d[SI_COMMENT].len = 50;
 
        d[SI_AFS_MODE].prefix = "";
        d[SI_AFS_MODE].postfix = "";
@@ -336,24 +352,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);
+};
+
+static 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;
+
+static 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;
-
-       return (num % NUM_THEMES)?
-               init_theme_simple(t) : init_theme_colorful_blackness(t);
+       PARA_NOTICE_LOG("theme: %s\n", t->name);
 }
 
-void prev_theme(struct gui_theme *t)
+void theme_init(const char *name, struct gui_theme *t)
 {
-       return init_theme(++current_theme_num, t);
+       int i;
+
+       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 next_theme(struct gui_theme *t)
+void theme_prev(struct gui_theme *t)
 {
-       return init_theme(--current_theme_num, t);
+       return set_theme(++current_theme_num, t);
 }
 
+void theme_next(struct gui_theme *t)
+{
+       return set_theme(--current_theme_num, t);
+}