1 /*
2 * $Id: screen_help.c,v 1.8 2004/03/17 13:40:25 kalle Exp $
3 *
4 */
6 #include <stdlib.h>
7 #include <string.h>
8 #include <glib.h>
9 #include <ncurses.h>
11 #include "config.h"
12 #include "libmpdclient.h"
13 #include "mpc.h"
14 #include "command.h"
15 #include "screen.h"
16 #include "screen_help.h"
18 typedef struct
19 {
20 char highlight;
21 command_t command;
22 char *text;
23 } help_text_row_t;
25 static help_text_row_t help_text[] =
26 {
27 { 1, CMD_NONE, " Keys " },
28 { 0, CMD_NONE, " --------" },
29 { 0, CMD_STOP, "Stop" },
30 { 0, CMD_PAUSE, "Pause" },
31 { 0, CMD_TRACK_NEXT, "Next track" },
32 { 0, CMD_TRACK_PREVIOUS, "Prevoius track (back)" },
33 { 0, CMD_VOLUME_DOWN, "Volume down" },
34 { 0, CMD_VOLUME_UP, "Volume up" },
35 { 0, CMD_NONE, " " },
36 { 0, CMD_LIST_NEXT, "Move cursor up" },
37 { 0, CMD_LIST_PREVIOUS, "Move cursor down" },
38 { 0, CMD_LIST_FIND, "Find" },
39 { 0, CMD_LIST_FIND_NEXT, "Find again" },
40 { 0, CMD_NONE, " " },
41 { 0, CMD_SCREEN_NEXT, "Change screen" },
42 { 0, CMD_SCREEN_HELP, "Help screen" },
43 { 0, CMD_SCREEN_PLAY, "Playlist screen" },
44 { 0, CMD_SCREEN_FILE, "Browse screen" },
45 { 0, CMD_QUIT, "Quit" },
46 { 0, CMD_NONE, " " },
47 { 0, CMD_NONE, " " },
48 { 1, CMD_NONE, " Keys - Playlist screen " },
49 { 0, CMD_NONE, " --------------------------" },
50 { 0, CMD_PLAY, "Play selected entry" },
51 { 0, CMD_DELETE, "Delete selected entry from platlist" },
52 { 0, CMD_SHUFFLE, "Shuffle playlist" },
53 { 0, CMD_CLEAR, "Clear playlist" },
54 { 0, CMD_REPEAT, "Toggle repeat mode" },
55 { 0, CMD_RANDOM, "Toggle random mode" },
56 { 0, CMD_NONE, " " },
57 { 0, CMD_NONE, " " },
58 { 1, CMD_NONE, " Keys - Browse screen " },
59 { 0, CMD_NONE, " ------------------------" },
60 { 0, CMD_PLAY, "Change to selected directory" },
61 { 0, CMD_SELECT, "Add/Remove selected file" },
62 { 0, CMD_NONE, " " },
63 { 0, CMD_NONE, " " },
64 { 1, CMD_NONE, " " PACKAGE " version " VERSION },
65 { 0, CMD_NONE, NULL }
66 };
68 static int help_text_rows = -1;
72 static char *
73 list_callback(int index, int *highlight, void *data)
74 {
75 static char buf[256];
77 if( help_text_rows<0 )
78 {
79 help_text_rows = 0;
80 while( help_text[help_text_rows].text )
81 help_text_rows++;
82 }
84 *highlight = 0;
85 if( index<help_text_rows )
86 {
87 *highlight = help_text[index].highlight;
88 if( help_text[index].command == CMD_NONE )
89 return help_text[index].text;
90 snprintf(buf, 256,
91 "%20s : %s",
92 command_get_keys(help_text[index].command),
93 help_text[index].text);
94 return buf;
95 }
97 return NULL;
98 }
101 void
102 help_open(screen_t *screen, mpd_client_t *c)
103 {
104 }
106 void
107 help_close(screen_t *screen, mpd_client_t *c)
108 {
109 }
111 void
112 help_paint(screen_t *screen, mpd_client_t *c)
113 {
114 list_window_t *w = screen->helplist;
116 w->clear = 1;
117 list_window_paint(screen->helplist, list_callback, NULL);
118 wrefresh(screen->helplist->w);
119 }
121 void
122 help_update(screen_t *screen, mpd_client_t *c)
123 {
124 list_window_t *w = screen->helplist;
126 if( w->repaint )
127 {
128 list_window_paint(screen->helplist, list_callback, NULL);
129 wrefresh(screen->helplist->w);
130 w->repaint = 0;
131 }
132 }
135 int
136 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
137 {
138 switch(cmd)
139 {
140 case CMD_LIST_PREVIOUS:
141 list_window_previous(screen->helplist);
142 screen->helplist->repaint=1;
143 break;
144 case CMD_LIST_NEXT:
145 list_window_next(screen->helplist, help_text_rows);
146 screen->helplist->repaint=1;
147 break;
148 case CMD_LIST_FIRST:
149 list_window_first(screen->helplist);
150 screen->helplist->repaint = 1;
151 break;
152 case CMD_LIST_LAST:
153 list_window_last(screen->helplist, help_text_rows);
154 screen->helplist->repaint = 1;
155 break;
156 case CMD_LIST_PREVIOUS_PAGE:
157 list_window_previous_page(screen->helplist);
158 screen->helplist->repaint = 1;
159 break;
160 case CMD_LIST_NEXT_PAGE:
161 list_window_next_page(screen->helplist, help_text_rows);
162 screen->helplist->repaint = 1;
163 break;
164 case CMD_LIST_FIND:
165 if( screen->findbuf )
166 {
167 free(screen->findbuf);
168 screen->findbuf=NULL;
169 }
170 /* continue... */
171 case CMD_LIST_FIND_NEXT:
172 if( !screen->findbuf )
173 screen->findbuf=screen_readln(screen->status_window.w, "/");
174 if( list_window_find(screen->helplist,
175 list_callback,
176 c,
177 screen->findbuf) == 0 )
178 {
179 screen->helplist->repaint = 1;
180 }
181 else
182 {
183 screen_status_printf("Unable to find \'%s\'", screen->findbuf);
184 beep();
185 }
186 break;
187 default:
188 return 0;
189 }
190 return 1;
191 }