1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 The Music Player Daemon Project
3 * Project homepage: http://musicpd.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 *
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 void
66 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
67 {
68 unsigned i;
70 for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
71 const struct screen_functions *sf = screens[i].functions;
73 if (sf->init)
74 sf->init(w, cols, rows);
75 }
76 }
78 void
79 screen_list_exit(void)
80 {
81 unsigned i;
83 for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
84 const struct screen_functions *sf = screens[i].functions;
86 if (sf->exit)
87 sf->exit();
88 }
89 }
91 void
92 screen_list_resize(unsigned cols, unsigned rows)
93 {
94 unsigned i;
96 for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
97 const struct screen_functions *sf = screens[i].functions;
99 if (sf->resize)
100 sf->resize(cols, rows);
101 }
102 }
104 const char *
105 screen_get_name(const struct screen_functions *sf)
106 {
107 unsigned i;
109 for (i = 0; i < G_N_ELEMENTS(screens); ++i)
110 if (screens[i].functions == sf)
111 return screens[i].name;
113 return NULL;
114 }
116 const struct screen_functions *
117 screen_lookup_name(const char *name)
118 {
119 unsigned i;
121 for (i = 0; i < G_N_ELEMENTS(screens); ++i)
122 if (strcmp(name, screens[i].name) == 0)
123 return screens[i].functions;
125 return NULL;
126 }