Code

Dont set the xterm title
[ncmpc.git] / src / screen_help.c
1 /* 
2  * $Id$
3  *
4  * (c) 2004 by Kalle Wallin <kaw@linux.se>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
21 #include <stdlib.h>
22 #include <string.h>
23 #include <glib.h>
24 #include <ncurses.h>
26 #include "config.h"
27 #include "ncmpc.h"
28 #include "mpdclient.h"
29 #include "command.h"
30 #include "screen.h"
31 #include "screen_utils.h"
34 typedef struct
35 {
36   signed char highlight;
37   command_t command;
38   char *text;
39 } help_text_row_t;
41 static help_text_row_t help_text[] = 
42 {
43   { 1, CMD_NONE,           N_("Keys - Movement") },
44   { 2, CMD_NONE,           NULL },
45   { 0, CMD_LIST_PREVIOUS,  NULL },
46   { 0, CMD_LIST_NEXT,      NULL },
47   { 0, CMD_LIST_PREVIOUS_PAGE, NULL }, 
48   { 0, CMD_LIST_NEXT_PAGE, NULL },
49   { 0, CMD_LIST_FIRST,     NULL },
50   { 0, CMD_LIST_LAST,      NULL },
51   { 0, CMD_NONE,           NULL },
52   { 0, CMD_SCREEN_NEXT,    NULL },
53   { 0, CMD_SCREEN_HELP,    NULL },
54   { 0, CMD_SCREEN_PLAY,    NULL },
55   { 0, CMD_SCREEN_FILE,    NULL },
56 #ifdef ENABLE_CLOCK_SCREEN
57   { 0, CMD_SCREEN_CLOCK,   NULL },
58 #endif
59 #ifdef ENABLE_KEYDEF_SCREEN
60   { 0, CMD_SCREEN_KEYDEF,  NULL },
61 #endif
63   { 0, CMD_NONE,           NULL },
64   { 0, CMD_NONE,           NULL },
65   { 1, CMD_NONE,           N_("Keys - Global") },
66   { 2, CMD_NONE,           NULL },
67   { 0, CMD_STOP,           NULL },
68   { 0, CMD_PAUSE,          NULL },
69   { 0, CMD_TRACK_NEXT,     NULL },
70   { 0, CMD_TRACK_PREVIOUS, NULL },
71   { 0, CMD_SEEK_FORWARD,   NULL },
72   { 0, CMD_SEEK_BACKWARD,  NULL },
73   { 0, CMD_VOLUME_DOWN,    NULL },
74   { 0, CMD_VOLUME_UP,      NULL },
75   { 0, CMD_NONE,           NULL },
76   { 0, CMD_REPEAT,         NULL },
77   { 0, CMD_RANDOM,         NULL },
78   { 0, CMD_CROSSFADE,      NULL },
79   { 0, CMD_SHUFFLE,        NULL },
80   { 0, CMD_DB_UPDATE,      NULL },
81   { 0, CMD_NONE,           NULL },
82   { 0, CMD_LIST_FIND,      NULL },
83   { 0, CMD_LIST_RFIND,     NULL },
84   { 0, CMD_LIST_FIND_NEXT, NULL },
85   { 0, CMD_LIST_RFIND_NEXT,  NULL },
86   { 0, CMD_TOGGLE_FIND_WRAP, NULL },
87   { 0, CMD_NONE,           NULL },
88   { 0, CMD_QUIT,           NULL },
90   { 0, CMD_NONE,           NULL },
91   { 0, CMD_NONE,           NULL },
92   { 1, CMD_NONE,           N_("Keys - Playlist screen") },
93   { 2, CMD_NONE,           NULL },
94   { 0, CMD_PLAY,           N_("Play") },
95   { 0, CMD_DELETE,         NULL },
96   { 0, CMD_CLEAR,          NULL },
97   { 0, CMD_LIST_MOVE_UP,   N_("Move song up") },
98   { 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
99   { 0, CMD_ADD,            NULL },
100   { 0, CMD_SAVE_PLAYLIST,  NULL },
101   { 0, CMD_SCREEN_UPDATE,  N_("Center") },
102   { 0, CMD_TOGGLE_AUTOCENTER, NULL },
104   { 0, CMD_NONE,           NULL },
105   { 0, CMD_NONE,           NULL },
106   { 1, CMD_NONE,           N_("Keys - Browse screen") },
107   { 2, CMD_NONE,           NULL },
108   { 0, CMD_PLAY,           N_("Enter directory") },
109   { 0, CMD_SELECT,         NULL },
110   { 0, CMD_DELETE,         NULL },
111   { 0, CMD_SCREEN_UPDATE,  NULL },
113   { 0, CMD_NONE, NULL },
114   { 0, CMD_NONE, NULL },
115   { 1, CMD_NONE, "ncmpc build information" },
116   { 2, CMD_NONE, NULL },
117   { 0, CMD_NONE, "             Version : " VERSION },
118   { 0, CMD_NONE, "  Configuration dirs : ~/.ncmpc, " SYSCONFDIR "/" PACKAGE },
119 #ifdef ENABLE_NLS
120   { 0, CMD_NONE, "NLS support : yes" },
121 #else
122   { 0, CMD_NONE, "NLS support : no" },
123 #endif
124 #ifdef ENABLE_KEYDEF_SCREEN
125   { 0, CMD_NONE, "Key Editor : yes" },
126 #else
127   { 0, CMD_NONE, "Key Editor : no" },
128 #endif
130   { 0, CMD_NONE, NULL },
131   {-1, CMD_NONE, NULL }
132 };
134 static int help_text_rows = -1;
135 static list_window_t *lw = NULL;
138 static char *
139 list_callback(int index, int *highlight, void *data)
141   static char buf[256];
143   if( help_text_rows<0 )
144     {
145       help_text_rows = 0;
146       while( help_text[help_text_rows].highlight != -1 )
147         help_text_rows++;
148     }
150   *highlight = 0;
151   if( index<help_text_rows )
152     {
153       *highlight = help_text[index].highlight > 0;
154       if( help_text[index].command == CMD_NONE )
155         {
156           if( help_text[index].text )
157             snprintf(buf, 256, "%28s", _(help_text[index].text));
158           else 
159             if( help_text[index].highlight == 2 )
160               {
161                 int i;
163                 for(i=3; i<COLS-3 && i<256; i++)
164                   buf[i]='-';
165                 buf[i] = '\0';
166               }
167             else
168               strcpy(buf, " ");
169           return buf;
170         }
171       if( help_text[index].text )
172         snprintf(buf, 256, 
173                  "%20s : %s   ", 
174                  get_key_names(help_text[index].command, TRUE),
175                  _(help_text[index].text));
176       else
177         snprintf(buf, 256, 
178                  "%20s : %s   ", 
179                  get_key_names(help_text[index].command, TRUE),
180                  get_key_description(help_text[index].command));
181       return buf;
182     }
184   return NULL;
187 static void
188 help_init(WINDOW *w, int cols, int rows)
190   lw = list_window_init(w, cols, rows);
193 static void
194 help_resize(int cols, int rows)
196   lw->cols = cols;
197   lw->rows = rows;
200 static void
201 help_exit(void)
203   list_window_free(lw);
207 static char *
208 help_title(char *str, size_t size)
210   return _("Help");
213 static void 
214 help_paint(screen_t *screen, mpdclient_t *c)
216   lw->clear = 1;
217   list_window_paint(lw, list_callback, NULL);
218   wrefresh(lw->w);
221 static void 
222 help_update(screen_t *screen, mpdclient_t *c)
223 {  
224   if( lw->repaint )
225     {
226       list_window_paint(lw, list_callback, NULL);
227       wrefresh(lw->w);
228       lw->repaint = 0;
229     }
233 static int 
234 help_cmd(screen_t *screen, mpdclient_t *c, command_t cmd)
236   int retval;
238   retval = list_window_cmd(lw, help_text_rows, cmd);
239   if( !retval )
240     return screen_find(screen, c, 
241                        lw,  help_text_rows,
242                        cmd, list_callback);
244   return retval;
247 static list_window_t *
248 help_lw(void)
250   return lw;
253 screen_functions_t *
254 get_screen_help(void)
256   static screen_functions_t functions;
258   memset(&functions, 0, sizeof(screen_functions_t));
259   functions.init   = help_init;
260   functions.exit   = help_exit;
261   functions.open   = NULL;
262   functions.close  = NULL;
263   functions.resize = help_resize;
264   functions.paint  = help_paint;
265   functions.update = help_update;
266   functions.cmd    = help_cmd;
267   functions.get_lw = help_lw;
268   functions.get_title = help_title;
270   return &functions;