fd: Improve error handling of write_nonblock().
[paraslash.git] / gui_theme.c
1 /*
2 * Copyright (C) 2005-2012 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 #include "para.h"
8 #include "gui.h"
9 #include <curses.h>
10
11 static void init_theme_simple(struct gui_theme *t)
12 {
13 struct stat_item_data *d = t->data;
14 t->author = "Andre Noll";
15 t->lines_min = 5;
16 t->top_lines_min = 2;
17 t->cols_min = 40;
18 t->top_lines_default = 2;
19 t->sb_bg = COLOR_CYAN;
20 t->sb_fg = COLOR_BLACK;
21 t->cmd_bg = COLOR_WHITE;
22 t->cmd_fg = COLOR_BLACK;
23 t->output_bg = COLOR_BLUE;
24 t->output_fg = COLOR_WHITE;
25 t->msg_bg = COLOR_BLUE;
26 t->msg_fg = COLOR_YELLOW;
27 t->err_msg_bg = COLOR_RED;
28 t->err_msg_fg = COLOR_WHITE;
29 t->welcome_bg = COLOR_BLUE;
30 t->welcome_fg = COLOR_WHITE;
31 t->sep_bg = COLOR_BLUE;
32 t->sep_fg = COLOR_CYAN;
33 t->default_fg = COLOR_WHITE;
34 t->default_bg = COLOR_BLUE;
35 t->sep_str = "*";
36
37 d[SI_BASENAME].prefix = "";
38 d[SI_BASENAME].postfix = "";
39 d[SI_BASENAME].fg = COLOR_WHITE;
40 d[SI_BASENAME].bg = COLOR_BLUE;
41 d[SI_BASENAME].align = CENTER;
42 d[SI_BASENAME].x = 0;
43 d[SI_BASENAME].y = 7;
44 d[SI_BASENAME].len = 100;
45
46 d[SI_STATUS].prefix = "para_server: ";
47 d[SI_STATUS].postfix = "";
48 d[SI_STATUS].fg = COLOR_WHITE;
49 d[SI_STATUS].bg = COLOR_BLUE;
50 d[SI_STATUS].align = CENTER;
51 d[SI_STATUS].x = 0;
52 d[SI_STATUS].y = 60;
53 d[SI_STATUS].len = 50;
54
55 d[SI_AUDIOD_STATUS].prefix = "para_audiod: ";
56 d[SI_AUDIOD_STATUS].postfix = "";
57 d[SI_AUDIOD_STATUS].fg = COLOR_WHITE;
58 d[SI_AUDIOD_STATUS].bg = COLOR_BLUE;
59 d[SI_AUDIOD_STATUS].align = CENTER;
60 d[SI_AUDIOD_STATUS].x = 50;
61 d[SI_AUDIOD_STATUS].y = 60;
62 d[SI_AUDIOD_STATUS].len = 50;
63
64 }
65
66 static void init_theme_colorful_blackness(struct gui_theme *t)
67 {
68 struct stat_item_data *d = t->data;
69 t->author = "Andre Noll";
70 /* minimal number of lines that is needed to display all
71 * information provided by this theme
72 */
73 t->lines_min = 15;
74 t->cols_min = 80;
75 t->top_lines_min = 9;
76 t->top_lines_default = 11; /* default number of lines */
77
78 t->sb_bg = COLOR_GREEN; /* status bar background */
79 t->sb_fg = COLOR_BLACK; /* status bar foreground */
80 t->cmd_bg = COLOR_BLACK;
81 t->cmd_fg = COLOR_YELLOW;
82 t->output_bg = COLOR_BLACK;
83 t->output_fg = COLOR_CYAN;
84 t->msg_bg = COLOR_BLACK;
85 t->msg_fg = COLOR_WHITE;
86 t->err_msg_bg = COLOR_RED;
87 t->err_msg_fg = COLOR_WHITE;
88 t->welcome_bg = COLOR_BLUE;
89 t->welcome_fg = COLOR_WHITE;
90 t->sep_bg = COLOR_BLACK; /* color of the separator */
91 t->sep_fg = COLOR_BLUE;
92 t->sep_str = "-";
93 t->default_bg = COLOR_BLACK;
94 t->default_fg = COLOR_MAGENTA;
95
96
97 d[SI_PLAY_TIME].prefix = "";
98 d[SI_PLAY_TIME].postfix = "";
99 d[SI_PLAY_TIME].fg = COLOR_CYAN;
100 d[SI_PLAY_TIME].bg = COLOR_BLACK;
101 d[SI_PLAY_TIME].align = CENTER;
102 d[SI_PLAY_TIME].x = 0;
103 d[SI_PLAY_TIME].y = 7;
104 d[SI_PLAY_TIME].len = 35;
105
106 d[SI_BASENAME].prefix = "";
107 d[SI_BASENAME].postfix = "";
108 d[SI_BASENAME].fg = COLOR_CYAN;
109 d[SI_BASENAME].bg = COLOR_BLACK;
110 d[SI_BASENAME].align = LEFT;
111 d[SI_BASENAME].x = 35;
112 d[SI_BASENAME].y = 7;
113 d[SI_BASENAME].len = 65;
114
115 d[SI_STATUS].prefix = "";
116 d[SI_STATUS].postfix = " ";
117 d[SI_STATUS].fg = COLOR_RED;
118 d[SI_STATUS].bg = COLOR_BLACK;
119 d[SI_STATUS].align = RIGHT;
120 d[SI_STATUS].x = 0;
121 d[SI_STATUS].y = 17;
122 d[SI_STATUS].len = 11;
123
124 d[SI_STATUS_FLAGS].prefix = "(";
125 d[SI_STATUS_FLAGS].postfix = ")";
126 d[SI_STATUS_FLAGS].fg = COLOR_RED;
127 d[SI_STATUS_FLAGS].bg = COLOR_BLACK;
128 d[SI_STATUS_FLAGS].align = LEFT;
129 d[SI_STATUS_FLAGS].x = 11;
130 d[SI_STATUS_FLAGS].y = 17;
131 d[SI_STATUS_FLAGS].len = 10;
132
133 d[SI_IMAGE_ID].prefix = "img: ";
134 d[SI_IMAGE_ID].postfix = "";
135 d[SI_IMAGE_ID].fg = COLOR_RED;
136 d[SI_IMAGE_ID].bg = COLOR_BLACK;
137 d[SI_IMAGE_ID].align = CENTER;
138 d[SI_IMAGE_ID].x = 21;
139 d[SI_IMAGE_ID].y = 17;
140 d[SI_IMAGE_ID].len = 10;
141
142 d[SI_LYRICS_ID].prefix = "lyr: ";
143 d[SI_LYRICS_ID].postfix = "";
144 d[SI_LYRICS_ID].fg = COLOR_RED;
145 d[SI_LYRICS_ID].bg = COLOR_BLACK;
146 d[SI_LYRICS_ID].align = CENTER;
147 d[SI_LYRICS_ID].x = 31;
148 d[SI_LYRICS_ID].y = 17;
149 d[SI_LYRICS_ID].len = 11;
150
151 d[SI_FORMAT].prefix = "format: ";
152 d[SI_FORMAT].postfix = "";
153 d[SI_FORMAT].fg = COLOR_RED;
154 d[SI_FORMAT].bg = COLOR_BLACK;
155 d[SI_FORMAT].align = CENTER;
156 d[SI_FORMAT].x = 42;
157 d[SI_FORMAT].y = 17;
158 d[SI_FORMAT].len = 18;
159
160 d[SI_NUM_PLAYED].prefix = "#";
161 d[SI_NUM_PLAYED].postfix = "";
162 d[SI_NUM_PLAYED].fg = COLOR_RED;
163 d[SI_NUM_PLAYED].bg = COLOR_BLACK;
164 d[SI_NUM_PLAYED].align = LEFT;
165 d[SI_NUM_PLAYED].x = 60;
166 d[SI_NUM_PLAYED].y = 17;
167 d[SI_NUM_PLAYED].len = 5;
168
169 d[SI_BITRATE].prefix = "";
170 d[SI_BITRATE].postfix = "";
171 d[SI_BITRATE].fg = COLOR_RED;
172 d[SI_BITRATE].bg = COLOR_BLACK;
173 d[SI_BITRATE].align = CENTER;
174 d[SI_BITRATE].x = 65;
175 d[SI_BITRATE].y = 17;
176 d[SI_BITRATE].len = 13;
177
178 d[SI_FREQUENCY].prefix = "";
179 d[SI_FREQUENCY].postfix = "";
180 d[SI_FREQUENCY].fg = COLOR_RED;
181 d[SI_FREQUENCY].bg = COLOR_BLACK;
182 d[SI_FREQUENCY].align = CENTER;
183 d[SI_FREQUENCY].x = 78;
184 d[SI_FREQUENCY].y = 17;
185 d[SI_FREQUENCY].len = 10;
186
187 d[SI_SCORE].prefix = "sc: ";
188 d[SI_SCORE].postfix = "";
189 d[SI_SCORE].fg = COLOR_RED;
190 d[SI_SCORE].bg = COLOR_BLACK;
191 d[SI_SCORE].align = CENTER;
192 d[SI_SCORE].x = 88;
193 d[SI_SCORE].y = 17;
194 d[SI_SCORE].len = 10;
195
196 d[SI_AUDIOD_STATUS].prefix = "";
197 d[SI_AUDIOD_STATUS].postfix = "";
198 d[SI_AUDIOD_STATUS].fg = COLOR_MAGENTA;
199 d[SI_AUDIOD_STATUS].bg = COLOR_BLACK;
200 d[SI_AUDIOD_STATUS].align = CENTER;
201 d[SI_AUDIOD_STATUS].x = 0;
202 d[SI_AUDIOD_STATUS].y = 27;
203 d[SI_AUDIOD_STATUS].len = 5;
204
205 d[SI_DECODER_FLAGS].prefix = "[";
206 d[SI_DECODER_FLAGS].postfix = "]";
207 d[SI_DECODER_FLAGS].fg = COLOR_MAGENTA;
208 d[SI_DECODER_FLAGS].bg = COLOR_BLACK;
209 d[SI_DECODER_FLAGS].align = CENTER;
210 d[SI_DECODER_FLAGS].x = 5;
211 d[SI_DECODER_FLAGS].y = 27;
212 d[SI_DECODER_FLAGS].len = 10;
213
214 d[SI_MTIME].prefix = "mod: ";
215 d[SI_MTIME].postfix = "";
216 d[SI_MTIME].fg = COLOR_MAGENTA;
217 d[SI_MTIME].bg = COLOR_BLACK;
218 d[SI_MTIME].align = CENTER;
219 d[SI_MTIME].x = 15;
220 d[SI_MTIME].y = 27;
221 d[SI_MTIME].len = 22;
222
223 d[SI_FILE_SIZE].prefix = "";
224 d[SI_FILE_SIZE].postfix = "kb";
225 d[SI_FILE_SIZE].fg = COLOR_MAGENTA;
226 d[SI_FILE_SIZE].bg = COLOR_BLACK;
227 d[SI_FILE_SIZE].align = CENTER;
228 d[SI_FILE_SIZE].x = 37;
229 d[SI_FILE_SIZE].y = 27;
230 d[SI_FILE_SIZE].len = 10;
231
232 d[SI_CHANNELS].prefix = "";
233 d[SI_CHANNELS].postfix = "ch";
234 d[SI_CHANNELS].fg = COLOR_MAGENTA;
235 d[SI_CHANNELS].bg = COLOR_BLACK;
236 d[SI_CHANNELS].align = CENTER;
237 d[SI_CHANNELS].x = 47;
238 d[SI_CHANNELS].y = 27;
239 d[SI_CHANNELS].len = 5;
240
241 d[SI_LAST_PLAYED].prefix = "lp: ";
242 d[SI_LAST_PLAYED].postfix = "";
243 d[SI_LAST_PLAYED].fg = COLOR_MAGENTA;
244 d[SI_LAST_PLAYED].bg = COLOR_BLACK;
245 d[SI_LAST_PLAYED].align = CENTER;
246 d[SI_LAST_PLAYED].x = 52;
247 d[SI_LAST_PLAYED].y = 27;
248 d[SI_LAST_PLAYED].len = 21;
249
250 d[SI_NUM_CHUNKS].prefix = "";
251 d[SI_NUM_CHUNKS].postfix = "x";
252 d[SI_NUM_CHUNKS].fg = COLOR_MAGENTA;
253 d[SI_NUM_CHUNKS].bg = COLOR_BLACK;
254 d[SI_NUM_CHUNKS].align = RIGHT;
255 d[SI_NUM_CHUNKS].x = 73;
256 d[SI_NUM_CHUNKS].y = 27;
257 d[SI_NUM_CHUNKS].len = 11;
258
259 d[SI_CHUNK_TIME].prefix = "";
260 d[SI_CHUNK_TIME].postfix = "ms";
261 d[SI_CHUNK_TIME].fg = COLOR_MAGENTA;
262 d[SI_CHUNK_TIME].bg = COLOR_BLACK;
263 d[SI_CHUNK_TIME].align = LEFT;
264 d[SI_CHUNK_TIME].x = 84;
265 d[SI_CHUNK_TIME].y = 27;
266 d[SI_CHUNK_TIME].len = 8;
267
268 d[SI_AMPLIFICATION].prefix = "amp:";
269 d[SI_AMPLIFICATION].postfix = "";
270 d[SI_AMPLIFICATION].fg = COLOR_MAGENTA;
271 d[SI_AMPLIFICATION].bg = COLOR_BLACK;
272 d[SI_AMPLIFICATION].align = RIGHT;
273 d[SI_AMPLIFICATION].x = 92;
274 d[SI_AMPLIFICATION].y = 27;
275 d[SI_AMPLIFICATION].len = 8;
276
277 d[SI_TECHINFO].prefix = "";
278 d[SI_TECHINFO].postfix = "";
279 d[SI_TECHINFO].fg = COLOR_GREEN;
280 d[SI_TECHINFO].bg = COLOR_BLACK;
281 d[SI_TECHINFO].align = CENTER;
282 d[SI_TECHINFO].x = 0;
283 d[SI_TECHINFO].y = 43;
284 d[SI_TECHINFO].len = 100;
285
286 d[SI_TITLE].prefix = "";
287 d[SI_TITLE].postfix = ",";
288 d[SI_TITLE].fg = COLOR_GREEN;
289 d[SI_TITLE].bg = COLOR_BLACK;
290 d[SI_TITLE].align = RIGHT;
291 d[SI_TITLE].x = 0;
292 d[SI_TITLE].y = 53;
293 d[SI_TITLE].len = 45;
294
295 d[SI_ARTIST].prefix = " by ";
296 d[SI_ARTIST].postfix = "";
297 d[SI_ARTIST].fg = COLOR_GREEN;
298 d[SI_ARTIST].bg = COLOR_BLACK;
299 d[SI_ARTIST].align = LEFT;
300 d[SI_ARTIST].x = 45;
301 d[SI_ARTIST].y = 53;
302 d[SI_ARTIST].len = 45;
303
304 d[SI_YEAR].prefix = "(";
305 d[SI_YEAR].postfix = ")";
306 d[SI_YEAR].fg = COLOR_GREEN;
307 d[SI_YEAR].bg = COLOR_BLACK;
308 d[SI_YEAR].align = RIGHT;
309 d[SI_YEAR].x = 90;
310 d[SI_YEAR].y = 53;
311 d[SI_YEAR].len = 10;
312
313 d[SI_ALBUM].prefix = "A: ";
314 d[SI_ALBUM].postfix = ",";
315 d[SI_ALBUM].fg = COLOR_GREEN;
316 d[SI_ALBUM].bg = COLOR_BLACK;
317 d[SI_ALBUM].align = RIGHT;
318 d[SI_ALBUM].x = 0;
319 d[SI_ALBUM].y = 63;
320 d[SI_ALBUM].len = 50;
321
322 d[SI_COMMENT].prefix = " C: ";
323 d[SI_COMMENT].postfix = "";
324 d[SI_COMMENT].fg = COLOR_GREEN;
325 d[SI_COMMENT].bg = COLOR_BLACK;
326 d[SI_COMMENT].align = LEFT;
327 d[SI_COMMENT].x = 50;
328 d[SI_COMMENT].y = 63;
329 d[SI_COMMENT].len = 50;
330
331 d[SI_AFS_MODE].prefix = "";
332 d[SI_AFS_MODE].postfix = "";
333 d[SI_AFS_MODE].fg = COLOR_YELLOW;
334 d[SI_AFS_MODE].bg = COLOR_BLACK;
335 d[SI_AFS_MODE].align = CENTER;
336 d[SI_AFS_MODE].x = 0;
337 d[SI_AFS_MODE].y = 77;
338 d[SI_AFS_MODE].len = 100;
339
340 d[SI_ATTRIBUTES_TXT].prefix = "";
341 d[SI_ATTRIBUTES_TXT].postfix = "";
342 d[SI_ATTRIBUTES_TXT].fg = COLOR_YELLOW;
343 d[SI_ATTRIBUTES_TXT].bg = COLOR_BLACK;
344 d[SI_ATTRIBUTES_TXT].align = CENTER;
345 d[SI_ATTRIBUTES_TXT].x = 0;
346 d[SI_ATTRIBUTES_TXT].y = 87;
347 d[SI_ATTRIBUTES_TXT].len = 100;
348
349 d[SI_DIRECTORY].prefix = "dir: ";
350 d[SI_DIRECTORY].postfix = "";
351 d[SI_DIRECTORY].fg = COLOR_YELLOW;
352 d[SI_DIRECTORY].bg = COLOR_BLACK;
353 d[SI_DIRECTORY].align = CENTER;
354 d[SI_DIRECTORY].x = 0;
355 d[SI_DIRECTORY].y = 97;
356 d[SI_DIRECTORY].len = 100;
357 }
358
359 struct theme_description {
360 const char *name;
361 void (*init)(struct gui_theme *t);
362 };
363
364 static struct theme_description themes[] = {
365 {
366 .name = "colorful blackness",
367 .init = init_theme_colorful_blackness,
368 },
369 {
370 .name = "simple",
371 .init = init_theme_simple,
372 },
373 };
374
375 #define NUM_THEMES (ARRAY_SIZE(themes))
376
377 static int current_theme_num;
378
379 static void set_theme(int num, struct gui_theme *t)
380 {
381 int i;
382 FOR_EACH_STATUS_ITEM(i)
383 t->data[i].len = 0;
384 num %= NUM_THEMES;
385 t->name = themes[num].name;
386 themes[num].init(t);
387 current_theme_num = num;
388 }
389
390 void init_theme_or_die(const char *name, struct gui_theme *t)
391 {
392 int i;
393
394 if (!name)
395 return set_theme(0, t);
396 for (i = 0; i < NUM_THEMES; i++)
397 if (strcmp(name, themes[i].name) == 0)
398 return set_theme(i, t);
399 fprintf(stderr, "Available themes:\n");
400 for (i = 0; i < NUM_THEMES; i++)
401 fprintf(stderr, "\t%s\n", themes[i].name);
402 exit(EXIT_FAILURE);
403 }
404
405 void prev_theme(struct gui_theme *t)
406 {
407 return set_theme(++current_theme_num, t);
408 }
409
410 void next_theme(struct gui_theme *t)
411 {
412 return set_theme(--current_theme_num, t);
413 }