1 /***************************************************************************
2 * Copyright (C) 2008-2014 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"
30 #include "screen_switcher.h"
32 using Global::MainHeight
;
33 using Global::MainStartY
;
39 std::string
display_keys(const Actions::Type at
)
41 std::wstring result
, skey
;
42 for (auto it
= Bindings
.begin(); it
!= Bindings
.end(); ++it
)
44 for (auto j
= it
->second
.begin(); j
!= it
->second
.end(); ++j
)
46 if (j
->isSingle() && j
->action()->type() == at
)
48 skey
= keyToWString(it
->first
);
51 result
+= std::move(skey
);
57 size_t i
= 0, len
= 0;
58 const size_t max_len
= 20;
59 for (; i
< result
.size(); ++i
)
61 int width
= std::max(1, wcwidth(result
[i
]));
62 if (len
+width
> max_len
)
67 result
.resize(i
+ max_len
- len
, ' ');
68 return ToString(result
);
71 void section(NC::Scrollpad
&w
, const char *type_
, const char *title_
)
73 w
<< "\n " << NC::Format::Bold
;
76 w
<< title_
<< NC::Format::NoBold
<< "\n\n";
79 /**********************************************************************/
81 void key_section(NC::Scrollpad
&w
, const char *title_
)
83 section(w
, "Keys", title_
);
86 void key(NC::Scrollpad
&w
, const Actions::Type at
, const char *desc
)
88 w
<< " " << display_keys(at
) << " : " << desc
<< '\n';
91 void key(NC::Scrollpad
&w
, const Actions::Type at
, const boost::format
&desc
)
93 w
<< " " << display_keys(at
) << " : " << desc
.str() << '\n';
96 /**********************************************************************/
98 void mouse_section(NC::Scrollpad
&w
, const char *title_
)
100 section(w
, "Mouse", title_
);
103 void mouse(NC::Scrollpad
&w
, std::string action
, const char *desc
, bool indent
= false)
105 action
.resize(31 - (indent
? 2 : 0), ' ');
106 w
<< " " << (indent
? " " : "") << action
;
107 w
<< ": " << desc
<< '\n';
110 void mouse_column(NC::Scrollpad
&w
, const char *column
)
112 w
<< NC::Format::Bold
<< " " << column
<< " column:\n" << NC::Format::NoBold
;
115 /**********************************************************************/
117 void write_bindings(NC::Scrollpad
&w
)
121 key_section(w
, "Movement");
122 key(w
, Type::ScrollUp
, "Move cursor up");
123 key(w
, Type::ScrollDown
, "Move cursor down");
124 key(w
, Type::ScrollUpAlbum
, "Move cursor up one album");
125 key(w
, Type::ScrollDownAlbum
, "Move cursor down one album");
126 key(w
, Type::ScrollUpArtist
, "Move cursor up one artist");
127 key(w
, Type::ScrollDownArtist
, "Move cursor down one artist");
128 key(w
, Type::PageUp
, "Page up");
129 key(w
, Type::PageDown
, "Page down");
130 key(w
, Type::MoveHome
, "Home");
131 key(w
, Type::MoveEnd
, "End");
133 if (Config
.screen_switcher_previous
)
135 key(w
, Type::NextScreen
, "Switch between current and last screen");
136 key(w
, Type::PreviousScreen
, "Switch between current and last screen");
140 key(w
, Type::NextScreen
, "Switch to next screen in sequence");
141 key(w
, Type::PreviousScreen
, "Switch to previous screen in sequence");
143 key(w
, Type::ShowHelp
, "Show help");
144 key(w
, Type::ShowPlaylist
, "Show playlist");
145 key(w
, Type::ShowBrowser
, "Show browser");
146 key(w
, Type::ShowSearchEngine
, "Show search engine");
147 key(w
, Type::ShowMediaLibrary
, "Show media library");
148 key(w
, Type::ShowPlaylistEditor
, "Show playlist editor");
149 # ifdef HAVE_TAGLIB_H
150 key(w
, Type::ShowTagEditor
, "Show tag editor");
151 # endif // HAVE_TAGLIB_H
152 # ifdef ENABLE_OUTPUTS
153 key(w
, Type::ShowOutputs
, "Show outputs");
154 # endif // ENABLE_OUTPUTS
155 # ifdef ENABLE_VISUALIZER
156 key(w
, Type::ShowVisualizer
, "Show music visualizer");
157 # endif // ENABLE_VISUALIZER
159 key(w
, Type::ShowClock
, "Show clock");
160 # endif // ENABLE_CLOCK
162 key(w
, Type::ShowServerInfo
, "Show server info");
164 key_section(w
, "Global");
165 key(w
, Type::Stop
, "Stop");
166 key(w
, Type::Pause
, "Pause");
167 key(w
, Type::Next
, "Next track");
168 key(w
, Type::Previous
, "Previous track");
169 key(w
, Type::ReplaySong
, "Replay playing song");
170 key(w
, Type::SeekForward
, "Seek forward in playing song");
171 key(w
, Type::SeekBackward
, "Seek backward in playing song");
172 key(w
, Type::VolumeDown
,
173 boost::format("Decrease volume by %1%%%") % Config
.volume_change_step
175 key(w
, Type::VolumeUp
,
176 boost::format("Increase volume by %1%%%") % Config
.volume_change_step
179 key(w
, Type::ToggleAddMode
, "Toggle add mode (add or remove/always add)");
180 key(w
, Type::ToggleMouse
, "Toggle mouse support");
181 key(w
, Type::ReverseSelection
, "Reverse selection");
182 key(w
, Type::RemoveSelection
, "Remove selection");
183 key(w
, Type::SelectItem
, "Select current item");
184 key(w
, Type::SelectAlbum
, "Select songs of album around the cursor");
185 key(w
, Type::AddSelectedItems
, "Add selected items to playlist");
186 key(w
, Type::AddRandomItems
, "Add random items to playlist");
188 key(w
, Type::ToggleRepeat
, "Toggle repeat mode");
189 key(w
, Type::ToggleRandom
, "Toggle random mode");
190 key(w
, Type::ToggleSingle
, "Toggle single mode");
191 key(w
, Type::ToggleConsume
, "Toggle consume mode");
192 key(w
, Type::ToggleReplayGainMode
, "Toggle replay gain mode");
193 key(w
, Type::ToggleBitrateVisibility
, "Toggle bitrate visibility");
194 key(w
, Type::Shuffle
, "Shuffle selected range in playlist");
195 key(w
, Type::ToggleCrossfade
, "Toggle crossfade mode");
196 key(w
, Type::SetCrossfade
, "Set crossfade");
197 key(w
, Type::SetVolume
, "Set volume");
198 key(w
, Type::UpdateDatabase
, "Start music database update");
200 key(w
, Type::ExecuteCommand
, "Execute command");
201 key(w
, Type::FindItemForward
, "Find item forward");
202 key(w
, Type::FindItemBackward
, "Find item backward");
203 key(w
, Type::PreviousFoundItem
, "Jump to previous found item");
204 key(w
, Type::NextFoundItem
, "Jump to next found item");
205 key(w
, Type::ToggleFindMode
, "Toggle find mode (normal/wrapped)");
206 key(w
, Type::JumpToBrowser
, "Locate song in browser");
207 key(w
, Type::JumpToMediaLibrary
, "Locate song in media library");
208 key(w
, Type::ToggleScreenLock
, "Lock/unlock current screen");
209 key(w
, Type::MasterScreen
, "Switch to master screen (left one)");
210 key(w
, Type::SlaveScreen
, "Switch to slave screen (right one)");
211 # ifdef HAVE_TAGLIB_H
212 key(w
, Type::JumpToTagEditor
, "Locate song in tag editor");
213 # endif // HAVE_TAGLIB_H
214 key(w
, Type::ToggleDisplayMode
, "Toggle display mode");
215 key(w
, Type::ToggleInterface
, "Toggle user interface");
216 key(w
, Type::ToggleSeparatorsBetweenAlbums
, "Toggle displaying separators between albums");
217 key(w
, Type::JumpToPositionInSong
, "Jump to given position in playing song (formats: mm:ss, x%)");
218 key(w
, Type::ShowSongInfo
, "Show song info");
219 # ifdef HAVE_CURL_CURL_H
220 key(w
, Type::ShowArtistInfo
, "Show artist info");
221 key(w
, Type::ToggleLyricsFetcher
, "Toggle lyrics fetcher");
222 key(w
, Type::ToggleFetchingLyricsInBackground
, "Toggle fetching lyrics for playing songs in background");
223 # endif // HAVE_CURL_CURL_H
224 key(w
, Type::ShowLyrics
, "Show/hide song lyrics");
226 key(w
, Type::Quit
, "Quit");
228 key_section(w
, "Playlist");
229 key(w
, Type::PressEnter
, "Play selected item");
230 key(w
, Type::DeletePlaylistItems
, "Delete selected item(s) from playlist");
231 key(w
, Type::ClearMainPlaylist
, "Clear playlist");
232 key(w
, Type::CropMainPlaylist
, "Clear playlist except selected item(s)");
233 key(w
, Type::SetSelectedItemsPriority
, "Set priority of selected items");
234 key(w
, Type::MoveSelectedItemsUp
, "Move selected item(s) up");
235 key(w
, Type::MoveSelectedItemsDown
, "Move selected item(s) down");
236 key(w
, Type::MoveSelectedItemsTo
, "Move selected item(s) to cursor position");
237 key(w
, Type::Add
, "Add item to playlist");
238 # ifdef HAVE_TAGLIB_H
239 key(w
, Type::EditSong
, "Edit song");
240 # endif // HAVE_TAGLIB_H
241 key(w
, Type::SavePlaylist
, "Save playlist");
242 key(w
, Type::SortPlaylist
, "Sort playlist");
243 key(w
, Type::ReversePlaylist
, "Reverse playlist");
244 key(w
, Type::JumpToPlayingSong
, "Jump to current song");
245 key(w
, Type::TogglePlayingSongCentering
, "Toggle playing song centering");
247 key_section(w
, "Browser");
248 key(w
, Type::PressEnter
, "Enter directory/Add item to playlist and play it");
249 key(w
, Type::AddItemToPlaylist
, "Add item to playlist");
250 # ifdef HAVE_TAGLIB_H
251 key(w
, Type::EditSong
, "Edit song");
252 # endif // HAVE_TAGLIB_H
253 key(w
, Type::EditDirectoryName
, "Edit directory name");
254 key(w
, Type::EditPlaylistName
, "Edit playlist name");
255 key(w
, Type::ChangeBrowseMode
, "Browse MPD database/local filesystem");
256 key(w
, Type::ToggleBrowserSortMode
, "Toggle sort mode");
257 key(w
, Type::JumpToPlayingSong
, "Locate playing song");
258 key(w
, Type::JumpToParentDirectory
, "Jump to parent directory");
259 key(w
, Type::DeleteBrowserItems
, "Delete selected items from disk");
260 key(w
, Type::JumpToPlaylistEditor
, "Jump to playlist editor (playlists only)");
262 key_section(w
, "Search engine");
263 key(w
, Type::PressEnter
, "Add item to playlist and play it/change option");
264 key(w
, Type::AddItemToPlaylist
, "Add item to playlist");
265 # ifdef HAVE_TAGLIB_H
266 key(w
, Type::EditSong
, "Edit song");
267 # endif // HAVE_TAGLIB_H
268 key(w
, Type::StartSearching
, "Start searching");
269 key(w
, Type::ResetSearchEngine
, "Reset search constraints and clear results");
271 key_section(w
, "Media library");
272 key(w
, Type::ToggleMediaLibraryColumnsMode
, "Switch between two/three columns mode");
273 key(w
, Type::PreviousColumn
, "Previous column");
274 key(w
, Type::NextColumn
, "Next column");
275 key(w
, Type::PressEnter
, "Add item to playlist and play it");
276 key(w
, Type::AddItemToPlaylist
, "Add item to playlist");
277 # ifdef HAVE_TAGLIB_H
278 key(w
, Type::EditSong
, "Edit song");
279 # endif // HAVE_TAGLIB_H
280 key(w
, Type::EditLibraryTag
, "Edit tag (left column)/album (middle/right column)");
281 key(w
, Type::ToggleLibraryTagType
, "Toggle type of tag used in left column");
282 key(w
, Type::ToggleMediaLibrarySortMode
, "Toggle sort mode");
284 key_section(w
, "Playlist editor");
285 key(w
, Type::PreviousColumn
, "Previous column");
286 key(w
, Type::NextColumn
, "Next column");
287 key(w
, Type::PressEnter
, "Add item to playlist and play it");
288 key(w
, Type::AddItemToPlaylist
, "Add item to playlist");
289 # ifdef HAVE_TAGLIB_H
290 key(w
, Type::EditSong
, "Edit song");
291 # endif // HAVE_TAGLIB_H
292 key(w
, Type::EditPlaylistName
, "Edit playlist name");
293 key(w
, Type::MoveSelectedItemsUp
, "Move selected item(s) up");
294 key(w
, Type::MoveSelectedItemsDown
, "Move selected item(s) down");
295 key(w
, Type::DeleteStoredPlaylist
, "Delete selected playlists (left column)");
296 key(w
, Type::DeletePlaylistItems
, "Delete selected item(s) from playlist (right column)");
297 key(w
, Type::ClearPlaylist
, "Clear playlist");
298 key(w
, Type::CropPlaylist
, "Clear playlist except selected items");
300 key_section(w
, "Lyrics");
301 key(w
, Type::ToggleLyricsUpdateOnSongChange
, "Toggle lyrics update on song change");
302 key(w
, Type::EditLyrics
, "Open lyrics in external editor");
303 key(w
, Type::RefetchLyrics
, "Refetch lyrics");
305 # ifdef HAVE_TAGLIB_H
306 key_section(w
, "Tiny tag editor");
307 key(w
, Type::PressEnter
, "Edit tag");
308 key(w
, Type::SaveTagChanges
, "Save");
310 key_section(w
, "Tag editor");
311 key(w
, Type::PressEnter
, "Edit tag/filename of selected item (left column)");
312 key(w
, Type::PressEnter
, "Perform operation on all/selected items (middle column)");
313 key(w
, Type::PreviousColumn
, "Previous column");
314 key(w
, Type::NextColumn
, "Next column");
315 key(w
, Type::JumpToParentDirectory
, "Jump to parent directory (left column, directories view)");
316 # endif // HAVE_TAGLIB_H
318 # ifdef ENABLE_OUTPUTS
319 key_section(w
, "Outputs");
320 key(w
, Type::PressEnter
, "Toggle output");
321 # endif // ENABLE_OUTPUTS
323 # if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)
324 key_section(w
, "Music visualizer");
325 key(w
, Type::ToggleVisualizationType
, "Toggle visualization type");
326 key(w
, Type::SetVisualizerSampleMultiplier
, "Set visualizer sample multiplier");
327 # endif // ENABLE_VISUALIZER && HAVE_FFTW3_H
329 mouse_section(w
, "Global");
330 mouse(w
, "Left click on \"Playing/Paused\"", "Play/pause");
331 mouse(w
, "Left click on progressbar", "Jump to pointed position in playing song");
333 mouse(w
, "Mouse wheel on \"Volume: xx\"", "Adjust volume");
334 mouse(w
, "Mouse wheel on main window", "Scroll");
336 mouse_section(w
, "Playlist");
337 mouse(w
, "Left click", "Select pointed item");
338 mouse(w
, "Right click", "Play");
340 mouse_section(w
, "Browser");
341 mouse(w
, "Left click on directory", "Enter pointed directory");
342 mouse(w
, "Right click on directory", "Add pointed directory to playlist");
344 mouse(w
, "Left click on song/playlist", "Add pointed item to playlist");
345 mouse(w
, "Right click on song/playlist", "Add pointed item to playlist and play it");
347 mouse_section(w
, "Search engine");
348 mouse(w
, "Left click", "Highlight/switch value");
349 mouse(w
, "Right click", "Change value");
351 mouse_section(w
, "Media library");
352 mouse_column(w
, "Left/middle");
353 mouse(w
, "Left click", "Select pointed item", true);
354 mouse(w
, "Right click", "Add item to playlist", true);
356 mouse_column(w
, "Right");
357 mouse(w
, "Left Click", "Add pointed item to playlist", true);
358 mouse(w
, "Right Click", "Add pointed item to playlist and play it", true);
360 mouse_section(w
, "Playlist editor");
361 mouse_column(w
, "Left");
362 mouse(w
, "Left click", "Select pointed item", true);
363 mouse(w
, "Right click", "Add item to playlist", true);
365 mouse_column(w
, "Right");
366 mouse(w
, "Left click", "Add pointed item to playlist", true);
367 mouse(w
, "Right click", "Add pointed item to playlist and play it", true);
369 # ifdef HAVE_TAGLIB_H
370 mouse_section(w
, "Tiny tag editor");
371 mouse(w
, "Left click", "Select option");
372 mouse(w
, "Right click", "Set value/execute");
374 mouse_section(w
, "Tag editor");
375 mouse_column(w
, "Left");
376 mouse(w
, "Left click", "Enter pointed directory/select pointed album", true);
377 mouse(w
, "Right click", "Toggle view (directories/albums)", true);
379 mouse_column(w
, "Middle");
380 mouse(w
, "Left click", "Select option", true);
381 mouse(w
, "Right click", "Set value/execute", true);
383 mouse_column(w
, "Right");
384 mouse(w
, "Left click", "Select pointed item", true);
385 mouse(w
, "Right click", "Set value", true);
386 # endif // HAVE_TAGLIB_H
388 # ifdef ENABLE_OUTPUTS
389 mouse_section(w
, "Outputs");
390 mouse(w
, "Left click", "Select pointed output");
391 mouse(w
, "Right click", "Toggle output");
392 # endif // ENABLE_OUTPUTS
394 section(w
, "", "List of available colors");
395 for (int i
= 0; i
< COLORS
; ++i
)
396 w
<< NC::Color(i
, NC::Color::transparent
) << i
+1 << NC::Color::End
<< " ";
402 : Screen(NC::Scrollpad(0, MainStartY
, COLS
, MainHeight
, "", Config
.main_color
, NC::Border()))
410 size_t x_offset
, width
;
411 getWindowResizeParams(x_offset
, width
);
412 w
.resize(width
, MainHeight
);
413 w
.moveTo(x_offset
, MainStartY
);
417 void Help::switchTo()
419 SwitchTo::execute(this);
423 std::wstring
Help::title()