Code

Changed directory layout (for future use of gettext)
[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 <stdlib.h>
20 #include <string.h>
21 #include <glib.h>
22 #include <ncurses.h>
24 #include "config.h"
25 #include "libmpdclient.h"
26 #include "mpc.h"
27 #include "command.h"
28 #include "screen.h"
29 #include "screen_utils.h"
30 #include "screen_help.h"
33 typedef struct
34 {
35   signed char highlight;
36   command_t command;
37   char *text;
38 } help_text_row_t;
40 static help_text_row_t help_text[] = 
41 {
42   { 1, CMD_NONE,  "          Movement keys  " },
43   { 0, CMD_NONE,  "        -----------------" },
44   { 0, CMD_LIST_PREVIOUS,  NULL },
45   { 0, CMD_LIST_NEXT,      NULL },
46   { 0, CMD_LIST_PREVIOUS_PAGE, NULL }, 
47   { 0, CMD_LIST_NEXT_PAGE, NULL },
48   { 0, CMD_LIST_FIRST,     NULL },
49   { 0, CMD_LIST_LAST,      NULL },
50   { 0, CMD_NONE,           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_KEYDEF_SCREEN
56   { 0, CMD_SCREEN_KEYDEF,  NULL },
57 #endif
59   { 0, CMD_NONE,           NULL },
60   { 0, CMD_NONE,           NULL },
61   { 1, CMD_NONE, "          General keys " },
62   { 0, CMD_NONE, "        ----------------" },
63   { 0, CMD_STOP,           NULL },
64   { 0, CMD_PAUSE,          NULL },
65   { 0, CMD_TRACK_NEXT,     NULL },
66   { 0, CMD_TRACK_PREVIOUS, NULL },
67   { 0, CMD_SEEK_FORWARD,   NULL },
68   { 0, CMD_SEEK_BACKWARD,  NULL },
69   { 0, CMD_VOLUME_DOWN,    NULL },
70   { 0, CMD_VOLUME_UP,      NULL },
71   { 0, CMD_NONE,           NULL },
72   { 0, CMD_SHUFFLE,        NULL },
73   { 0, CMD_REPEAT,         NULL },
74   { 0, CMD_RANDOM,         NULL },
75   { 0, CMD_CROSSFADE,      NULL },
76   { 0, CMD_NONE,           NULL },
77   { 0, CMD_QUIT,           NULL },
79   { 0, CMD_NONE,           NULL },
80   { 0, CMD_NONE,           NULL },
81   { 1, CMD_NONE, "          Keys - Playlist screen " },
82   { 0, CMD_NONE, "        --------------------------" },
83   { 0, CMD_PLAY,           "Play" },
84   { 0, CMD_DELETE,         NULL },
85   { 0, CMD_CLEAR,          NULL },
86   { 0, CMD_LIST_MOVE_UP,   "Move song up" },
87   { 0, CMD_LIST_MOVE_DOWN, "Move song down" },
88   { 0, CMD_SAVE_PLAYLIST,  NULL },
89   { 0, CMD_SCREEN_UPDATE,  "Center" },
90   { 0, CMD_TOGGLE_AUTOCENTER, NULL },
92   { 0, CMD_NONE,           NULL },
93   { 0, CMD_NONE,           NULL },
94   { 1, CMD_NONE, "          Keys - Browse screen " },
95   { 0, CMD_NONE, "        ------------------------" },
96   { 0, CMD_PLAY,            "Enter directory" },
97   { 0, CMD_SELECT,          NULL },
98   { 0, CMD_DELETE,          NULL },
99   { 0, CMD_SCREEN_UPDATE,   NULL },
101   { 0, CMD_NONE,           NULL },
102   { 0, CMD_NONE,           NULL },
103   { 1, CMD_NONE, "               Find keys " },
104   { 0, CMD_NONE, "              -------------" },
105   { 0, CMD_LIST_FIND,      NULL },
106   { 0, CMD_LIST_RFIND,     NULL },
107   { 0, CMD_LIST_FIND_NEXT, NULL },
108   { 0, CMD_LIST_RFIND_NEXT,  NULL },
109   { 0, CMD_TOGGLE_FIND_WRAP, NULL },
111   { 0, CMD_NONE, NULL },
112   { 0, CMD_NONE, NULL },
113   { 1, CMD_NONE, "          ncmpc build information " },
114   { 0, CMD_NONE, "         ---------------------------" },
115   { 0, CMD_NONE, "             Version : " VERSION },
116   { 0, CMD_NONE, "  Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
117 #ifdef ENABLE_KEYDEF_SCREEN
118   { 0, CMD_NONE, "          Key Editor : yes" },
119 #else
120   { 0, CMD_NONE, "          Key Editor : no" },
121 #endif
123   { 0, CMD_NONE, NULL },
124   {-1, CMD_NONE, NULL }
125 };
127 static int help_text_rows = -1;
128 static list_window_t *lw = NULL;
131 static char *
132 list_callback(int index, int *highlight, void *data)
134   static char buf[256];
136   if( help_text_rows<0 )
137     {
138       help_text_rows = 0;
139       while( help_text[help_text_rows].highlight != -1 )
140         help_text_rows++;
141     }
143   *highlight = 0;
144   if( index<help_text_rows )
145     {
146       *highlight = help_text[index].highlight > 0;
147       if( help_text[index].command == CMD_NONE )
148         {
149           if( help_text[index].text )
150             return help_text[index].text;
151           else
152             return "  ";
153         }
154       if( help_text[index].text )
155         snprintf(buf, 256, 
156                  "%20s : %s   ", 
157                  get_key_names(help_text[index].command, TRUE),
158                  help_text[index].text);
159       else
160         snprintf(buf, 256, 
161                  "%20s : %s   ", 
162                  get_key_names(help_text[index].command, TRUE),
163                  get_key_description(help_text[index].command));
164       return buf;
165     }
167   return NULL;
170 static void
171 help_init(WINDOW *w, int cols, int rows)
173   lw = list_window_init(w, cols, rows);
176 static void
177 help_resize(int cols, int rows)
179   lw->cols = cols;
180   lw->rows = rows;
183 static void
184 help_exit(void)
186   list_window_free(lw);
190 static char *
191 help_title(void)
193   return (TOP_HEADER_PREFIX "Help");
196 static void 
197 help_paint(screen_t *screen, mpd_client_t *c)
199   lw->clear = 1;
200   list_window_paint(lw, list_callback, NULL);
201   wrefresh(lw->w);
204 static void 
205 help_update(screen_t *screen, mpd_client_t *c)
206 {  
207   if( lw->repaint )
208     {
209       list_window_paint(lw, list_callback, NULL);
210       wrefresh(lw->w);
211       lw->repaint = 0;
212     }
216 static int 
217 help_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
219   int retval;
221   retval = list_window_cmd(lw, help_text_rows, cmd);
222   if( !retval )
223     return screen_find(screen, c, 
224                        lw,  help_text_rows,
225                        cmd, list_callback);
227   return retval;
230 static list_window_t *
231 help_lw(void)
233   return lw;
236 screen_functions_t *
237 get_screen_help(void)
239   static screen_functions_t functions;
241   memset(&functions, 0, sizeof(screen_functions_t));
242   functions.init   = help_init;
243   functions.exit   = help_exit;
244   functions.open   = NULL;
245   functions.close  = NULL;
246   functions.resize = help_resize;
247   functions.paint  = help_paint;
248   functions.update = help_update;
249   functions.cmd    = help_cmd;
250   functions.get_lw = help_lw;
251   functions.get_title = help_title;
253   return &functions;