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 { "help", &screen_help },
36 #ifdef ENABLE_SEARCH_SCREEN
37 { "search", &screen_search },
38 #endif
39 #ifdef ENABLE_KEYDEF_SCREEN
40 { "keydef", &screen_keydef },
41 #endif
42 #ifdef ENABLE_LYRICS_SCREEN
43 { "lyrics", &screen_lyrics },
44 #endif
45 };
47 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
49 void
50 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
51 {
52 unsigned i;
54 for (i = 0; i < NUM_SCREENS; ++i) {
55 const struct screen_functions *sf = screens[i].functions;
57 if (sf->init)
58 sf->init(w, cols, rows);
59 }
60 }
62 void
63 screen_list_exit(void)
64 {
65 unsigned i;
67 for (i = 0; i < NUM_SCREENS; ++i) {
68 const struct screen_functions *sf = screens[i].functions;
70 if (sf->exit)
71 sf->exit();
72 }
73 }
75 void
76 screen_list_resize(unsigned cols, unsigned rows)
77 {
78 unsigned i;
80 for (i = 0; i < NUM_SCREENS; ++i) {
81 const struct screen_functions *sf = screens[i].functions;
83 if (sf->resize)
84 sf->resize(cols, rows);
85 }
86 }
88 const char *
89 screen_get_name(const struct screen_functions *sf)
90 {
91 unsigned i;
93 for (i = 0; i < NUM_SCREENS; ++i)
94 if (screens[i].functions == sf)
95 return screens[i].name;
97 return NULL;
98 }
100 const struct screen_functions *
101 screen_lookup_name(const char *name)
102 {
103 unsigned i;
105 for (i = 0; i < NUM_SCREENS; ++i)
106 if (strcmp(name, screens[i].name) == 0)
107 return screens[i].functions;
109 return NULL;
110 }