1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * 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 *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
28 #include "utility/wide_string.h"
31 using Global::MainHeight
;
32 using Global::MainStartY
;
34 Help
*myHelp
= new Help
;
38 std::string
keyToString(const Key
&key
, bool *print_backspace
)
41 if (key
== Key(KEY_UP
, Key::NCurses
))
43 else if (key
== Key(KEY_DOWN
, Key::NCurses
))
45 else if (key
== Key(KEY_PPAGE
, Key::NCurses
))
47 else if (key
== Key(KEY_NPAGE
, Key::NCurses
))
49 else if (key
== Key(KEY_HOME
, Key::NCurses
))
51 else if (key
== Key(KEY_END
, Key::NCurses
))
53 else if (key
== Key(KEY_SPACE
, Key::Standard
))
55 else if (key
== Key(KEY_ENTER
, Key::Standard
))
57 else if (key
== Key(KEY_IC
, Key::NCurses
))
59 else if (key
== Key(KEY_DC
, Key::NCurses
))
61 else if (key
== Key(KEY_RIGHT
, Key::NCurses
))
63 else if (key
== Key(KEY_LEFT
, Key::NCurses
))
65 else if (key
== Key(KEY_TAB
, Key::Standard
))
67 else if (key
== Key(KEY_SHIFT_TAB
, Key::NCurses
))
68 result
+= "Shift-Tab";
69 else if (key
>= Key(KEY_CTRL_A
, Key::Standard
) && key
<= Key(KEY_CTRL_Z
, Key::Standard
))
72 result
+= key
.getChar()+64;
74 else if (key
>= Key(KEY_F1
, Key::NCurses
) && key
<= Key(KEY_F12
, Key::NCurses
))
77 result
+= intTo
<std::string
>::apply(key
.getChar()-264);
79 else if ((key
== Key(KEY_BACKSPACE
, Key::NCurses
) || key
== Key(KEY_BACKSPACE_2
, Key::Standard
)))
81 // since some terminals interpret KEY_BACKSPACE as backspace and other need KEY_BACKSPACE_2,
82 // actions have to be bound to either of them, but we want to display "Backspace" only once,
83 // hance this 'print_backspace' switch.
84 if (!print_backspace
|| *print_backspace
)
86 result
+= "Backspace";
88 *print_backspace
= false;
92 result
+= ToString(std::wstring(1, key
.getChar()));
100 w
= new NC::Scrollpad(0, MainStartY
, COLS
, MainHeight
, "", Config
.main_color
, NC::brNone
);
108 size_t x_offset
, width
;
109 GetWindowResizeParams(x_offset
, width
);
110 w
->resize(width
, MainHeight
);
111 w
->moveTo(x_offset
, MainStartY
);
115 void Help::SwitchTo()
117 using Global::myScreen
;
118 using Global::myLockedScreen
;
120 if (myScreen
== this)
127 UpdateInactiveScreen(this);
129 if (hasToBeResized
|| myLockedScreen
)
132 if (myScreen
!= this && myScreen
->isTabbable())
133 Global::myPrevScreen
= myScreen
;
138 std::wstring
Help::Title()
143 std::string
Help::DisplayKeys(const ActionType at
)
145 bool print_backspace
= true;
147 for (auto it
= Bindings
.begin(); it
!= Bindings
.end(); ++it
)
149 if (it
->second
.isSingle() && it
->second
.action()->Type() == at
)
151 result
+= keyToString(it
->first
, &print_backspace
);
155 result
.resize(16, ' ');
159 void Help::Section(const char *type
, const char *title
)
161 *w
<< L
"\n " << NC::fmtBold
<< ToWString(type
) << L
" - ";
162 *w
<< ToWString(title
) << NC::fmtBoldEnd
<< L
"\n\n";
165 void Help::KeyDesc(const ActionType at
, const char *desc
)
167 *w
<< L
" " << DisplayKeys(at
) << L
" : " << ToWString(desc
) << '\n';
170 void Help::MouseDesc(std::string action
, const char *desc
, bool indent
)
172 action
.resize(31 - (indent
? 2 : 0), ' ');
173 *w
<< L
" " << (indent
? L
" " : L
"") << ToWString(action
);
174 *w
<< L
": " << ToWString(desc
) << '\n';
177 void Help::MouseColumn(const char *column
)
179 *w
<< NC::fmtBold
<< L
" " << ToWString(column
) << L
" column:\n" << NC::fmtBoldEnd
;
182 void Help::GetKeybindings()
184 KeysSection("Movement");
185 KeyDesc(aScrollUp
, "Move cursor up");
186 KeyDesc(aScrollDown
, "Move cursor down");
187 KeyDesc(aScrollUpAlbum
, "Move cursor up one album");
188 KeyDesc(aScrollDownAlbum
, "Move cursor down one album");
189 KeyDesc(aScrollUpArtist
, "Move cursor up one artist");
190 KeyDesc(aScrollDownArtist
, "Move cursor down one artist");
191 KeyDesc(aPageUp
, "Page up");
192 KeyDesc(aPageDown
, "Page down");
193 KeyDesc(aMoveHome
, "Home");
194 KeyDesc(aMoveEnd
, "End");
196 if (Config
.screen_switcher_previous
)
198 KeyDesc(aNextScreen
, "Switch between current and last screen");
199 KeyDesc(aPreviousScreen
, "Switch between current and last screen");
203 KeyDesc(aNextScreen
, "Switch to next screen in sequence");
204 KeyDesc(aPreviousScreen
, "Switch to previous screen in sequence");
206 KeyDesc(aShowHelp
, "Show help");
207 KeyDesc(aShowPlaylist
, "Show playlist");
208 KeyDesc(aShowBrowser
, "Show browser");
209 KeyDesc(aShowSearchEngine
, "Show search engine");
210 KeyDesc(aShowMediaLibrary
, "Show media library");
211 KeyDesc(aShowPlaylistEditor
, "Show playlist editor");
212 # ifdef HAVE_TAGLIB_H
213 KeyDesc(aShowTagEditor
, "Show tag editor");
214 # endif // HAVE_TAGLIB_H
215 # ifdef ENABLE_OUTPUTS
216 KeyDesc(aShowOutputs
, "Show outputs");
217 # endif // ENABLE_OUTPUTS
218 # ifdef ENABLE_VISUALIZER
219 KeyDesc(aShowVisualizer
, "Show music visualizer");
220 # endif // ENABLE_VISUALIZER
222 KeyDesc(aShowClock
, "Show clock");
223 # endif // ENABLE_CLOCK
225 KeyDesc(aShowServerInfo
, "Show server info");
227 KeysSection("Global");
228 KeyDesc(aStop
, "Stop");
229 KeyDesc(aPause
, "Pause");
230 KeyDesc(aNext
, "Next track");
231 KeyDesc(aPrevious
, "Previous track");
232 KeyDesc(aReplaySong
, "Replay playing song");
233 KeyDesc(aSeekForward
, "Seek forward in playing song");
234 KeyDesc(aSeekBackward
, "Seek backward in playing song");
235 KeyDesc(aVolumeDown
, "Decrease volume by 2%");
236 KeyDesc(aVolumeUp
, "Increase volume by 2%");
238 KeyDesc(aToggleSpaceMode
, "Toggle space mode (select/add)");
239 KeyDesc(aToggleAddMode
, "Toggle add mode (add or remove/always add)");
240 KeyDesc(aToggleMouse
, "Toggle mouse support");
241 KeyDesc(aReverseSelection
, "Reverse selection");
242 KeyDesc(aRemoveSelection
, "Remove selection");
243 KeyDesc(aSelectAlbum
, "Select songs of album around the cursor");
244 KeyDesc(aAddSelectedItems
, "Add selected items to playlist");
245 KeyDesc(aAddRandomItems
, "Add random items to playlist");
247 KeyDesc(aToggleRepeat
, "Toggle repeat mode");
248 KeyDesc(aToggleRandom
, "Toggle random mode");
249 KeyDesc(aToggleSingle
, "Toggle single mode");
250 KeyDesc(aToggleConsume
, "Toggle consume mode");
251 KeyDesc(aToggleReplayGainMode
, "Toggle replay gain mode");
252 KeyDesc(aToggleBitrateVisibility
, "Toggle bitrate visibility");
253 KeyDesc(aShuffle
, "Shuffle playlist");
254 KeyDesc(aToggleCrossfade
, "Toggle crossfade mode");
255 KeyDesc(aSetCrossfade
, "Set crossfade");
256 KeyDesc(aUpdateDatabase
, "Start music database update");
258 KeyDesc(aApplyFilter
, "Apply filter");
259 KeyDesc(aFindItemForward
, "Find item forward");
260 KeyDesc(aFindItemBackward
, "Find item backward");
261 KeyDesc(aPreviousFoundItem
, "Jump to previous found item");
262 KeyDesc(aNextFoundItem
, "Jump to next found item");
263 KeyDesc(aToggleFindMode
, "Toggle find mode (normal/wrapped)");
264 KeyDesc(aJumpToBrowser
, "Locate song in browser");
265 KeyDesc(aJumpToMediaLibrary
, "Locate song in media library");
266 KeyDesc(aToggleScreenLock
, "Lock/unlock current screen");
267 KeyDesc(aMasterScreen
, "Switch to master screen (left one)");
268 KeyDesc(aSlaveScreen
, "Switch to slave screen (right one)");
269 # ifdef HAVE_TAGLIB_H
270 KeyDesc(aJumpToTagEditor
, "Locate song in tag editor");
271 # endif // HAVE_TAGLIB_H
272 KeyDesc(aToggleDisplayMode
, "Toggle display mode");
273 KeyDesc(aToggleInterface
, "Toggle user interface");
274 KeyDesc(aToggleSeparatorsBetweenAlbums
, "Toggle displaying separators between albums");
275 KeyDesc(aJumpToPositionInSong
, "Jump to given position in playing song (formats: mm:ss, x%)");
276 KeyDesc(aShowSongInfo
, "Show song info");
277 # ifdef HAVE_CURL_CURL_H
278 KeyDesc(aShowArtistInfo
, "Show artist info");
279 KeyDesc(aToggleLyricsFetcher
, "Toggle lyrics fetcher");
280 KeyDesc(aToggleFetchingLyricsInBackground
, "Toggle fetching lyrics for playing songs in background");
281 # endif // HAVE_CURL_CURL_H
282 KeyDesc(aShowLyrics
, "Show/hide song lyrics");
284 KeyDesc(aQuit
, "Quit");
286 KeysSection("Playlist");
287 KeyDesc(aPressEnter
, "Play selected item");
288 KeyDesc(aDelete
, "Delete selected item(s) from playlist");
289 KeyDesc(aClearMainPlaylist
, "Clear playlist");
290 KeyDesc(aCropMainPlaylist
, "Clear playlist except selected item(s)");
291 KeyDesc(aSetSelectedItemsPriority
, "Set priority of selected items");
292 KeyDesc(aMoveSelectedItemsUp
, "Move selected item(s) up");
293 KeyDesc(aMoveSelectedItemsDown
, "Move selected item(s) down");
294 KeyDesc(aMoveSelectedItemsTo
, "Move selected item(s) to cursor position");
295 KeyDesc(aAdd
, "Add item to playlist");
296 # ifdef HAVE_TAGLIB_H
297 KeyDesc(aEditSong
, "Edit song");
298 # endif // HAVE_TAGLIB_H
299 KeyDesc(aSavePlaylist
, "Save playlist");
300 KeyDesc(aSortPlaylist
, "Sort playlist");
301 KeyDesc(aReversePlaylist
, "Reverse playlist");
302 KeyDesc(aFilterPlaylistOnPriorities
, "Filter playlist on priorities");
303 KeyDesc(aJumpToPlayingSong
, "Jump to playing song");
304 KeyDesc(aTogglePlayingSongCentering
, "Toggle playing song centering");
306 KeysSection("Browser");
307 KeyDesc(aPressEnter
, "Enter directory/Add item to playlist and play it");
308 KeyDesc(aPressSpace
, "Add item to playlist/select it");
309 # ifdef HAVE_TAGLIB_H
310 KeyDesc(aEditSong
, "Edit song");
311 # endif // HAVE_TAGLIB_H
312 KeyDesc(aEditDirectoryName
, "Edit directory name");
313 KeyDesc(aEditPlaylistName
, "Edit playlist name");
314 KeyDesc(aShowBrowser
, "Browse MPD database/local filesystem");
315 KeyDesc(aToggleBrowserSortMode
, "Toggle sort mode");
316 KeyDesc(aJumpToPlayingSong
, "Locate playing song");
317 KeyDesc(aJumpToParentDirectory
, "Jump to parent directory");
318 KeyDesc(aDelete
, "Delete item");
319 KeyDesc(aJumpToPlaylistEditor
, "Jump to playlist editor (playlists only)");
321 KeysSection("Search engine");
322 KeyDesc(aPressEnter
, "Add item to playlist and play it/change option");
323 KeyDesc(aPressSpace
, "Add item to playlist");
324 # ifdef HAVE_TAGLIB_H
325 KeyDesc(aEditSong
, "Edit song");
326 # endif // HAVE_TAGLIB_H
327 KeyDesc(aStartSearching
, "Start searching");
328 KeyDesc(aShowSearchEngine
, "Reset search constraints and clear results");
330 KeysSection("Media library");
331 if (!Config
.media_library_disable_two_column_mode
)
332 KeyDesc(aShowMediaLibrary
, "Switch between two/three columns mode");
333 KeyDesc(aPreviousColumn
, "Previous column");
334 KeyDesc(aNextColumn
, "Next column");
335 KeyDesc(aPressEnter
, "Add item to playlist and play it");
336 KeyDesc(aPressSpace
, "Add item to playlist");
337 # ifdef HAVE_TAGLIB_H
338 KeyDesc(aEditSong
, "Edit song");
339 # endif // HAVE_TAGLIB_H
340 KeyDesc(aEditLibraryTag
, "Edit tag (left column)/album (middle/right column)");
341 KeyDesc(aToggleLibraryTagType
, "Toggle type of tag used in left column");
343 KeysSection("Playlist editor");
344 KeyDesc(aPreviousColumn
, "Previous column");
345 KeyDesc(aNextColumn
, "Next column");
346 KeyDesc(aPressEnter
, "Add item to playlist and play it");
347 KeyDesc(aPressSpace
, "Add item to playlist/select it");
348 # ifdef HAVE_TAGLIB_H
349 KeyDesc(aEditSong
, "Edit song");
350 # endif // HAVE_TAGLIB_H
351 KeyDesc(aEditPlaylistName
, "Edit playlist name");
352 KeyDesc(aMoveSelectedItemsUp
, "Move selected item(s) up");
353 KeyDesc(aMoveSelectedItemsDown
, "Move selected item(s) down");
354 KeyDesc(aClearPlaylist
, "Clear playlist");
355 KeyDesc(aCropPlaylist
, "Clear playlist except selected items");
357 KeysSection("Lyrics");
358 KeyDesc(aPressSpace
, "Toggle reloading lyrics upon song change");
359 KeyDesc(aEditLyrics
, "Open lyrics in external editor");
360 KeyDesc(aRefetchLyrics
, "Refetch lyrics");
362 KeysSection("Artist info");
363 KeyDesc(aRefetchArtistInfo
, "Refetch artist info");
365 # ifdef HAVE_TAGLIB_H
366 KeysSection("Tiny tag editor");
367 KeyDesc(aPressEnter
, "Edit tag");
368 KeyDesc(aSaveTagChanges
, "Save");
370 KeysSection("Tag editor");
371 KeyDesc(aPressEnter
, "Edit tag/filename of selected item (left column)");
372 KeyDesc(aPressEnter
, "Perform operation on all/selected items (middle column)");
373 KeyDesc(aPressSpace
, "Switch to albums/directories view (left column)");
374 KeyDesc(aPressSpace
, "Select item (right column)");
375 KeyDesc(aPreviousColumn
, "Previous column");
376 KeyDesc(aNextColumn
, "Next column");
377 KeyDesc(aJumpToParentDirectory
, "Jump to parent directory (left column, directories view)");
378 # endif // HAVE_TAGLIB_H
380 # ifdef ENABLE_OUTPUTS
381 KeysSection("Outputs");
382 KeyDesc(aPressEnter
, "Toggle output");
383 # endif // ENABLE_OUTPUTS
385 # if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)
386 KeysSection("Music visualizer");
387 KeyDesc(aPressSpace
, "Toggle visualization type");
388 # endif // ENABLE_VISUALIZER && HAVE_FFTW3_H
390 MouseSection("Global");
391 MouseDesc("Left click on \"Playing/Paused\"", "Play/pause");
392 MouseDesc("Left click on progressbar", "Jump to pointed position in playing song");
394 MouseDesc("Mouse wheel on \"Volume: xx\"", "Play/pause");
395 MouseDesc("Mouse wheel on main window", "Scroll");
397 MouseSection("Playlist");
398 MouseDesc("Left click", "Select pointed item");
399 MouseDesc("Right click", "Play");
401 MouseSection("Browser");
402 MouseDesc("Left click on directory", "Enter pointed directory");
403 MouseDesc("Right click on directory", "Add pointed directory to playlist");
405 MouseDesc("Left click on song/playlist", "Add pointed item to playlist");
406 MouseDesc("Right click on song/playlist", "Add pointed item to playlist and play it");
408 MouseSection("Search engine");
409 MouseDesc("Left click", "Highlight/switch value");
410 MouseDesc("Right click", "Change value");
412 MouseSection("Media library");
413 MouseColumn("Left/middle");
414 MouseDesc("Left click", "Select pointed item", true);
415 MouseDesc("Right click", "Add item to playlist", true);
417 MouseColumn("Right");
418 MouseDesc("Left Click", "Add pointed item to playlist", true);
419 MouseDesc("Right Click", "Add pointed item to playlist and play it", true);
421 MouseSection("Playlist editor");
423 MouseDesc("Left click", "Select pointed item", true);
424 MouseDesc("Right click", "Add item to playlist", true);
426 MouseColumn("Right");
427 MouseDesc("Left click", "Add pointed item to playlist", true);
428 MouseDesc("Right click", "Add pointed item to playlist and play it", true);
430 # ifdef HAVE_TAGLIB_H
431 MouseSection("Tiny tag editor");
432 MouseDesc("Left click", "Select option");
433 MouseDesc("Right click", "Set value/execute");
435 MouseSection("Tag editor");
437 MouseDesc("Left click", "Enter pointed directory/select pointed album", true);
438 MouseDesc("Right click", "Toggle view (directories/albums)", true);
440 MouseColumn("Middle");
441 MouseDesc("Left click", "Select option", true);
442 MouseDesc("Right click", "Set value/execute", true);
444 MouseColumn("Right");
445 MouseDesc("Left click", "Select pointed item", true);
446 MouseDesc("Right click", "Set value", true);
447 # endif // HAVE_TAGLIB_H
449 # ifdef ENABLE_OUTPUTS
450 MouseSection("Outputs");
451 MouseDesc("Left click", "Select pointed output");
452 MouseDesc("Right click", "Toggle output");
453 # endif // ENABLE_OUTPUTS