Code

eec76d18ad62088db76339efeed5472950cef0b4
[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 "ncmpc.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>
30 #include <ncurses.h>
33 typedef struct {
34         signed char highlight;
35         command_t command;
36         const char *text;
37 } help_text_row_t;
39 static help_text_row_t help_text[] =
40 {
41   { 1, CMD_NONE,           N_("Keys - Movement") },
42   { 2, CMD_NONE,           NULL },
43   { 0, CMD_LIST_PREVIOUS,  NULL },
44   { 0, CMD_LIST_NEXT,      NULL },
45   { 0, CMD_LIST_PREVIOUS_PAGE, NULL }, 
46   { 0, CMD_LIST_NEXT_PAGE, NULL },
47   { 0, CMD_LIST_FIRST,     NULL },
48   { 0, CMD_LIST_LAST,      NULL },
49   { 0, CMD_NONE,           NULL },
50   { 0, CMD_SCREEN_PREVIOUS,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_SEARCH_SCREEN
56   { 0, CMD_SCREEN_SEARCH,  NULL },
57 #endif
58 #ifdef ENABLE_KEYDEF_SCREEN
59   { 0, CMD_SCREEN_KEYDEF,  NULL },
60 #endif
62   { 0, CMD_NONE,           NULL },
63   { 0, CMD_NONE,           NULL },
64   { 1, CMD_NONE,           N_("Keys - Global") },
65   { 2, CMD_NONE,           NULL },
66   { 0, CMD_STOP,           NULL },
67   { 0, CMD_PAUSE,          NULL },
68   { 0, CMD_CROP, 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   { 1, CMD_LIST_MOVE_UP,   N_("Move song up") },
98   { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
99   { 0, CMD_ADD,            NULL },
100   { 0, CMD_SAVE_PLAYLIST,  NULL },
101   { 0, CMD_SCREEN_UPDATE,  N_("Center") },
102   { 0, CMD_TOGGLE_AUTOCENTER, NULL },
104   { 0, CMD_NONE,           NULL },
105   { 0, CMD_NONE,           NULL },
106   { 1, CMD_NONE,           N_("Keys - Browse screen") },
107   { 2, CMD_NONE,           NULL },
108   { 0, CMD_PLAY,           N_("Enter directory/Select and play song") },
109   { 0, CMD_SELECT,         NULL },
110   { 0, CMD_SAVE_PLAYLIST,  NULL },
111   { 0, CMD_DELETE,         N_("Delete playlist") },
112   { 0, CMD_GO_PARENT_DIRECTORY, NULL },
113   { 0, CMD_GO_ROOT_DIRECTORY, NULL },
114   { 0, CMD_SCREEN_UPDATE,  NULL },
116 #ifdef ENABLE_SEARCH_SCREEN
117   { 0, CMD_NONE,           NULL },
118   { 0, CMD_NONE,           NULL },
119   { 1, CMD_NONE,           N_("Keys - Search screen") },
120   { 2, CMD_NONE,           NULL },
121   { 0, CMD_SCREEN_SEARCH,  N_("Search") },
122   { 0, CMD_PLAY,           N_("Select and play") },
123   { 0, CMD_SELECT,         NULL },
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 = NULL;
145 static const char *
146 list_callback(unsigned idx, int *highlight, mpd_unused void *data)
148         static char buf[512];
150         if (idx >= help_text_rows)
151                 return NULL;
153         if (help_text[idx].highlight)
154                 *highlight = 1;
156         if (help_text[idx].command == CMD_NONE) {
157                 if (help_text[idx].text)
158                         g_snprintf(buf, sizeof(buf), "      %s", _(help_text[idx].text));
159                 else if (help_text[idx].highlight == 2) {
160                         int i;
162                         for (i = 3; i < COLS - 3 && i < (int)sizeof(buf); i++)
163                                 buf[i] = '-';
164                         buf[i] = '\0';
165                 } else
166                         g_strlcpy(buf, " ", sizeof(buf));
167                 return buf;
168         }
170         if (help_text[idx].text)
171                 g_snprintf(buf, sizeof(buf),
172                            "%20s : %s   ",
173                            get_key_names(help_text[idx].command, TRUE),
174                            _(help_text[idx].text));
175         else
176                 g_snprintf(buf, sizeof(buf),
177                            "%20s : %s   ",
178                            get_key_names(help_text[idx].command, TRUE),
179                            get_key_description(help_text[idx].command));
180         return buf;
183 static void
184 help_init(WINDOW *w, int cols, int rows)
186   lw = list_window_init(w, cols, rows);
187   lw->flags = LW_HIDE_CURSOR;
190 static void
191 help_resize(int cols, int rows)
193   lw->cols = cols;
194   lw->rows = rows;
197 static void
198 help_exit(void)
200   list_window_free(lw);
204 static const char *
205 help_title(mpd_unused char *str, mpd_unused size_t size)
207         return _("Help");
210 static void
211 help_paint(mpd_unused screen_t *screen, mpd_unused mpdclient_t *c)
213         list_window_paint(lw, list_callback, NULL);
214         wrefresh(lw->w);
217 static int
218 help_cmd(screen_t *screen, mpd_unused mpdclient_t *c, command_t cmd)
220         if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
221                 list_window_paint(lw, list_callback, NULL);
222                 wrefresh(lw->w);
223                 return 1;
224         }
226         lw->selected = lw->start+lw->rows;
227         if (screen_find(screen,
228                         lw,  help_text_rows,
229                         cmd, list_callback, NULL)) {
230                 /* center the row */
231                 list_window_center(lw, help_text_rows, lw->selected);
232                 list_window_paint(lw, list_callback, NULL);
233                 wrefresh(lw->w);
234                 return 1;
235         }
237         return 0;
240 const struct screen_functions screen_help = {
241         .init = help_init,
242         .exit = help_exit,
243         .resize = help_resize,
244         .paint = help_paint,
245         .cmd = help_cmd,
246         .get_title = help_title,
247 };