0299d6ca418caaf1bb2407b33a04da3a1ca642e1
1 /*
2 * (c) 2004 by Kalle Wallin (kaw@linux.se)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
19 #include <stdlib.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <ncurses.h>
24 #include "config.h"
25 #include "ncmpc.h"
26 #include "libmpdclient.h"
27 #include "mpc.h"
28 #include "command.h"
29 #include "screen.h"
30 #include "screen_utils.h"
31 #include "screen_help.h"
34 typedef struct
35 {
36 signed char highlight;
37 command_t command;
38 char *text;
39 } help_text_row_t;
41 static help_text_row_t help_text[] =
42 {
43 { 1, CMD_NONE, N_("Keys - Movement") },
44 { 2, CMD_NONE, NULL },
45 { 0, CMD_LIST_PREVIOUS, NULL },
46 { 0, CMD_LIST_NEXT, NULL },
47 { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
48 { 0, CMD_LIST_NEXT_PAGE, NULL },
49 { 0, CMD_LIST_FIRST, NULL },
50 { 0, CMD_LIST_LAST, NULL },
51 { 0, CMD_NONE, NULL },
52 { 0, CMD_SCREEN_NEXT, NULL },
53 { 0, CMD_SCREEN_HELP, NULL },
54 { 0, CMD_SCREEN_PLAY, NULL },
55 { 0, CMD_SCREEN_FILE, NULL },
56 #ifdef ENABLE_CLOCK_SCREEN
57 { 0, CMD_SCREEN_CLOCK, 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_("Keys - Global") },
66 { 2, CMD_NONE, NULL },
67 { 0, CMD_STOP, NULL },
68 { 0, CMD_PAUSE, NULL },
69 { 0, CMD_TRACK_NEXT, NULL },
70 { 0, CMD_TRACK_PREVIOUS, NULL },
71 { 0, CMD_SEEK_FORWARD, NULL },
72 { 0, CMD_SEEK_BACKWARD, NULL },
73 { 0, CMD_VOLUME_DOWN, NULL },
74 { 0, CMD_VOLUME_UP, NULL },
75 { 0, CMD_NONE, NULL },
76 { 0, CMD_REPEAT, NULL },
77 { 0, CMD_RANDOM, NULL },
78 { 0, CMD_CROSSFADE, NULL },
79 { 0, CMD_SHUFFLE, NULL },
80 { 0, CMD_DB_UPDATE, NULL },
81 { 0, CMD_NONE, NULL },
82 { 0, CMD_LIST_FIND, NULL },
83 { 0, CMD_LIST_RFIND, NULL },
84 { 0, CMD_LIST_FIND_NEXT, NULL },
85 { 0, CMD_LIST_RFIND_NEXT, NULL },
86 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
87 { 0, CMD_NONE, NULL },
88 { 0, CMD_QUIT, NULL },
90 { 0, CMD_NONE, NULL },
91 { 0, CMD_NONE, NULL },
92 { 1, CMD_NONE, N_("Keys - Playlist screen") },
93 { 2, CMD_NONE, NULL },
94 { 0, CMD_PLAY, N_("Play") },
95 { 0, CMD_DELETE, NULL },
96 { 0, CMD_CLEAR, NULL },
97 { 0, CMD_LIST_MOVE_UP, N_("Move song up") },
98 { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
99 { 0, CMD_SAVE_PLAYLIST, NULL },
100 { 0, CMD_SCREEN_UPDATE, N_("Center") },
101 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
103 { 0, CMD_NONE, NULL },
104 { 0, CMD_NONE, NULL },
105 { 1, CMD_NONE, N_("Keys - Browse screen") },
106 { 2, CMD_NONE, NULL },
107 { 0, CMD_PLAY, N_("Enter directory") },
108 { 0, CMD_SELECT, NULL },
109 { 0, CMD_DELETE, NULL },
110 { 0, CMD_SCREEN_UPDATE, NULL },
112 { 0, CMD_NONE, NULL },
113 { 0, CMD_NONE, NULL },
114 { 1, CMD_NONE, "ncmpc build information" },
115 { 2, CMD_NONE, NULL },
116 { 0, CMD_NONE, " Version : " VERSION },
117 { 0, CMD_NONE, " Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
118 #ifdef ENABLE_NLS
119 { 0, CMD_NONE, "NLS support : yes" },
120 #else
121 { 0, CMD_NONE, "NLS support : no" },
122 #endif
123 #ifdef ENABLE_KEYDEF_SCREEN
124 { 0, CMD_NONE, "Key Editor : yes" },
125 #else
126 { 0, CMD_NONE, "Key Editor : no" },
127 #endif
129 { 0, CMD_NONE, NULL },
130 {-1, CMD_NONE, NULL }
131 };
133 static int help_text_rows = -1;
134 static list_window_t *lw = NULL;
137 static char *
138 list_callback(int index, int *highlight, void *data)
139 {
140 static char buf[256];
142 if( help_text_rows<0 )
143 {
144 help_text_rows = 0;
145 while( help_text[help_text_rows].highlight != -1 )
146 help_text_rows++;
147 }
149 *highlight = 0;
150 if( index<help_text_rows )
151 {
152 *highlight = help_text[index].highlight > 0;
153 if( help_text[index].command == CMD_NONE )
154 {
155 if( help_text[index].text )
156 snprintf(buf, 256, "%28s", _(help_text[index].text));
157 else
158 if( help_text[index].highlight == 2 )
159 {
160 int i;
162 for(i=3; i<COLS-3 && i<256; i++)
163 buf[i]='-';
164 buf[i] = '\0';
165 }
166 else
167 strcpy(buf, " ");
168 return buf;
169 }
170 if( help_text[index].text )
171 snprintf(buf, 256,
172 "%20s : %s ",
173 get_key_names(help_text[index].command, TRUE),
174 _(help_text[index].text));
175 else
176 snprintf(buf, 256,
177 "%20s : %s ",
178 get_key_names(help_text[index].command, TRUE),
179 get_key_description(help_text[index].command));
180 return buf;
181 }
183 return NULL;
184 }
186 static void
187 help_init(WINDOW *w, int cols, int rows)
188 {
189 lw = list_window_init(w, cols, rows);
190 }
192 static void
193 help_resize(int cols, int rows)
194 {
195 lw->cols = cols;
196 lw->rows = rows;
197 }
199 static void
200 help_exit(void)
201 {
202 list_window_free(lw);
203 }
206 static char *
207 help_title(void)
208 {
209 return _("Music Player Client - Help");
210 }
212 static void
213 help_paint(screen_t *screen, mpd_client_t *c)
214 {
215 lw->clear = 1;
216 list_window_paint(lw, list_callback, NULL);
217 wrefresh(lw->w);
218 }
220 static void
221 help_update(screen_t *screen, mpd_client_t *c)
222 {
223 if( lw->repaint )
224 {
225 list_window_paint(lw, list_callback, NULL);
226 wrefresh(lw->w);
227 lw->repaint = 0;
228 }
229 }
232 static int
233 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
234 {
235 int retval;
237 retval = list_window_cmd(lw, help_text_rows, cmd);
238 if( !retval )
239 return screen_find(screen, c,
240 lw, help_text_rows,
241 cmd, list_callback);
243 return retval;
244 }
246 static list_window_t *
247 help_lw(void)
248 {
249 return lw;
250 }
252 screen_functions_t *
253 get_screen_help(void)
254 {
255 static screen_functions_t functions;
257 memset(&functions, 0, sizeof(screen_functions_t));
258 functions.init = help_init;
259 functions.exit = help_exit;
260 functions.open = NULL;
261 functions.close = NULL;
262 functions.resize = help_resize;
263 functions.paint = help_paint;
264 functions.update = help_update;
265 functions.cmd = help_cmd;
266 functions.get_lw = help_lw;
267 functions.get_title = help_title;
269 return &functions;
270 }