Code

command: added CMD_LOCATE to locate song in database
[ncmpc.git] / src / screen_help.c
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 "config.h"
20 #include "i18n.h"
21 #include "mpdclient.h"
22 #include "command.h"
23 #include "screen.h"
24 #include "screen_utils.h"
25 #include "gcc.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_("Keys - 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_NONE, NULL },
47         { 0, CMD_SCREEN_PREVIOUS,NULL },
48         { 0, CMD_SCREEN_NEXT, NULL },
49         { 0, CMD_SCREEN_HELP, NULL },
50         { 0, CMD_SCREEN_PLAY, NULL },
51         { 0, CMD_SCREEN_FILE, NULL },
52 #ifdef ENABLE_SEARCH_SCREEN
53         { 0, CMD_SCREEN_SEARCH, NULL },
54 #endif
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, N_("Keys - Global") },
62         { 2, CMD_NONE, NULL },
63         { 0, CMD_STOP, NULL },
64         { 0, CMD_PAUSE, NULL },
65         { 0, CMD_CROP, NULL },
66         { 0, CMD_TRACK_NEXT, NULL },
67         { 0, CMD_TRACK_PREVIOUS, NULL },
68         { 0, CMD_SEEK_FORWARD, NULL },
69         { 0, CMD_SEEK_BACKWARD, NULL },
70         { 0, CMD_VOLUME_DOWN, NULL },
71         { 0, CMD_VOLUME_UP, NULL },
72         { 0, CMD_NONE, NULL },
73         { 0, CMD_REPEAT, NULL },
74         { 0, CMD_RANDOM, NULL },
75         { 0, CMD_CROSSFADE, NULL },
76         { 0, CMD_SHUFFLE, NULL },
77         { 0, CMD_DB_UPDATE, NULL },
78         { 0, CMD_NONE, NULL },
79         { 0, CMD_LIST_FIND, NULL },
80         { 0, CMD_LIST_RFIND, NULL },
81         { 0, CMD_LIST_FIND_NEXT, NULL },
82         { 0, CMD_LIST_RFIND_NEXT, NULL },
83         { 0, CMD_TOGGLE_FIND_WRAP, NULL },
84         { 0, CMD_LOCATE, NULL },
85         { 0, CMD_NONE, NULL },
86         { 0, CMD_QUIT, NULL },
88         { 0, CMD_NONE, NULL },
89         { 0, CMD_NONE, NULL },
90         { 1, CMD_NONE, N_("Keys - Playlist screen") },
91         { 2, CMD_NONE, NULL },
92         { 0, CMD_PLAY, N_("Play") },
93         { 0, CMD_DELETE, NULL },
94         { 0, CMD_CLEAR, NULL },
95         { 1, CMD_LIST_MOVE_UP, N_("Move song up") },
96         { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
97         { 0, CMD_ADD, NULL },
98         { 0, CMD_SAVE_PLAYLIST, NULL },
99         { 0, CMD_SCREEN_UPDATE, N_("Center") },
100         { 0, CMD_TOGGLE_AUTOCENTER, NULL },
102         { 0, CMD_NONE, NULL },
103         { 0, CMD_NONE, NULL },
104         { 1, CMD_NONE, N_("Keys - Browse screen") },
105         { 2, CMD_NONE, NULL },
106         { 0, CMD_PLAY, N_("Enter directory/Select and play song") },
107         { 0, CMD_SELECT, NULL },
108         { 0, CMD_ADD, N_("Append song to playlist") },
109         { 0, CMD_SAVE_PLAYLIST, NULL },
110         { 0, CMD_DELETE, N_("Delete playlist") },
111         { 0, CMD_GO_PARENT_DIRECTORY, NULL },
112         { 0, CMD_GO_ROOT_DIRECTORY, NULL },
113         { 0, CMD_SCREEN_UPDATE, NULL },
115 #ifdef ENABLE_SEARCH_SCREEN
116         { 0, CMD_NONE, NULL },
117         { 0, CMD_NONE, NULL },
118         { 1, CMD_NONE, N_("Keys - Search screen") },
119         { 2, CMD_NONE, NULL },
120         { 0, CMD_SCREEN_SEARCH, N_("Search") },
121         { 0, CMD_PLAY, N_("Select and play") },
122         { 0, CMD_SELECT, NULL },
123         { 0, CMD_ADD, N_("Append song to playlist") },
124         { 0, CMD_SELECT_ALL,     NULL },
125         { 0, CMD_SEARCH_MODE, NULL },
126 #endif
127 #ifdef ENABLE_LYRICS_SCREEN
128         { 0, CMD_NONE, NULL },
129         { 0, CMD_NONE, NULL },
130         { 1, CMD_NONE, N_("Keys - Lyrics screen") },
131         { 2, CMD_NONE, NULL },
132         { 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
133         { 0, CMD_SELECT, N_("(Re)load lyrics") },
134         { 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
135         { 0, CMD_LYRICS_UPDATE, N_("Explicitly download lyrics") },
136         { 0, CMD_ADD, N_("Save lyrics") },
137 #endif
138 };
140 #define help_text_rows (sizeof(help_text) / sizeof(help_text[0]))
142 static list_window_t *lw;
144 static const char *
145 list_callback(unsigned idx, int *highlight, mpd_unused void *data)
147         static char buf[512];
149         if (idx >= help_text_rows)
150                 return NULL;
152         if (help_text[idx].highlight)
153                 *highlight = 1;
155         if (help_text[idx].command == CMD_NONE) {
156                 if (help_text[idx].text)
157                         g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
158                 else if (help_text[idx].highlight == 2) {
159                         int i;
161                         for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
162                                 buf[i] = '-';
163                         buf[i] = '\0';
164                 } else
165                         g_strlcpy(buf, " ", sizeof(buf));
166                 return buf;
167         }
169         if (help_text[idx].text)
170                 g_snprintf(buf, sizeof(buf),
171                            "%20s : %s   ",
172                            get_key_names(help_text[idx].command, TRUE),
173                            _(help_text[idx].text));
174         else
175                 g_snprintf(buf, sizeof(buf),
176                            "%20s : %s   ",
177                            get_key_names(help_text[idx].command, TRUE),
178                            get_key_description(help_text[idx].command));
179         return buf;
182 static void
183 help_init(WINDOW *w, int cols, int rows)
185   lw = list_window_init(w, cols, rows);
186   lw->flags = LW_HIDE_CURSOR;
189 static void
190 help_resize(int cols, int rows)
192   lw->cols = cols;
193   lw->rows = rows;
196 static void
197 help_exit(void)
199   list_window_free(lw);
203 static const char *
204 help_title(mpd_unused char *str, mpd_unused size_t size)
206         return _("Help");
209 static void
210 help_paint(void)
212         list_window_paint(lw, list_callback, NULL);
215 static int
216 help_cmd(mpd_unused mpdclient_t *c, command_t cmd)
218         if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
219                 list_window_paint(lw, list_callback, NULL);
220                 wrefresh(lw->w);
221                 return 1;
222         }
224         lw->selected = lw->start+lw->rows;
225         if (screen_find(lw,  help_text_rows,
226                         cmd, list_callback, NULL)) {
227                 /* center the row */
228                 list_window_center(lw, help_text_rows, lw->selected);
229                 list_window_paint(lw, list_callback, NULL);
230                 wrefresh(lw->w);
231                 return 1;
232         }
234         return 0;
237 const struct screen_functions screen_help = {
238         .init = help_init,
239         .exit = help_exit,
240         .resize = help_resize,
241         .paint = help_paint,
242         .cmd = help_cmd,
243         .get_title = help_title,
244 };