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