1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "screen_list.h"
21 #include "screen_interface.h"
22 #include "screen.h"
23 #include "screen_help.h"
24 #include "screen_queue.h"
25 #include "screen_file.h"
26 #include "screen_artist.h"
27 #include "screen_search.h"
28 #include "screen_song.h"
29 #include "screen_keydef.h"
30 #include "screen_lyrics.h"
31 #include "screen_outputs.h"
33 #include <string.h>
35 static const struct
36 {
37 const char *name;
38 const struct screen_functions *functions;
39 } screens[] = {
40 { "playlist", &screen_queue },
41 { "browse", &screen_browse },
42 #ifdef ENABLE_ARTIST_SCREEN
43 { "artist", &screen_artist },
44 #endif
45 #ifdef ENABLE_HELP_SCREEN
46 { "help", &screen_help },
47 #endif
48 #ifdef ENABLE_SEARCH_SCREEN
49 { "search", &screen_search },
50 #endif
51 #ifdef ENABLE_SONG_SCREEN
52 { "song", &screen_song },
53 #endif
54 #ifdef ENABLE_KEYDEF_SCREEN
55 { "keydef", &screen_keydef },
56 #endif
57 #ifdef ENABLE_LYRICS_SCREEN
58 { "lyrics", &screen_lyrics },
59 #endif
60 #ifdef ENABLE_OUTPUTS_SCREEN
61 { "outputs", &screen_outputs },
62 #endif
63 };
65 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
67 void
68 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
69 {
70 unsigned i;
72 for (i = 0; i < NUM_SCREENS; ++i) {
73 const struct screen_functions *sf = screens[i].functions;
75 if (sf->init)
76 sf->init(w, cols, rows);
77 }
78 }
80 void
81 screen_list_exit(void)
82 {
83 unsigned i;
85 for (i = 0; i < NUM_SCREENS; ++i) {
86 const struct screen_functions *sf = screens[i].functions;
88 if (sf->exit)
89 sf->exit();
90 }
91 }
93 void
94 screen_list_resize(unsigned cols, unsigned rows)
95 {
96 unsigned i;
98 for (i = 0; i < NUM_SCREENS; ++i) {
99 const struct screen_functions *sf = screens[i].functions;
101 if (sf->resize)
102 sf->resize(cols, rows);
103 }
104 }
106 const char *
107 screen_get_name(const struct screen_functions *sf)
108 {
109 unsigned i;
111 for (i = 0; i < NUM_SCREENS; ++i)
112 if (screens[i].functions == sf)
113 return screens[i].name;
115 return NULL;
116 }
118 const struct screen_functions *
119 screen_lookup_name(const char *name)
120 {
121 unsigned i;
123 for (i = 0; i < NUM_SCREENS; ++i)
124 if (strcmp(name, screens[i].name) == 0)
125 return screens[i].functions;
127 return NULL;
128 }