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, "Stop" },
26 { 0, CMD_PAUSE, "Pause" },
27 { 0, CMD_TRACK_NEXT, "Next track" },
28 { 0, CMD_TRACK_PREVIOUS, "Prevoius track (back)" },
29 { 0, CMD_VOLUME_DOWN, "Volume down" },
30 { 0, CMD_VOLUME_UP, "Volume up" },
31 { 0, CMD_NONE, " " },
32 { 0, CMD_LIST_NEXT, "Move cursor up" },
33 { 0, CMD_LIST_PREVIOUS, "Move cursor down" },
34 { 0, CMD_LIST_FIND, "Find" },
35 { 0, CMD_LIST_RFIND, "find backward" },
36 { 0, CMD_LIST_FIND_NEXT, "Find next" },
37 { 0, CMD_LIST_RFIND_NEXT,"Find previuos" },
38 { 0, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" },
39 { 0, CMD_NONE, " " },
40 { 0, CMD_SCREEN_NEXT, "Change screen" },
41 { 0, CMD_SCREEN_HELP, "Help screen" },
42 { 0, CMD_SCREEN_PLAY, "Playlist screen" },
43 { 0, CMD_SCREEN_FILE, "Browse screen" },
44 { 0, CMD_QUIT, "Quit" },
45 { 0, CMD_NONE, " " },
46 { 0, CMD_NONE, " " },
47 { 1, CMD_NONE, " Keys - Playlist screen " },
48 { 0, CMD_NONE, " --------------------------" },
49 { 0, CMD_PLAY, "Play selected entry" },
50 { 0, CMD_DELETE, "Delete selected entry from playlist" },
51 { 0, CMD_SHUFFLE, "Shuffle playlist" },
52 { 0, CMD_CLEAR, "Clear playlist" },
53 { 0, CMD_SAVE_PLAYLIST, "Save 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, "Enter directory/Load playlist" },
61 { 0, CMD_SELECT, "Add/remove song from playlist" },
62 { 0, CMD_DELETE, "Delete playlist" },
63 { 0, CMD_SCREEN_UPDATE, "Update" },
64 { 0, CMD_NONE, " " },
65 { 0, CMD_NONE, " " },
66 { 1, CMD_NONE, " " PACKAGE " version " VERSION },
67 { 0, CMD_NONE, NULL }
68 };
70 static int help_text_rows = -1;
74 static char *
75 list_callback(int index, int *highlight, void *data)
76 {
77 static char buf[256];
79 if( help_text_rows<0 )
80 {
81 help_text_rows = 0;
82 while( help_text[help_text_rows].text )
83 help_text_rows++;
84 }
86 *highlight = 0;
87 if( index<help_text_rows )
88 {
89 *highlight = help_text[index].highlight;
90 if( help_text[index].command == CMD_NONE )
91 return help_text[index].text;
92 snprintf(buf, 256,
93 "%20s : %s",
94 command_get_keys(help_text[index].command),
95 help_text[index].text);
96 return buf;
97 }
99 return NULL;
100 }
103 void
104 help_open(screen_t *screen, mpd_client_t *c)
105 {
106 }
108 void
109 help_close(screen_t *screen, mpd_client_t *c)
110 {
111 }
113 void
114 help_paint(screen_t *screen, mpd_client_t *c)
115 {
116 list_window_t *w = screen->helplist;
118 w->clear = 1;
119 list_window_paint(screen->helplist, list_callback, NULL);
120 wrefresh(screen->helplist->w);
121 }
123 void
124 help_update(screen_t *screen, mpd_client_t *c)
125 {
126 list_window_t *w = screen->helplist;
128 if( w->repaint )
129 {
130 list_window_paint(screen->helplist, list_callback, NULL);
131 wrefresh(screen->helplist->w);
132 w->repaint = 0;
133 }
134 }
137 int
138 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
139 {
140 int retval;
142 retval = list_window_cmd(screen->helplist, help_text_rows, cmd);
143 if( !retval )
144 return screen_find(screen, c,
145 screen->helplist, help_text_rows,
146 cmd, list_callback);
148 return retval;
149 }