Code

Update copyright notices
[ncmpc.git] / src / screen_list.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 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.
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.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 #ifdef ENABLE_OUTPUTS_SCREEN
51         { "outputs", &screen_outputs },
52 #endif
53 };
55 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
57 void
58 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
59 {
60         unsigned i;
62         for (i = 0; i < NUM_SCREENS; ++i) {
63                 const struct screen_functions *sf = screens[i].functions;
65                 if (sf->init)
66                         sf->init(w, cols, rows);
67         }
68 }
70 void
71 screen_list_exit(void)
72 {
73         unsigned i;
75         for (i = 0; i < NUM_SCREENS; ++i) {
76                 const struct screen_functions *sf = screens[i].functions;
78                 if (sf->exit)
79                         sf->exit();
80         }
81 }
83 void
84 screen_list_resize(unsigned cols, unsigned rows)
85 {
86         unsigned i;
88         for (i = 0; i < NUM_SCREENS; ++i) {
89                 const struct screen_functions *sf = screens[i].functions;
91                 if (sf->resize)
92                         sf->resize(cols, rows);
93         }
94 }
96 const char *
97 screen_get_name(const struct screen_functions *sf)
98 {
99         unsigned i;
101         for (i = 0; i < NUM_SCREENS; ++i)
102                 if (screens[i].functions == sf)
103                         return screens[i].name;
105         return NULL;
108 const struct screen_functions *
109 screen_lookup_name(const char *name)
111         unsigned i;
113         for (i = 0; i < NUM_SCREENS; ++i)
114                 if (strcmp(name, screens[i].name) == 0)
115                         return screens[i].functions;
117         return NULL;