Code

Added delete playlist feature.
[ncmpc.git] / screen_help.c
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_NONE, " " },
64   { 0, CMD_NONE, " " },
65   { 1, CMD_NONE, " " PACKAGE " version " VERSION },
66   { 0, CMD_NONE, NULL }
67 };
69 static int help_text_rows = -1;
73 static char *
74 list_callback(int index, int *highlight, void *data)
75 {
76   static char buf[256];
78   if( help_text_rows<0 )
79     {
80       help_text_rows = 0;
81       while( help_text[help_text_rows].text )
82         help_text_rows++;
83     }
85   *highlight = 0;
86   if( index<help_text_rows )
87     {
88       *highlight = help_text[index].highlight;
89       if( help_text[index].command == CMD_NONE )
90         return help_text[index].text;
91       snprintf(buf, 256, 
92                "%20s : %s", 
93                command_get_keys(help_text[index].command),
94                help_text[index].text);
95       return buf;
96     }
98   return NULL;
99 }
102 void 
103 help_open(screen_t *screen, mpd_client_t *c)
107 void 
108 help_close(screen_t *screen, mpd_client_t *c)
112 void 
113 help_paint(screen_t *screen, mpd_client_t *c)
115   list_window_t *w = screen->helplist;
117   w->clear = 1;
118   list_window_paint(screen->helplist, list_callback, NULL);
119   wrefresh(screen->helplist->w);
122 void 
123 help_update(screen_t *screen, mpd_client_t *c)
124 {  
125   list_window_t *w = screen->helplist;
126  
127   if( w->repaint )
128     {
129       list_window_paint(screen->helplist, list_callback, NULL);
130       wrefresh(screen->helplist->w);
131       w->repaint = 0;
132     }
136 int 
137 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
139   int retval;
141   retval = list_window_cmd(screen->helplist, help_text_rows, cmd);
142   if( !retval )
143     return screen_find(screen, c, 
144                        screen->helplist, help_text_rows,
145                        cmd, list_callback);
147   return retval;