plugin: convert plugin_fd_add() to method
[ncmpc-debian.git] / src / screen_list.cxx
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2019 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  */
19
20 #include "screen_list.hxx"
21 #include "PageMeta.hxx"
22 #include "HelpPage.hxx"
23 #include "QueuePage.hxx"
24 #include "FileBrowserPage.hxx"
25 #include "LibraryPage.hxx"
26 #include "SearchPage.hxx"
27 #include "SongPage.hxx"
28 #include "screen_keydef.hxx"
29 #include "LyricsPage.hxx"
30 #include "OutputsPage.hxx"
31 #include "ChatPage.hxx"
32 #include "util/Macros.hxx"
33 #include "config.h"
34
35 #include <string.h>
36
37 static const PageMeta *const screens[] = {
38 #ifdef ENABLE_HELP_SCREEN
39         &screen_help,
40 #endif
41         &screen_queue,
42         &screen_browse,
43 #ifdef ENABLE_LIBRARY_PAGE
44         &library_page,
45 #endif
46 #ifdef ENABLE_SEARCH_SCREEN
47         &screen_search,
48 #endif
49 #ifdef ENABLE_LYRICS_SCREEN
50         &screen_lyrics,
51 #endif
52 #ifdef ENABLE_OUTPUTS_SCREEN
53         &screen_outputs,
54 #endif
55 #ifdef ENABLE_CHAT_SCREEN
56         &screen_chat,
57 #endif
58 #ifdef ENABLE_SONG_SCREEN
59         &screen_song,
60 #endif
61 #ifdef ENABLE_KEYDEF_SCREEN
62         &screen_keydef,
63 #endif
64 };
65
66 const PageMeta *
67 GetPageMeta(unsigned i) noexcept
68 {
69         return i < ARRAY_SIZE(screens)
70                    ? screens[i]
71                    : nullptr;
72 }
73
74 const PageMeta *
75 screen_lookup_name(const char *name) noexcept
76 {
77         for (const auto *i : screens)
78                 if (strcmp(name, i->name) == 0)
79                         return i;
80
81 #ifdef ENABLE_LIBRARY_PAGE
82         /* compatibility with 0.32 and older */
83         if (strcmp(name, "artist") == 0)
84                 return &library_page;
85 #endif
86
87         return nullptr;
88 }
89
90 const PageMeta *
91 PageByCommand(Command cmd) noexcept
92 {
93         for (const auto *i : screens)
94                 if (i->command == cmd)
95                         return i;
96
97         return nullptr;
98 }