1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2009 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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_help.h"
21 #include "screen_interface.h"
22 #include "screen_find.h"
23 #include "config.h"
24 #include "i18n.h"
26 #include <glib.h>
28 #include <assert.h>
30 struct help_text_row {
31 signed char highlight;
32 command_t command;
33 const char *text;
34 };
36 static const struct help_text_row help_text[] = {
37 { 1, CMD_NONE, N_("Movement") },
38 { 2, CMD_NONE, NULL },
39 { 0, CMD_LIST_PREVIOUS, NULL },
40 { 0, CMD_LIST_NEXT, NULL },
41 { 0, CMD_LIST_TOP, NULL },
42 { 0, CMD_LIST_MIDDLE, NULL },
43 { 0, CMD_LIST_BOTTOM, NULL },
44 { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
45 { 0, CMD_LIST_NEXT_PAGE, NULL },
46 { 0, CMD_LIST_FIRST, NULL },
47 { 0, CMD_LIST_LAST, NULL },
48 { 0, CMD_LIST_RANGE_SELECT, NULL },
49 { 0, CMD_LIST_SCROLL_UP_LINE, NULL},
50 { 0, CMD_LIST_SCROLL_DOWN_LINE, NULL},
51 { 0, CMD_LIST_SCROLL_UP_HALF, NULL},
52 { 0, CMD_LIST_SCROLL_DOWN_HALF, NULL},
53 { 0, CMD_NONE, NULL },
55 { 0, CMD_SCREEN_PREVIOUS,NULL },
56 { 0, CMD_SCREEN_NEXT, NULL },
57 { 0, CMD_SCREEN_SWAP, NULL },
58 { 0, CMD_SCREEN_HELP, NULL },
59 { 0, CMD_SCREEN_PLAY, NULL },
60 { 0, CMD_SCREEN_FILE, NULL },
61 #ifdef ENABLE_ARTIST_SCREEN
62 { 0, CMD_SCREEN_ARTIST, NULL },
63 #endif
64 #ifdef ENABLE_SEARCH_SCREEN
65 { 0, CMD_SCREEN_SEARCH, NULL },
66 #endif
67 #ifdef ENABLE_LYRICS_SCREEN
68 { 0, CMD_SCREEN_LYRICS, NULL },
69 #endif
70 #ifdef ENABLE_OUTPUTS_SCREEN
71 { 0, CMD_SCREEN_OUTPUTS, NULL },
72 #endif
73 #ifdef ENABLE_KEYDEF_SCREEN
74 { 0, CMD_SCREEN_KEYDEF, NULL },
75 #endif
77 { 0, CMD_NONE, NULL },
78 { 0, CMD_NONE, NULL },
79 { 1, CMD_NONE, N_("Global") },
80 { 2, CMD_NONE, NULL },
81 { 0, CMD_STOP, NULL },
82 { 0, CMD_PAUSE, NULL },
83 { 0, CMD_CROP, NULL },
84 { 0, CMD_TRACK_NEXT, NULL },
85 { 0, CMD_TRACK_PREVIOUS, NULL },
86 { 0, CMD_SEEK_FORWARD, NULL },
87 { 0, CMD_SEEK_BACKWARD, NULL },
88 { 0, CMD_VOLUME_DOWN, NULL },
89 { 0, CMD_VOLUME_UP, NULL },
90 { 0, CMD_NONE, NULL },
91 { 0, CMD_REPEAT, NULL },
92 { 0, CMD_RANDOM, NULL },
93 { 0, CMD_SINGLE, NULL },
94 { 0, CMD_CONSUME, NULL },
95 { 0, CMD_CROSSFADE, NULL },
96 { 0, CMD_SHUFFLE, NULL },
97 { 0, CMD_DB_UPDATE, NULL },
98 { 0, CMD_NONE, NULL },
99 { 0, CMD_LIST_FIND, NULL },
100 { 0, CMD_LIST_RFIND, NULL },
101 { 0, CMD_LIST_FIND_NEXT, NULL },
102 { 0, CMD_LIST_RFIND_NEXT, NULL },
103 { 0, CMD_LIST_JUMP, NULL },
104 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
105 { 0, CMD_LOCATE, NULL },
106 { 0, CMD_SCREEN_SONG, NULL },
107 { 0, CMD_NONE, NULL },
108 { 0, CMD_QUIT, NULL },
110 { 0, CMD_NONE, NULL },
111 { 0, CMD_NONE, NULL },
112 { 1, CMD_NONE, N_("Playlist screen") },
113 { 2, CMD_NONE, NULL },
114 { 0, CMD_PLAY, N_("Play") },
115 { 0, CMD_DELETE, NULL },
116 { 0, CMD_CLEAR, NULL },
117 { 0, CMD_LIST_MOVE_UP, N_("Move song up") },
118 { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
119 { 0, CMD_ADD, NULL },
120 { 0, CMD_SAVE_PLAYLIST, NULL },
121 { 0, CMD_SCREEN_UPDATE, N_("Center") },
122 { 0, CMD_SELECT_PLAYING, NULL },
123 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
125 { 0, CMD_NONE, NULL },
126 { 0, CMD_NONE, NULL },
127 { 1, CMD_NONE, N_("Browse screen") },
128 { 2, CMD_NONE, NULL },
129 { 0, CMD_PLAY, N_("Enter directory/Select and play song") },
130 { 0, CMD_SELECT, NULL },
131 { 0, CMD_ADD, N_("Append song to playlist") },
132 { 0, CMD_SAVE_PLAYLIST, NULL },
133 { 0, CMD_DELETE, N_("Delete playlist") },
134 { 0, CMD_GO_PARENT_DIRECTORY, NULL },
135 { 0, CMD_GO_ROOT_DIRECTORY, NULL },
136 { 0, CMD_SCREEN_UPDATE, NULL },
138 #ifdef ENABLE_SEARCH_SCREEN
139 { 0, CMD_NONE, NULL },
140 { 0, CMD_NONE, NULL },
141 { 1, CMD_NONE, N_("Search screen") },
142 { 2, CMD_NONE, NULL },
143 { 0, CMD_SCREEN_SEARCH, N_("Search") },
144 { 0, CMD_PLAY, N_("Select and play") },
145 { 0, CMD_SELECT, NULL },
146 { 0, CMD_ADD, N_("Append song to playlist") },
147 { 0, CMD_SELECT_ALL, NULL },
148 { 0, CMD_SEARCH_MODE, NULL },
149 #endif
150 #ifdef ENABLE_LYRICS_SCREEN
151 { 0, CMD_NONE, NULL },
152 { 0, CMD_NONE, NULL },
153 { 1, CMD_NONE, N_("Lyrics screen") },
154 { 2, CMD_NONE, NULL },
155 { 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
156 { 0, CMD_SELECT, N_("(Re)load lyrics") },
157 /* to translators: this hotkey aborts the retrieval of lyrics
158 from the server */
159 { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
160 { 0, CMD_LYRICS_UPDATE, N_("Download lyrics for currently playing song") },
161 { 0, CMD_SAVE_PLAYLIST, N_("Save lyrics") },
162 #endif
163 #ifdef ENABLE_OUTPUTS_SCREEN
164 { 0, CMD_NONE, NULL },
165 { 0, CMD_NONE, NULL },
166 { 1, CMD_NONE, N_("Outputs screen") },
167 { 2, CMD_NONE, NULL },
168 { 0, CMD_PLAY, N_("Enable/disable output") },
169 #endif
170 #ifdef ENABLE_KEYDEF_SCREEN
171 { 0, CMD_NONE, NULL },
172 { 0, CMD_NONE, NULL },
173 { 1, CMD_NONE, N_("Keydef screen") },
174 { 2, CMD_NONE, NULL },
175 { 0, CMD_PLAY, N_("Edit keydefs for selected command") },
176 { 0, CMD_DELETE, N_("Remove selected keydef") },
177 { 0, CMD_GO_PARENT_DIRECTORY, N_("Go up a level") },
178 { 0, CMD_SAVE_PLAYLIST, N_("Apply and save changes") },
179 #endif
180 };
182 static struct list_window *lw;
184 static const char *
185 list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED char** second_column, G_GNUC_UNUSED void *data)
186 {
187 static char buf[512];
189 assert(idx < G_N_ELEMENTS(help_text));
191 if (help_text[idx].highlight)
192 *highlight = true;
194 if (help_text[idx].command == CMD_NONE) {
195 if (help_text[idx].text)
196 g_snprintf(buf, sizeof(buf), " %s", _(help_text[idx].text));
197 else if (help_text[idx].highlight == 2) {
198 int i;
200 for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
201 buf[i] = '-';
202 buf[i] = '\0';
203 } else
204 g_strlcpy(buf, " ", sizeof(buf));
205 return buf;
206 }
208 if (help_text[idx].text)
209 g_snprintf(buf, sizeof(buf),
210 "%20s : %s ",
211 get_key_names(help_text[idx].command, TRUE),
212 _(help_text[idx].text));
213 else
214 g_snprintf(buf, sizeof(buf),
215 "%20s : %s ",
216 get_key_names(help_text[idx].command, TRUE),
217 get_key_description(help_text[idx].command));
218 return buf;
219 }
221 static void
222 help_init(WINDOW *w, int cols, int rows)
223 {
224 lw = list_window_init(w, cols, rows);
225 lw->hide_cursor = true;
226 list_window_set_length(lw, G_N_ELEMENTS(help_text));
227 }
229 static void
230 help_resize(int cols, int rows)
231 {
232 list_window_resize(lw, cols, rows);
233 }
235 static void
236 help_exit(void)
237 {
238 list_window_free(lw);
239 }
242 static const char *
243 help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
244 {
245 return _("Help");
246 }
248 static void
249 help_paint(void)
250 {
251 list_window_paint(lw, list_callback, NULL);
252 }
254 static bool
255 help_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
256 {
257 if (list_window_scroll_cmd(lw, cmd)) {
258 help_paint();
259 wrefresh(lw->w);
260 return true;
261 }
263 list_window_set_cursor(lw, lw->start);
264 if (screen_find(lw, cmd, list_callback, NULL)) {
265 /* center the row */
266 list_window_center(lw, lw->selected);
267 help_paint();
268 wrefresh(lw->w);
269 return true;
270 }
272 return false;
273 }
275 const struct screen_functions screen_help = {
276 .init = help_init,
277 .exit = help_exit,
278 .resize = help_resize,
279 .paint = help_paint,
280 .cmd = help_cmd,
281 .get_title = help_title,
282 };