bfbf90c639a5b8cd02cdf78b7d33dc5b90fa1e34
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_SONG_SCREEN
42 { "song", &screen_song },
43 #endif
44 #ifdef ENABLE_KEYDEF_SCREEN
45 { "keydef", &screen_keydef },
46 #endif
47 #ifdef ENABLE_LYRICS_SCREEN
48 { "lyrics", &screen_lyrics },
49 #endif
50 };
52 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
54 void
55 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
56 {
57 unsigned i;
59 for (i = 0; i < NUM_SCREENS; ++i) {
60 const struct screen_functions *sf = screens[i].functions;
62 if (sf->init)
63 sf->init(w, cols, rows);
64 }
65 }
67 void
68 screen_list_exit(void)
69 {
70 unsigned i;
72 for (i = 0; i < NUM_SCREENS; ++i) {
73 const struct screen_functions *sf = screens[i].functions;
75 if (sf->exit)
76 sf->exit();
77 }
78 }
80 void
81 screen_list_resize(unsigned cols, unsigned rows)
82 {
83 unsigned i;
85 for (i = 0; i < NUM_SCREENS; ++i) {
86 const struct screen_functions *sf = screens[i].functions;
88 if (sf->resize)
89 sf->resize(cols, rows);
90 }
91 }
93 const char *
94 screen_get_name(const struct screen_functions *sf)
95 {
96 unsigned i;
98 for (i = 0; i < NUM_SCREENS; ++i)
99 if (screens[i].functions == sf)
100 return screens[i].name;
102 return NULL;
103 }
105 const struct screen_functions *
106 screen_lookup_name(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].functions;
114 return NULL;
115 }