plugin: convert plugin_fd_add() to method
[ncmpc-debian.git] / src / Command.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 "Command.hxx"
21 #include "i18n.h"
22 #include "util/Macros.hxx"
23
24 #include <string.h>
25
26 static constexpr command_definition_t cmds[] = {
27 #ifdef ENABLE_KEYDEF_SCREEN
28         { "screen-keyedit",
29           N_("Key configuration screen") },
30 #endif
31         { "quit",
32           N_("Quit") },
33
34         /* movement */
35         { "up",
36           N_("Move cursor up") },
37         { "down",
38           N_("Move cursor down") },
39         { "top",
40           N_("Move cursor to the top of screen") },
41         { "middle",
42           N_("Move cursor to the middle of screen") },
43         { "bottom",
44           N_("Move cursor to the bottom of screen") },
45         { "home",
46           N_("Move cursor to the top of the list") },
47         { "end",
48           N_("Move cursor to the bottom of the list") },
49         { "pgup",
50           N_("Page up") },
51         { "pgdn",
52           N_("Page down") },
53         { "range-select",
54           N_("Range selection") },
55         { "scroll-down-line",
56           N_("Scroll down one line") },
57         { "scroll-up-line",
58           N_("Scroll up one line") },
59         { "scroll-down-half",
60           N_("Scroll up half a screen") },
61         { "scroll-up-half",
62           N_("Scroll down half a screen") },
63         { "select-playing",
64           N_("Select currently playing song") },
65
66
67         /* basic screens */
68         { "screen-help",
69           N_("Help screen") },
70         { "screen-playlist",
71           N_("Queue screen") },
72         { "screen-browse",
73           N_("Browse screen") },
74
75
76         /* player commands */
77         { "play",
78           N_("Play/Enter directory") },
79         { "pause",
80           N_("Pause") },
81         { "stop",
82           N_("Stop") },
83         { "crop",
84           N_("Crop") },
85         { "next",
86           N_("Next track") },
87         { "prev",
88           N_("Previous track") },
89         { "seek-forward",
90           N_("Seek forward") },
91         { "seek-backward",
92           N_("Seek backward") },
93         { "volume-up",
94           N_("Increase volume") },
95         { "volume-down",
96           N_("Decrease volume") },
97         { "select",
98           N_("Select/deselect song in queue") },
99         { "select_all",
100           N_("Select all listed items") },
101         { "delete",
102           N_("Delete song from queue") },
103         { "shuffle",
104           N_("Shuffle queue") },
105         { "clear",
106           N_("Clear queue") },
107         { "repeat",
108           N_("Toggle repeat mode") },
109         { "random",
110           N_("Toggle random mode") },
111         { "single",
112           N_("Toggle single mode") },
113         { "consume",
114           N_("Toggle consume mode") },
115         { "crossfade",
116           N_("Toggle crossfade mode") },
117         { "db-update",
118           N_("Start a music database update") },
119         { "save",
120           N_("Save queue") },
121         { "add",
122           N_("Append song to queue") },
123
124         { "go-root-directory",
125           N_("Go to root directory") },
126         { "go-parent-directory",
127           N_("Go to parent directory") },
128
129         { "locate",
130           N_("Locate song in browser") },
131
132         /* lists */
133         { "move-up",
134           N_("Move item up") },
135         { "move-down",
136           N_("Move item down") },
137         { "update",
138           N_("Refresh screen") },
139
140
141         /* ncmpc options */
142         { "wrap-mode",
143           /* translators: toggle between wrapping and non-wrapping
144              search */
145           N_("Toggle find mode") },
146         { "autocenter-mode",
147           /* translators: the auto center mode always centers the song
148              currently being played */
149           N_("Toggle auto center mode") },
150
151
152         /* change screen */
153         { "screen-next",
154           N_("Next screen") },
155         { "screen-prev",
156           N_("Previous screen") },
157         { "screen-swap",
158           N_("Swap to most recent screen") },
159
160
161         /* find */
162         { "find",
163           N_("Forward find") },
164         { "find-next",
165           N_("Forward find next") },
166         { "rfind",
167           N_("Backward find") },
168         { "rfind-next",
169           N_("Backward find previous") },
170         { "jump",
171                 /* translators: this queries the user for a string
172                  * and jumps directly (while the user is typing)
173                  * to the entry which begins with this string */
174           N_("Jump to") },
175
176
177         /* extra screens */
178 #ifdef ENABLE_LIBRARY_PAGE
179         { "library-page",
180           N_("Library page") },
181 #endif
182 #ifdef ENABLE_SEARCH_SCREEN
183         { "screen-search",
184           N_("Search screen") },
185         { "search-mode",
186           N_("Change search mode") },
187 #endif
188 #ifdef ENABLE_SONG_SCREEN
189         { "view",
190           N_("View the selected and the currently playing song") },
191 #endif
192 #ifdef ENABLE_LYRICS_SCREEN
193         { "screen-lyrics",
194           N_("Lyrics screen") },
195         { "lyrics-interrupt",
196           /* translators: interrupt the current background action,
197              e.g. stop loading lyrics from the internet */
198           N_("Interrupt action") },
199         { "lyrics-update",
200           N_("Update Lyrics") },
201         /* this command may move out of #ifdef ENABLE_LYRICS_SCREEN
202            at some point */
203         { "edit",
204           N_("Edit the current item") },
205 #endif
206
207 #ifdef ENABLE_OUTPUTS_SCREEN
208         { "screen-outputs",
209           N_("Outputs screen") },
210 #endif
211
212 #ifdef ENABLE_CHAT_SCREEN
213         { "screen-chat",
214           N_("Chat screen") },
215 #endif
216 };
217
218 static_assert(ARRAY_SIZE(cmds) == size_t(Command::NONE),
219               "Wrong command table size");
220
221 const command_definition_t *
222 get_command_definitions()
223 {
224         return cmds;
225 }
226
227 size_t
228 get_cmds_max_name_width()
229 {
230         static size_t max = 0;
231
232         if (max != 0)
233                 return max;
234
235         for (const auto &i : cmds) {
236                 /*
237                  * width and length are considered the same here, as command
238                  * names are not translated.
239                  */
240                 size_t len = strlen(i.name);
241                 if (len > max)
242                         max = len;
243         }
244
245         return max;
246 }
247
248 const char *
249 get_key_description(Command command)
250 {
251         return gettext(cmds[size_t(command)].description);
252 }
253
254 const char *
255 get_key_command_name(Command command)
256 {
257         return cmds[size_t(command)].name;
258 }
259
260 Command
261 get_key_command_from_name(const char *name)
262 {
263         for (size_t i = 0; i < size_t(Command::NONE); ++i)
264                 if (strcmp(name, cmds[i].name) == 0)
265                         return Command(i);
266
267 #ifdef ENABLE_LIBRARY_PAGE
268         /* compatibility with 0.32 and older */
269         if (strcmp(name, "screen-artist") == 0)
270                 return Command::LIBRARY_PAGE;
271 #endif
272
273         return Command::NONE;
274 }