960638d650a3f41396628f76abb86c0cb593f2ca
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_DB_UPDATE, NULL },
77 { 0, CMD_NONE, NULL },
78 { 0, CMD_QUIT, NULL },
80 { 0, CMD_NONE, NULL },
81 { 0, CMD_NONE, NULL },
82 { 1, CMD_NONE, " Keys - Playlist screen " },
83 { 0, CMD_NONE, " --------------------------" },
84 { 0, CMD_PLAY, "Play" },
85 { 0, CMD_DELETE, NULL },
86 { 0, CMD_CLEAR, NULL },
87 { 0, CMD_LIST_MOVE_UP, "Move song up" },
88 { 0, CMD_LIST_MOVE_DOWN, "Move song down" },
89 { 0, CMD_SAVE_PLAYLIST, NULL },
90 { 0, CMD_SCREEN_UPDATE, "Center" },
91 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
93 { 0, CMD_NONE, NULL },
94 { 0, CMD_NONE, NULL },
95 { 1, CMD_NONE, " Keys - Browse screen " },
96 { 0, CMD_NONE, " ------------------------" },
97 { 0, CMD_PLAY, "Enter directory" },
98 { 0, CMD_SELECT, NULL },
99 { 0, CMD_DELETE, NULL },
100 { 0, CMD_SCREEN_UPDATE, NULL },
102 { 0, CMD_NONE, NULL },
103 { 0, CMD_NONE, NULL },
104 { 1, CMD_NONE, " Find keys " },
105 { 0, CMD_NONE, " -------------" },
106 { 0, CMD_LIST_FIND, NULL },
107 { 0, CMD_LIST_RFIND, NULL },
108 { 0, CMD_LIST_FIND_NEXT, NULL },
109 { 0, CMD_LIST_RFIND_NEXT, NULL },
110 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
112 { 0, CMD_NONE, NULL },
113 { 0, CMD_NONE, NULL },
114 { 1, CMD_NONE, " ncmpc build information " },
115 { 0, CMD_NONE, " ---------------------------" },
116 { 0, CMD_NONE, " Version : " VERSION },
117 { 0, CMD_NONE, " Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
118 #ifdef ENABLE_KEYDEF_SCREEN
119 { 0, CMD_NONE, " Key Editor : yes" },
120 #else
121 { 0, CMD_NONE, " Key Editor : no" },
122 #endif
124 { 0, CMD_NONE, NULL },
125 {-1, CMD_NONE, NULL }
126 };
128 static int help_text_rows = -1;
129 static list_window_t *lw = NULL;
132 static char *
133 list_callback(int index, int *highlight, void *data)
134 {
135 static char buf[256];
137 if( help_text_rows<0 )
138 {
139 help_text_rows = 0;
140 while( help_text[help_text_rows].highlight != -1 )
141 help_text_rows++;
142 }
144 *highlight = 0;
145 if( index<help_text_rows )
146 {
147 *highlight = help_text[index].highlight > 0;
148 if( help_text[index].command == CMD_NONE )
149 {
150 if( help_text[index].text )
151 return help_text[index].text;
152 else
153 return " ";
154 }
155 if( help_text[index].text )
156 snprintf(buf, 256,
157 "%20s : %s ",
158 get_key_names(help_text[index].command, TRUE),
159 help_text[index].text);
160 else
161 snprintf(buf, 256,
162 "%20s : %s ",
163 get_key_names(help_text[index].command, TRUE),
164 get_key_description(help_text[index].command));
165 return buf;
166 }
168 return NULL;
169 }
171 static void
172 help_init(WINDOW *w, int cols, int rows)
173 {
174 lw = list_window_init(w, cols, rows);
175 }
177 static void
178 help_resize(int cols, int rows)
179 {
180 lw->cols = cols;
181 lw->rows = rows;
182 }
184 static void
185 help_exit(void)
186 {
187 list_window_free(lw);
188 }
191 static char *
192 help_title(void)
193 {
194 return (TOP_HEADER_PREFIX "Help");
195 }
197 static void
198 help_paint(screen_t *screen, mpd_client_t *c)
199 {
200 lw->clear = 1;
201 list_window_paint(lw, list_callback, NULL);
202 wrefresh(lw->w);
203 }
205 static void
206 help_update(screen_t *screen, mpd_client_t *c)
207 {
208 if( lw->repaint )
209 {
210 list_window_paint(lw, list_callback, NULL);
211 wrefresh(lw->w);
212 lw->repaint = 0;
213 }
214 }
217 static int
218 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
219 {
220 int retval;
222 retval = list_window_cmd(lw, help_text_rows, cmd);
223 if( !retval )
224 return screen_find(screen, c,
225 lw, help_text_rows,
226 cmd, list_callback);
228 return retval;
229 }
231 static list_window_t *
232 help_lw(void)
233 {
234 return lw;
235 }
237 screen_functions_t *
238 get_screen_help(void)
239 {
240 static screen_functions_t functions;
242 memset(&functions, 0, sizeof(screen_functions_t));
243 functions.init = help_init;
244 functions.exit = help_exit;
245 functions.open = NULL;
246 functions.close = NULL;
247 functions.resize = help_resize;
248 functions.paint = help_paint;
249 functions.update = help_update;
250 functions.cmd = help_cmd;
251 functions.get_lw = help_lw;
252 functions.get_title = help_title;
254 return &functions;
255 }