f8438dccaa3f5b7b34be579c8838fef85b739bfb
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 "config.h"
21 #include "i18n.h"
22 #include "mpdclient.h"
23 #include "command.h"
24 #include "screen.h"
25 #include "screen_utils.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
31 typedef struct {
32 signed char highlight;
33 command_t command;
34 const char *text;
35 } help_text_row_t;
37 static help_text_row_t help_text[] = {
38 { 1, CMD_NONE, N_("Movement") },
39 { 2, CMD_NONE, NULL },
40 { 0, CMD_LIST_PREVIOUS, NULL },
41 { 0, CMD_LIST_NEXT, NULL },
42 { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
43 { 0, CMD_LIST_NEXT_PAGE, NULL },
44 { 0, CMD_LIST_FIRST, NULL },
45 { 0, CMD_LIST_LAST, NULL },
46 { 0, CMD_LIST_VISUAL_SELECT, NULL },
47 { 0, CMD_NONE, NULL },
48 { 0, CMD_SCREEN_PREVIOUS,NULL },
49 { 0, CMD_SCREEN_NEXT, NULL },
50 { 0, CMD_SCREEN_HELP, NULL },
51 { 0, CMD_SCREEN_PLAY, NULL },
52 { 0, CMD_SCREEN_FILE, NULL },
53 #ifdef ENABLE_ARTIST_SCREEN
54 { 0, CMD_SCREEN_ARTIST, NULL },
55 #endif
56 #ifdef ENABLE_SEARCH_SCREEN
57 { 0, CMD_SCREEN_SEARCH, NULL },
58 #endif
59 #ifdef ENABLE_KEYDEF_SCREEN
60 { 0, CMD_SCREEN_KEYDEF, NULL },
61 #endif
63 { 0, CMD_NONE, NULL },
64 { 0, CMD_NONE, NULL },
65 { 1, CMD_NONE, N_("Global") },
66 { 2, CMD_NONE, NULL },
67 { 0, CMD_STOP, NULL },
68 { 0, CMD_PAUSE, NULL },
69 { 0, CMD_CROP, NULL },
70 { 0, CMD_TRACK_NEXT, NULL },
71 { 0, CMD_TRACK_PREVIOUS, NULL },
72 { 0, CMD_SEEK_FORWARD, NULL },
73 { 0, CMD_SEEK_BACKWARD, NULL },
74 { 0, CMD_VOLUME_DOWN, NULL },
75 { 0, CMD_VOLUME_UP, NULL },
76 { 0, CMD_NONE, NULL },
77 { 0, CMD_REPEAT, NULL },
78 { 0, CMD_RANDOM, NULL },
79 { 0, CMD_CROSSFADE, NULL },
80 { 0, CMD_SHUFFLE, NULL },
81 { 0, CMD_DB_UPDATE, NULL },
82 { 0, CMD_NONE, NULL },
83 { 0, CMD_LIST_FIND, NULL },
84 { 0, CMD_LIST_RFIND, NULL },
85 { 0, CMD_LIST_FIND_NEXT, NULL },
86 { 0, CMD_LIST_RFIND_NEXT, NULL },
87 { 0, CMD_LIST_JUMP, NULL },
88 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
89 { 0, CMD_LOCATE, NULL },
90 { 0, CMD_VIEW, NULL },
91 { 0, CMD_NONE, NULL },
92 { 0, CMD_QUIT, NULL },
94 { 0, CMD_NONE, NULL },
95 { 0, CMD_NONE, NULL },
96 { 1, CMD_NONE, N_("Playlist screen") },
97 { 2, CMD_NONE, NULL },
98 { 0, CMD_PLAY, N_("Play") },
99 { 0, CMD_DELETE, NULL },
100 { 0, CMD_CLEAR, NULL },
101 { 0, CMD_LIST_MOVE_UP, N_("Move song up") },
102 { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
103 { 0, CMD_ADD, NULL },
104 { 0, CMD_SAVE_PLAYLIST, NULL },
105 { 0, CMD_SCREEN_UPDATE, N_("Center") },
106 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
108 { 0, CMD_NONE, NULL },
109 { 0, CMD_NONE, NULL },
110 { 1, CMD_NONE, N_("Browse screen") },
111 { 2, CMD_NONE, NULL },
112 { 0, CMD_PLAY, N_("Enter directory/Select and play song") },
113 { 0, CMD_SELECT, NULL },
114 { 0, CMD_ADD, N_("Append song to playlist") },
115 { 0, CMD_SAVE_PLAYLIST, NULL },
116 { 0, CMD_DELETE, N_("Delete playlist") },
117 { 0, CMD_GO_PARENT_DIRECTORY, NULL },
118 { 0, CMD_GO_ROOT_DIRECTORY, NULL },
119 { 0, CMD_SCREEN_UPDATE, NULL },
121 #ifdef ENABLE_SEARCH_SCREEN
122 { 0, CMD_NONE, NULL },
123 { 0, CMD_NONE, NULL },
124 { 1, CMD_NONE, N_("Search screen") },
125 { 2, CMD_NONE, NULL },
126 { 0, CMD_SCREEN_SEARCH, N_("Search") },
127 { 0, CMD_PLAY, N_("Select and play") },
128 { 0, CMD_SELECT, NULL },
129 { 0, CMD_ADD, N_("Append song to playlist") },
130 { 0, CMD_SELECT_ALL, NULL },
131 { 0, CMD_SEARCH_MODE, NULL },
132 #endif
133 #ifdef ENABLE_LYRICS_SCREEN
134 { 0, CMD_NONE, NULL },
135 { 0, CMD_NONE, NULL },
136 { 1, CMD_NONE, N_("Lyrics screen") },
137 { 2, CMD_NONE, NULL },
138 { 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
139 { 0, CMD_SELECT, N_("(Re)load lyrics") },
140 { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
141 { 0, CMD_LYRICS_UPDATE, N_("Explicitly download lyrics") },
142 { 0, CMD_ADD, N_("Save lyrics") },
143 #endif
144 #ifdef ENABLE_OUTPUTS_SCREEN
145 { 0, CMD_NONE, NULL },
146 { 0, CMD_NONE, NULL },
147 { 1, CMD_NONE, N_("Outputs screen") },
148 { 2, CMD_NONE, NULL },
149 { 0, CMD_PLAY, N_("Enable/disable output") },
150 #endif
151 };
153 #define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
155 static list_window_t *lw;
157 static const char *
158 list_callback(unsigned idx, bool *highlight, G_GNUC_UNUSED void *data)
159 {
160 static char buf[512];
162 if (idx >= help_text_rows)
163 return NULL;
165 if (help_text[idx].highlight)
166 *highlight = true;
168 if (help_text[idx].command == CMD_NONE) {
169 if (help_text[idx].text)
170 g_snprintf(buf, sizeof(buf), " %s", _(help_text[idx].text));
171 else if (help_text[idx].highlight == 2) {
172 int i;
174 for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
175 buf[i] = '-';
176 buf[i] = '\0';
177 } else
178 g_strlcpy(buf, " ", sizeof(buf));
179 return buf;
180 }
182 if (help_text[idx].text)
183 g_snprintf(buf, sizeof(buf),
184 "%20s : %s ",
185 get_key_names(help_text[idx].command, TRUE),
186 _(help_text[idx].text));
187 else
188 g_snprintf(buf, sizeof(buf),
189 "%20s : %s ",
190 get_key_names(help_text[idx].command, TRUE),
191 get_key_description(help_text[idx].command));
192 return buf;
193 }
195 static void
196 help_init(WINDOW *w, int cols, int rows)
197 {
198 lw = list_window_init(w, cols, rows);
199 lw->hide_cursor = true;
200 }
202 static void
203 help_resize(int cols, int rows)
204 {
205 lw->cols = cols;
206 lw->rows = rows;
207 }
209 static void
210 help_exit(void)
211 {
212 list_window_free(lw);
213 }
216 static const char *
217 help_title(G_GNUC_UNUSED char *str, G_GNUC_UNUSED size_t size)
218 {
219 return _("Help");
220 }
222 static void
223 help_paint(void)
224 {
225 list_window_paint(lw, list_callback, NULL);
226 }
228 static bool
229 help_cmd(G_GNUC_UNUSED mpdclient_t *c, command_t cmd)
230 {
231 if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
232 list_window_paint(lw, list_callback, NULL);
233 wrefresh(lw->w);
234 return true;
235 }
237 lw->selected = lw->start+lw->rows;
238 if (screen_find(lw, help_text_rows,
239 cmd, list_callback, NULL)) {
240 /* center the row */
241 list_window_center(lw, help_text_rows, lw->selected);
242 list_window_paint(lw, list_callback, NULL);
243 wrefresh(lw->w);
244 return true;
245 }
247 return false;
248 }
250 const struct screen_functions screen_help = {
251 .init = help_init,
252 .exit = help_exit,
253 .resize = help_resize,
254 .paint = help_paint,
255 .cmd = help_cmd,
256 .get_title = help_title,
257 };