File: screen_help.c

package info (click to toggle)
ncmpc 0.25-0.1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,616 kB
  • sloc: ansic: 12,229; sh: 4,157; makefile: 282; ruby: 28
file content (311 lines) | stat: -rw-r--r-- 8,103 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* ncmpc (Ncurses MPD Client)
 * (c) 2004-2010 The Music Player Daemon Project
 * Project homepage: http://musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "screen_help.h"
#include "screen_interface.h"
#include "screen_find.h"
#include "paint.h"
#include "charset.h"
#include "config.h"
#include "i18n.h"

#include <glib.h>

#include <assert.h>

struct help_text_row {
	signed char highlight;
	command_t command;
	const char *text;
};

static const struct help_text_row help_text[] = {
	{ 1, CMD_NONE, N_("Movement") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_LIST_PREVIOUS, NULL },
	{ 0, CMD_LIST_NEXT, NULL },
	{ 0, CMD_LIST_TOP, NULL },
	{ 0, CMD_LIST_MIDDLE, NULL },
	{ 0, CMD_LIST_BOTTOM, NULL },
	{ 0, CMD_LIST_PREVIOUS_PAGE, NULL },
	{ 0, CMD_LIST_NEXT_PAGE, NULL },
	{ 0, CMD_LIST_FIRST, NULL },
	{ 0, CMD_LIST_LAST, NULL },
	{ 0, CMD_LIST_RANGE_SELECT, NULL },
	{ 0, CMD_LIST_SCROLL_UP_LINE, NULL},
	{ 0, CMD_LIST_SCROLL_DOWN_LINE, NULL},
	{ 0, CMD_LIST_SCROLL_UP_HALF, NULL},
	{ 0, CMD_LIST_SCROLL_DOWN_HALF, NULL},
	{ 0, CMD_NONE, NULL },

	{ 0, CMD_SCREEN_PREVIOUS,NULL },
	{ 0, CMD_SCREEN_NEXT, NULL },
	{ 0, CMD_SCREEN_SWAP, NULL },
	{ 0, CMD_SCREEN_HELP, NULL },
	{ 0, CMD_SCREEN_PLAY, NULL },
	{ 0, CMD_SCREEN_FILE, NULL },
#ifdef ENABLE_ARTIST_SCREEN
	{ 0, CMD_SCREEN_ARTIST, NULL },
#endif
#ifdef ENABLE_SEARCH_SCREEN
	{ 0, CMD_SCREEN_SEARCH, NULL },
#endif
#ifdef ENABLE_LYRICS_SCREEN
	{ 0, CMD_SCREEN_LYRICS, NULL },
#endif
#ifdef ENABLE_OUTPUTS_SCREEN
	{ 0, CMD_SCREEN_OUTPUTS, NULL },
#endif
#ifdef ENABLE_CHAT_SCREEN
	{ 0, CMD_SCREEN_CHAT, NULL },
#endif
#ifdef ENABLE_KEYDEF_SCREEN
	{ 0, CMD_SCREEN_KEYDEF, NULL },
#endif

	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Global") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_STOP, NULL },
	{ 0, CMD_PAUSE, NULL },
	{ 0, CMD_CROP, NULL },
	{ 0, CMD_TRACK_NEXT, NULL },
	{ 0, CMD_TRACK_PREVIOUS, NULL },
	{ 0, CMD_SEEK_FORWARD, NULL },
	{ 0, CMD_SEEK_BACKWARD, NULL },
	{ 0, CMD_VOLUME_DOWN, NULL },
	{ 0, CMD_VOLUME_UP, NULL },
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_REPEAT, NULL },
	{ 0, CMD_RANDOM, NULL },
	{ 0, CMD_SINGLE, NULL },
	{ 0, CMD_CONSUME, NULL },
	{ 0, CMD_CROSSFADE, NULL },
	{ 0, CMD_SHUFFLE, NULL },
	{ 0, CMD_DB_UPDATE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_LIST_FIND, NULL },
	{ 0, CMD_LIST_RFIND, NULL },
	{ 0, CMD_LIST_FIND_NEXT, NULL },
	{ 0, CMD_LIST_RFIND_NEXT, NULL },
	{ 0, CMD_LIST_JUMP, NULL },
	{ 0, CMD_TOGGLE_FIND_WRAP, NULL },
	{ 0, CMD_LOCATE, NULL },
#ifdef ENABLE_SONG_SCREEN
	{ 0, CMD_SCREEN_SONG, NULL },
#endif
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_QUIT, NULL },

	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Queue screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_PLAY, N_("Play") },
	{ 0, CMD_DELETE, NULL },
	{ 0, CMD_CLEAR, NULL },
	{ 0, CMD_LIST_MOVE_UP, N_("Move song up") },
	{ 0, CMD_LIST_MOVE_DOWN, N_("Move song down") },
	{ 0, CMD_ADD, NULL },
	{ 0, CMD_SAVE_PLAYLIST, NULL },
	{ 0, CMD_SCREEN_UPDATE, N_("Center") },
	{ 0, CMD_SELECT_PLAYING, NULL },
	{ 0, CMD_TOGGLE_AUTOCENTER, NULL },

	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Browse screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_PLAY, N_("Enter directory/Select and play song") },
	{ 0, CMD_SELECT, NULL },
	{ 0, CMD_ADD, N_("Append song to queue") },
	{ 0, CMD_SAVE_PLAYLIST, NULL },
	{ 0, CMD_DELETE, N_("Delete playlist") },
	{ 0, CMD_GO_PARENT_DIRECTORY, NULL },
	{ 0, CMD_GO_ROOT_DIRECTORY, NULL },
	{ 0, CMD_SCREEN_UPDATE, NULL },

#ifdef ENABLE_SEARCH_SCREEN
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Search screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_SCREEN_SEARCH, N_("Search") },
	{ 0, CMD_PLAY, N_("Select and play") },
	{ 0, CMD_SELECT, NULL },
	{ 0, CMD_ADD, N_("Append song to queue") },
	{ 0, CMD_SELECT_ALL,	 NULL },
	{ 0, CMD_SEARCH_MODE, NULL },
#endif
#ifdef ENABLE_LYRICS_SCREEN
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Lyrics screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_SCREEN_LYRICS, N_("View Lyrics") },
	{ 0, CMD_SELECT, N_("(Re)load lyrics") },
	/* to translators: this hotkey aborts the retrieval of lyrics
	   from the server */
	{ 0, CMD_INTERRUPT, N_("Interrupt retrieval") },
	{ 0, CMD_LYRICS_UPDATE, N_("Download lyrics for currently playing song") },
	{ 0, CMD_EDIT, N_("Add or edit lyrics") },
	{ 0, CMD_SAVE_PLAYLIST, N_("Save lyrics") },
	{ 0, CMD_DELETE, N_("Delete saved lyrics") },
#endif
#ifdef ENABLE_OUTPUTS_SCREEN
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Outputs screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_PLAY, N_("Enable/disable output") },
#endif
#ifdef ENABLE_CHAT_SCREEN
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Chat screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_PLAY, N_("Write a message") },
#endif
#ifdef ENABLE_KEYDEF_SCREEN
	{ 0, CMD_NONE, NULL },
	{ 0, CMD_NONE, NULL },
	{ 1, CMD_NONE, N_("Keydef screen") },
	{ 2, CMD_NONE, NULL },
	{ 0, CMD_PLAY, N_("Edit keydefs for selected command") },
	{ 0, CMD_DELETE, N_("Remove selected keydef") },
	{ 0, CMD_ADD, N_("Add a keydef") },
	{ 0, CMD_GO_PARENT_DIRECTORY, N_("Go up a level") },
	{ 0, CMD_SAVE_PLAYLIST, N_("Apply and save changes") },
#endif
};

static struct list_window *lw;

static const char *
list_callback(unsigned i, gcc_unused void *data)
{
	const struct help_text_row *row = &help_text[i];

	assert(i < G_N_ELEMENTS(help_text));

	if (row->text != NULL)
		return _(row->text);

	if (row->command != CMD_NONE)
		return get_key_description(row->command);

	return "";
}

static void
help_init(WINDOW *w, int cols, int rows)
{
	lw = list_window_init(w, cols, rows);
	lw->hide_cursor = true;
	list_window_set_length(lw, G_N_ELEMENTS(help_text));
}

static void
help_resize(int cols, int rows)
{
	list_window_resize(lw, cols, rows);
}

static void
help_exit(void)
{
	list_window_free(lw);
}


static const char *
help_title(gcc_unused char *str, gcc_unused size_t size)
{
	return _("Help");
}

static void
screen_help_paint_callback(WINDOW *w, unsigned i,
			   unsigned y, unsigned width,
			   gcc_unused bool selected,
			   gcc_unused const void *data)
{
	const struct help_text_row *row = &help_text[i];

	assert(i < G_N_ELEMENTS(help_text));

	row_color(w, row->highlight ? COLOR_LIST_BOLD : COLOR_LIST, false);

	wclrtoeol(w);

	if (row->command == CMD_NONE) {
		if (row->text != NULL)
			mvwaddstr(w, y, 6, _(row->text));
		else if (row->highlight == 2)
			mvwhline(w, y, 3, '-', width - 6);
	} else {
		const char *key = get_key_names(row->command, true);

		if (utf8_width(key) < 20)
			wmove(w, y, 20 - utf8_width(key));
		waddstr(w, key);
		mvwaddch(w, y, 21, ':');
		mvwaddstr(w, y, 23,
			  row->text != NULL
			  ? _(row->text)
			  : get_key_description(row->command));
	}
}

static void
help_paint(void)
{
	list_window_paint2(lw, screen_help_paint_callback, NULL);
}

static bool
help_cmd(gcc_unused struct mpdclient *c, command_t cmd)
{
	if (list_window_scroll_cmd(lw, cmd)) {
		help_paint();
		wrefresh(lw->w);
		return true;
	}

	list_window_set_cursor(lw, lw->start);
	if (screen_find(lw,  cmd, list_callback, NULL)) {
		/* center the row */
		list_window_center(lw, lw->selected);
		help_paint();
		wrefresh(lw->w);
		return true;
	}

	return false;
}

const struct screen_functions screen_help = {
	.init = help_init,
	.exit = help_exit,
	.resize = help_resize,
	.paint = help_paint,
	.cmd = help_cmd,
	.get_title = help_title,
};