Code

configure.ac: require libmpdclient 2.3
[ncmpc.git] / src / screen_list.c
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"
32 #include "screen_chat.h"
34 #include <string.h>
36 static const struct
37 {
38         const char *name;
39         const struct screen_functions *functions;
40 } screens[] = {
41         { "playlist", &screen_queue },
42         { "browse", &screen_browse },
43 #ifdef ENABLE_ARTIST_SCREEN
44         { "artist", &screen_artist },
45 #endif
46 #ifdef ENABLE_HELP_SCREEN
47         { "help", &screen_help },
48 #endif
49 #ifdef ENABLE_SEARCH_SCREEN
50         { "search", &screen_search },
51 #endif
52 #ifdef ENABLE_SONG_SCREEN
53         { "song", &screen_song },
54 #endif
55 #ifdef ENABLE_KEYDEF_SCREEN
56         { "keydef", &screen_keydef },
57 #endif
58 #ifdef ENABLE_LYRICS_SCREEN
59         { "lyrics", &screen_lyrics },
60 #endif
61 #ifdef ENABLE_OUTPUTS_SCREEN
62         { "outputs", &screen_outputs },
63 #endif
64 #ifdef ENABLE_CHAT_SCREEN
65         { "chat", &screen_chat },
66 #endif
67 };
69 void
70 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
71 {
72         unsigned i;
74         for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
75                 const struct screen_functions *sf = screens[i].functions;
77                 if (sf->init)
78                         sf->init(w, cols, rows);
79         }
80 }
82 void
83 screen_list_exit(void)
84 {
85         unsigned i;
87         for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
88                 const struct screen_functions *sf = screens[i].functions;
90                 if (sf->exit)
91                         sf->exit();
92         }
93 }
95 void
96 screen_list_resize(unsigned cols, unsigned rows)
97 {
98         unsigned i;
100         for (i = 0; i < G_N_ELEMENTS(screens); ++i) {
101                 const struct screen_functions *sf = screens[i].functions;
103                 if (sf->resize)
104                         sf->resize(cols, rows);
105         }
108 const char *
109 screen_get_name(const struct screen_functions *sf)
111         unsigned i;
113         for (i = 0; i < G_N_ELEMENTS(screens); ++i)
114                 if (screens[i].functions == sf)
115                         return screens[i].name;
117         return NULL;
120 const struct screen_functions *
121 screen_lookup_name(const char *name)
123         unsigned i;
125         for (i = 0; i < G_N_ELEMENTS(screens); ++i)
126                 if (strcmp(name, screens[i].name) == 0)
127                         return screens[i].functions;
129         return NULL;