1 #include <stdlib.h>
2 #include <string.h>
3 #include <glib.h>
4 #include <ncurses.h>
6 #include "config.h"
7 #include "libmpdclient.h"
8 #include "mpc.h"
9 #include "command.h"
10 #include "screen.h"
11 #include "screen_utils.h"
12 #include "screen_help.h"
14 typedef struct
15 {
16 char highlight;
17 command_t command;
18 char *text;
19 } help_text_row_t;
21 static help_text_row_t help_text[] =
22 {
23 { 1, CMD_NONE, " Keys " },
24 { 0, CMD_NONE, " --------" },
25 { 0, CMD_STOP, NULL },
26 { 0, CMD_PAUSE, NULL },
27 { 0, CMD_TRACK_NEXT, NULL },
28 { 0, CMD_TRACK_PREVIOUS, NULL },
29 { 0, CMD_VOLUME_DOWN, NULL },
30 { 0, CMD_VOLUME_UP, NULL },
31 { 0, CMD_NONE, NULL },
32 { 0, CMD_LIST_PREVIOUS, NULL },
33 { 0, CMD_LIST_NEXT, NULL },
34 { 0, CMD_LIST_PREVIOUS_PAGE, NULL },
35 { 0, CMD_LIST_NEXT_PAGE, NULL },
36 { 0, CMD_LIST_FIRST, NULL },
37 { 0, CMD_LIST_LAST, NULL },
39 { 0, CMD_LIST_FIND, NULL },
40 { 0, CMD_LIST_RFIND, NULL },
41 { 0, CMD_LIST_FIND_NEXT, NULL },
42 { 0, CMD_LIST_RFIND_NEXT, NULL },
43 { 0, CMD_TOGGLE_FIND_WRAP, NULL },
44 { 0, CMD_NONE, NULL },
45 { 0, CMD_SCREEN_NEXT, NULL },
46 { 0, CMD_SCREEN_HELP, NULL },
47 { 0, CMD_SCREEN_PLAY, NULL },
48 { 0, CMD_SCREEN_FILE, NULL },
49 { 0, CMD_QUIT, NULL },
50 { 0, CMD_NONE, NULL },
51 { 0, CMD_NONE, NULL },
52 { 1, CMD_NONE, " Keys - Playlist screen " },
53 { 0, CMD_NONE, " --------------------------" },
54 { 0, CMD_PLAY, "Play" },
55 { 0, CMD_DELETE, NULL },
56 { 0, CMD_SHUFFLE, NULL },
57 { 0, CMD_CLEAR, NULL },
58 { 0, CMD_SAVE_PLAYLIST, NULL },
59 { 0, CMD_REPEAT, NULL },
60 { 0, CMD_RANDOM, NULL },
61 { 0, CMD_SCREEN_UPDATE, "Center" },
62 { 0, CMD_TOGGLE_AUTOCENTER, NULL },
63 { 0, CMD_NONE, NULL },
64 { 0, CMD_NONE, NULL },
65 { 1, CMD_NONE, " Keys - Browse screen " },
66 { 0, CMD_NONE, " ------------------------" },
67 { 0, CMD_PLAY, "Enter directory" },
68 { 0, CMD_SELECT, NULL },
69 { 0, CMD_DELETE, NULL },
70 { 0, CMD_SCREEN_UPDATE, NULL },
71 { 0, CMD_NONE, NULL },
72 { 0, CMD_NONE, NULL },
73 { 1, CMD_NONE, " " PACKAGE " version " VERSION },
74 {-1, CMD_NONE, NULL }
75 };
77 static int help_text_rows = -1;
81 static char *
82 list_callback(int index, int *highlight, void *data)
83 {
84 static char buf[256];
86 if( help_text_rows<0 )
87 {
88 help_text_rows = 0;
89 while( help_text[help_text_rows].highlight != -1 )
90 help_text_rows++;
91 }
93 *highlight = 0;
94 if( index<help_text_rows )
95 {
96 *highlight = help_text[index].highlight > 0;
97 if( help_text[index].command == CMD_NONE )
98 {
99 if( help_text[index].text )
100 return help_text[index].text;
101 else
102 return " ";
103 }
104 if( help_text[index].text )
105 snprintf(buf, 256,
106 "%20s : %s",
107 get_key_names(help_text[index].command, TRUE),
108 help_text[index].text);
109 else
110 snprintf(buf, 256,
111 "%20s : %s",
112 get_key_names(help_text[index].command, TRUE),
113 get_key_description(help_text[index].command));
114 return buf;
115 }
117 return NULL;
118 }
121 void
122 help_open(screen_t *screen, mpd_client_t *c)
123 {
124 }
126 void
127 help_close(screen_t *screen, mpd_client_t *c)
128 {
129 }
131 void
132 help_paint(screen_t *screen, mpd_client_t *c)
133 {
134 list_window_t *w = screen->helplist;
136 w->clear = 1;
137 list_window_paint(screen->helplist, list_callback, NULL);
138 wrefresh(screen->helplist->w);
139 }
141 void
142 help_update(screen_t *screen, mpd_client_t *c)
143 {
144 list_window_t *w = screen->helplist;
146 if( w->repaint )
147 {
148 list_window_paint(screen->helplist, list_callback, NULL);
149 wrefresh(screen->helplist->w);
150 w->repaint = 0;
151 }
152 }
155 int
156 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
157 {
158 int retval;
160 retval = list_window_cmd(screen->helplist, help_text_rows, cmd);
161 if( !retval )
162 return screen_find(screen, c,
163 screen->helplist, help_text_rows,
164 cmd, list_callback);
166 return retval;
167 }