Code

moved struct screen_functions to screen_interface.h
[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_interface.h"
22 #include "screen.h"
24 #include <string.h>
26 static const struct
27 {
28         const char *name;
29         const struct screen_functions *functions;
30 } screens[] = {
31         { "playlist", &screen_playlist },
32         { "browse", &screen_browse },
33 #ifdef ENABLE_ARTIST_SCREEN
34         { "artist", &screen_artist },
35 #endif
36 #ifdef ENABLE_HELP_SCREEN
37         { "help", &screen_help },
38 #endif
39 #ifdef ENABLE_SEARCH_SCREEN
40         { "search", &screen_search },
41 #endif
42 #ifdef ENABLE_SONG_SCREEN
43         { "song", &screen_song },
44 #endif
45 #ifdef ENABLE_KEYDEF_SCREEN
46         { "keydef", &screen_keydef },
47 #endif
48 #ifdef ENABLE_LYRICS_SCREEN
49         { "lyrics", &screen_lyrics },
50 #endif
51 #ifdef ENABLE_OUTPUTS_SCREEN
52         { "outputs", &screen_outputs },
53 #endif
54 };
56 static const unsigned NUM_SCREENS = sizeof(screens) / sizeof(screens[0]);
58 void
59 screen_list_init(WINDOW *w, unsigned cols, unsigned rows)
60 {
61         unsigned i;
63         for (i = 0; i < NUM_SCREENS; ++i) {
64                 const struct screen_functions *sf = screens[i].functions;
66                 if (sf->init)
67                         sf->init(w, cols, rows);
68         }
69 }
71 void
72 screen_list_exit(void)
73 {
74         unsigned i;
76         for (i = 0; i < NUM_SCREENS; ++i) {
77                 const struct screen_functions *sf = screens[i].functions;
79                 if (sf->exit)
80                         sf->exit();
81         }
82 }
84 void
85 screen_list_resize(unsigned cols, unsigned rows)
86 {
87         unsigned i;
89         for (i = 0; i < NUM_SCREENS; ++i) {
90                 const struct screen_functions *sf = screens[i].functions;
92                 if (sf->resize)
93                         sf->resize(cols, rows);
94         }
95 }
97 const char *
98 screen_get_name(const struct screen_functions *sf)
99 {
100         unsigned i;
102         for (i = 0; i < NUM_SCREENS; ++i)
103                 if (screens[i].functions == sf)
104                         return screens[i].name;
106         return NULL;
109 const struct screen_functions *
110 screen_lookup_name(const char *name)
112         unsigned i;
114         for (i = 0; i < NUM_SCREENS; ++i)
115                 if (strcmp(name, screens[i].name) == 0)
116                         return screens[i].functions;
118         return NULL;