1 /*
2 * (c) 2004 by Kalle Wallin <kaw@linux.se>
3 * Copyright (C) 2008 Max Kellermann <max@duempel.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 */
20 #include "screen_list.h"
21 #include "screen.h"
23 #include <string.h>
25 static const struct
26 {
27 const char *name;
28 const struct screen_functions *functions;
29 } screens[] = {
30 { "playlist", &screen_playlist },
31 { "browse", &screen_browse },
32 #ifdef ENABLE_ARTIST_SCREEN
33 { "artist", &screen_artist },
34 #endif
35 #ifdef ENABLE_HELP_SCREEN
36 { "help", &screen_help },
37 #endif
38 #ifdef ENABLE_SEARCH_SCREEN
39 { "search", &screen_search },
40 #endif
41 #ifdef ENABLE_KEYDEF_SCREEN
42 { "keydef", &screen_keydef },
43 #endif
44 #ifdef ENABLE_LYRICS_SCREEN
45 { "lyrics", &screen_lyrics },
46 #endif
47 };
49 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
51 void
52 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
53 {
54 unsigned i;
56 for (i = 0; i < NUM_SCREENS; ++i) {
57 const struct screen_functions *sf = screens[i].functions;
59 if (sf->init)
60 sf->init(w, cols, rows);
61 }
62 }
64 void
65 screen_list_exit(void)
66 {
67 unsigned i;
69 for (i = 0; i < NUM_SCREENS; ++i) {
70 const struct screen_functions *sf = screens[i].functions;
72 if (sf->exit)
73 sf->exit();
74 }
75 }
77 void
78 screen_list_resize(unsigned cols, unsigned rows)
79 {
80 unsigned i;
82 for (i = 0; i < NUM_SCREENS; ++i) {
83 const struct screen_functions *sf = screens[i].functions;
85 if (sf->resize)
86 sf->resize(cols, rows);
87 }
88 }
90 const char *
91 screen_get_name(const struct screen_functions *sf)
92 {
93 unsigned i;
95 for (i = 0; i < NUM_SCREENS; ++i)
96 if (screens[i].functions == sf)
97 return screens[i].name;
99 return NULL;
100 }
102 const struct screen_functions *
103 screen_lookup_name(const char *name)
104 {
105 unsigned i;
107 for (i = 0; i < NUM_SCREENS; ++i)
108 if (strcmp(name, screens[i].name) == 0)
109 return screens[i].functions;
111 return NULL;
112 }