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 int id;
28 const char *name;
29 const struct screen_functions *functions;
30 } screens[] = {
31 { SCREEN_PLAYLIST_ID, "playlist", &screen_playlist },
32 { SCREEN_BROWSE_ID, "browse", &screen_browse },
33 #ifdef ENABLE_ARTIST_SCREEN
34 { SCREEN_ARTIST_ID, "artist", &screen_artist },
35 #endif
36 { SCREEN_HELP_ID, "help", &screen_help },
37 #ifdef ENABLE_SEARCH_SCREEN
38 { SCREEN_SEARCH_ID, "search", &screen_search },
39 #endif
40 #ifdef ENABLE_KEYDEF_SCREEN
41 { SCREEN_KEYDEF_ID, "keydef", &screen_keydef },
42 #endif
43 #ifdef ENABLE_LYRICS_SCREEN
44 { SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
45 #endif
46 };
48 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
50 void
51 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
52 {
53 unsigned i;
55 for (i = 0; i < NUM_SCREENS; ++i) {
56 const struct screen_functions *sf = screens[i].functions;
58 if (sf->init)
59 sf->init(w, cols, rows);
60 }
61 }
63 void
64 screen_list_exit(void)
65 {
66 unsigned i;
68 for (i = 0; i < NUM_SCREENS; ++i) {
69 const struct screen_functions *sf = screens[i].functions;
71 if (sf->exit)
72 sf->exit();
73 }
74 }
76 void
77 screen_list_resize(unsigned cols, unsigned rows)
78 {
79 unsigned i;
81 for (i = 0; i < NUM_SCREENS; ++i) {
82 const struct screen_functions *sf = screens[i].functions;
84 if (sf->resize)
85 sf->resize(cols, rows);
86 }
87 }
89 int
90 screen_get_id_by_index(unsigned i)
91 {
92 assert(i < NUM_SCREENS);
94 return screens[i].id;
95 }
97 const char *
98 screen_get_name(unsigned i)
99 {
100 assert(i < NUM_SCREENS);
102 return screens[i].name;
103 }
105 int
106 screen_get_id(const char *name)
107 {
108 unsigned i;
110 for (i = 0; i < NUM_SCREENS; ++i)
111 if (strcmp(name, screens[i].name) == 0)
112 return screens[i].id;
114 return -1;
115 }
117 const struct screen_functions *
118 screen_get_functions(unsigned i)
119 {
120 assert(i < NUM_SCREENS);
122 return screens[i].functions;
123 }
125 int
126 lookup_mode(int id)
127 {
128 unsigned i;
130 for (i = 0; i < NUM_SCREENS; ++i)
131 if (screens[i].id == id)
132 return i;
134 return -1;
135 }