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 "libmpdclient.h"
26 #include "mpc.h"
27 #include "command.h"
28 #include "screen.h"
29 #include "screen_utils.h"
30 #include "screen_help.h"
33 typedef struct
34 {
35 signed char highlight;
36 command_t command;
37 char *text;
38 } help_text_row_t;
40 static help_text_row_t help_text[] =
41 {
42 { 1, CMD_NONE, " Movement keys " },
43 { 0, CMD_NONE, " -----------------" },
44 { 0, CMD_LIST_PREVIOUS, NULL },
45 { 0, CMD_LIST_NEXT, 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_NONE, NULL },
51 { 0, CMD_SCREEN_NEXT, NULL },
52 { 0, CMD_SCREEN_HELP, NULL },
53 { 0, CMD_SCREEN_PLAY, NULL },
54 { 0, CMD_SCREEN_FILE, NULL },
55 #ifdef ENABLE_KEYDEF_SCREEN
56 { 0, CMD_SCREEN_KEYDEF, NULL },
57 #endif
59 { 0, CMD_NONE, NULL },
60 { 0, CMD_NONE, NULL },
61 { 1, CMD_NONE, " General keys " },
62 { 0, CMD_NONE, " ----------------" },
63 { 0, CMD_STOP, NULL },
64 { 0, CMD_PAUSE, NULL },
65 { 0, CMD_TRACK_NEXT, NULL },
66 { 0, CMD_TRACK_PREVIOUS, NULL },
67 { 0, CMD_SEEK_FORWARD, NULL },
68 { 0, CMD_SEEK_BACKWARD, NULL },
69 { 0, CMD_VOLUME_DOWN, NULL },
70 { 0, CMD_VOLUME_UP, NULL },
71 { 0, CMD_NONE, NULL },
72 { 0, CMD_SHUFFLE, NULL },
73 { 0, CMD_REPEAT, NULL },
74 { 0, CMD_RANDOM, NULL },
75 { 0, CMD_CROSSFADE, NULL },
76 { 0, CMD_NONE, NULL },
77 { 0, CMD_QUIT, NULL },
79 { 0, CMD_NONE, NULL },
80 { 0, CMD_NONE, NULL },
81 { 1, CMD_NONE, " Keys - Playlist screen " },
82 { 0, CMD_NONE, " --------------------------" },
83 { 0, CMD_PLAY, "Play" },
84 { 0, CMD_DELETE, NULL },
85 { 0, CMD_CLEAR, NULL },
86 { 0, CMD_SAVE_PLAYLIST, NULL },
87 { 0, CMD_SCREEN_UPDATE, "Center" },
88 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
90 { 0, CMD_NONE, NULL },
91 { 0, CMD_NONE, NULL },
92 { 1, CMD_NONE, " Keys - Browse screen " },
93 { 0, CMD_NONE, " ------------------------" },
94 { 0, CMD_PLAY, "Enter directory" },
95 { 0, CMD_SELECT, NULL },
96 { 0, CMD_DELETE, NULL },
97 { 0, CMD_SCREEN_UPDATE, NULL },
99 { 0, CMD_NONE, NULL },
100 { 0, CMD_NONE, NULL },
101 { 1, CMD_NONE, " Find keys " },
102 { 0, CMD_NONE, " -------------" },
103 { 0, CMD_LIST_FIND, NULL },
104 { 0, CMD_LIST_RFIND, NULL },
105 { 0, CMD_LIST_FIND_NEXT, NULL },
106 { 0, CMD_LIST_RFIND_NEXT, NULL },
107 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
109 { 0, CMD_NONE, NULL },
110 { 0, CMD_NONE, NULL },
111 { 1, CMD_NONE, " ncmpc build information " },
112 { 0, CMD_NONE, " ---------------------------" },
113 { 0, CMD_NONE, " Version : " VERSION },
114 { 0, CMD_NONE, " Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
115 #ifdef ENABLE_KEYDEF_SCREEN
116 { 0, CMD_NONE, " Key Editor : yes" },
117 #else
118 { 0, CMD_NONE, " Key Editor : no" },
119 #endif
121 { 0, CMD_NONE, NULL },
122 {-1, CMD_NONE, NULL }
123 };
125 static int help_text_rows = -1;
126 static list_window_t *lw = NULL;
129 static char *
130 list_callback(int index, int *highlight, void *data)
131 {
132 static char buf[256];
134 if( help_text_rows<0 )
135 {
136 help_text_rows = 0;
137 while( help_text[help_text_rows].highlight != -1 )
138 help_text_rows++;
139 }
141 *highlight = 0;
142 if( index<help_text_rows )
143 {
144 *highlight = help_text[index].highlight > 0;
145 if( help_text[index].command == CMD_NONE )
146 {
147 if( help_text[index].text )
148 return help_text[index].text;
149 else
150 return " ";
151 }
152 if( help_text[index].text )
153 snprintf(buf, 256,
154 "%20s : %s ",
155 get_key_names(help_text[index].command, TRUE),
156 help_text[index].text);
157 else
158 snprintf(buf, 256,
159 "%20s : %s ",
160 get_key_names(help_text[index].command, TRUE),
161 get_key_description(help_text[index].command));
162 return buf;
163 }
165 return NULL;
166 }
168 static void
169 help_init(WINDOW *w, int cols, int rows)
170 {
171 lw = list_window_init(w, cols, rows);
172 }
174 static void
175 help_resize(int cols, int rows)
176 {
177 lw->cols = cols;
178 lw->rows = rows;
179 }
181 static void
182 help_exit(void)
183 {
184 list_window_free(lw);
185 }
188 static char *
189 help_title(void)
190 {
191 return (TOP_HEADER_PREFIX "Help");
192 }
194 static void
195 help_paint(screen_t *screen, mpd_client_t *c)
196 {
197 lw->clear = 1;
198 list_window_paint(lw, list_callback, NULL);
199 wrefresh(lw->w);
200 }
202 static void
203 help_update(screen_t *screen, mpd_client_t *c)
204 {
205 if( lw->repaint )
206 {
207 list_window_paint(lw, list_callback, NULL);
208 wrefresh(lw->w);
209 lw->repaint = 0;
210 }
211 }
214 static int
215 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
216 {
217 int retval;
219 retval = list_window_cmd(lw, help_text_rows, cmd);
220 if( !retval )
221 return screen_find(screen, c,
222 lw, help_text_rows,
223 cmd, list_callback);
225 return retval;
226 }
228 static list_window_t *
229 help_lw(void)
230 {
231 return lw;
232 }
234 screen_functions_t *
235 get_screen_help(void)
236 {
237 static screen_functions_t functions;
239 memset(&functions, 0, sizeof(screen_functions_t));
240 functions.init = help_init;
241 functions.exit = help_exit;
242 functions.open = NULL;
243 functions.close = NULL;
244 functions.resize = help_resize;
245 functions.paint = help_paint;
246 functions.update = help_update;
247 functions.cmd = help_cmd;
248 functions.get_lw = help_lw;
249 functions.get_title = help_title;
251 return &functions;
252 }