Fix InternetLyricsFetcher
[ncmpcpp.git] / src / bindings.cpp
blob00b0e446a2ff3c4c95303e06cccb6b1071f9c603
1 /***************************************************************************
2 * Copyright (C) 2008-2017 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
21 #include <boost/algorithm/string/trim.hpp>
22 #include <fstream>
23 #include <iostream>
24 #include "global.h"
25 #include "bindings.h"
26 #include "utility/string.h"
27 #include "utility/wide_string.h"
29 BindingsConfiguration Bindings;
31 namespace {
33 void warning(const char *msg)
35 std::cerr << "WARNING: " << msg << "\n";
38 NC::Key::Type stringToKey(const std::string &s);
40 NC::Key::Type stringToSpecialKey(const std::string &s)
42 NC::Key::Type result = NC::Key::None;
43 if (!s.compare(0, 4, "ctrl") && s.length() == 6 && s[4] == '-')
45 if (s[5] >= 'a' && s[5] <= 'z')
46 result = NC::Key::Ctrl_A + (s[5] - 'a');
47 else if (s[5] == '[')
48 result = NC::Key::Ctrl_LeftBracket;
49 else if (s[5] == '\\')
50 result = NC::Key::Ctrl_Backslash;
51 else if (s[5] == ']')
52 result = NC::Key::Ctrl_RightBracket;
53 else if (s[5] == '^')
54 result = NC::Key::Ctrl_Caret;
55 else if (s[5] == '_')
56 result = NC::Key::Ctrl_Underscore;
58 else if (!s.compare(0, 3, "alt") && s.length() > 3 && s[3] == '-')
60 result = NC::Key::Alt | stringToKey(s.substr(4));
62 else if (!s.compare(0, 4, "ctrl") && s.length() > 4 && s[4] == '-')
64 result = NC::Key::Ctrl | stringToKey(s.substr(5));
66 else if (!s.compare(0, 5, "shift") && s.length() > 5 && s[5] == '-')
68 result = NC::Key::Shift | stringToKey(s.substr(6));
70 else if (!s.compare("escape"))
71 result = NC::Key::Escape;
72 else if (!s.compare("mouse"))
73 result = NC::Key::Mouse;
74 else if (!s.compare("up"))
75 result = NC::Key::Up;
76 else if (!s.compare("down"))
77 result = NC::Key::Down;
78 else if (!s.compare("page_up"))
79 result = NC::Key::PageUp;
80 else if (!s.compare("page_down"))
81 result = NC::Key::PageDown;
82 else if (!s.compare("home"))
83 result = NC::Key::Home;
84 else if (!s.compare("end"))
85 result = NC::Key::End;
86 else if (!s.compare("space"))
87 result = NC::Key::Space;
88 else if (!s.compare("enter"))
89 result = NC::Key::Enter;
90 else if (!s.compare("insert"))
91 result = NC::Key::Insert;
92 else if (!s.compare("delete"))
93 result = NC::Key::Delete;
94 else if (!s.compare("left"))
95 result = NC::Key::Left;
96 else if (!s.compare("right"))
97 result = NC::Key::Right;
98 else if (!s.compare("tab"))
99 result = NC::Key::Tab;
100 else if ((s.length() == 2 || s.length() == 3) && s[0] == 'f')
102 int n = atoi(s.c_str() + 1);
103 if (n >= 1 && n <= 12)
104 result = NC::Key::F1 + n - 1;
106 else if (!s.compare("backspace"))
107 result = NC::Key::Backspace;
108 return result;
111 NC::Key::Type stringToKey(const std::string &s)
113 NC::Key::Type result = stringToSpecialKey(s);
114 if (result == NC::Key::None)
116 std::wstring ws = ToWString(s);
117 if (ws.length() == 1)
118 result = ws[0];
120 return result;
123 template <typename F>
124 std::shared_ptr<Actions::BaseAction> parseActionLine(const std::string &line, F error)
126 std::shared_ptr<Actions::BaseAction> result;
127 size_t i = 0;
128 for (; i < line.size() && !isspace(line[i]); ++i) { }
129 if (i == line.size()) // only action name
131 if (line == "set_visualizer_sample_multiplier")
133 warning("action 'set_visualizer_sample_multiplier' is deprecated"
134 " and will be removed in 0.9");
135 result = Actions::get_(Actions::Type::Dummy);
137 else
138 result = Actions::get_(line);
140 else // there is something else
142 std::string action_name = line.substr(0, i);
143 if (action_name == "push_character")
145 // push single character into input queue
146 std::string arg = getEnclosedString(line, '"', '"', 0);
147 NC::Key::Type k = stringToSpecialKey(arg);
148 if (k != NC::Key::None)
149 result = std::static_pointer_cast<Actions::BaseAction>(
150 std::make_shared<Actions::PushCharacters>(
151 &Global::wFooter,
152 std::vector<NC::Key::Type>{k}));
153 else
154 error() << "invalid character passed to push_character: '" << arg << "'\n";
156 else if (action_name == "push_characters")
158 // push sequence of characters into input queue
159 std::string arg = getEnclosedString(line, '"', '"', 0);
160 if (!arg.empty())
162 // if char is signed, erase 1s from char -> int conversion
163 for (auto it = arg.begin(); it != arg.end(); ++it)
164 *it &= 0xff;
165 result = std::static_pointer_cast<Actions::BaseAction>(
166 std::make_shared<Actions::PushCharacters>(
167 &Global::wFooter,
168 std::vector<NC::Key::Type>{arg.begin(), arg.end()}));
170 else
171 error() << "empty argument passed to push_characters\n";
173 else if (action_name == "require_screen")
175 // require screen of given type
176 std::string arg = getEnclosedString(line, '"', '"', 0);
177 ScreenType screen_type = stringToScreenType(arg);
178 if (screen_type != ScreenType::Unknown)
179 result = std::static_pointer_cast<Actions::BaseAction>(
180 std::make_shared<Actions::RequireScreen>(screen_type));
181 else
182 error() << "unknown screen passed to require_screen: '" << arg << "'\n";
184 else if (action_name == "require_runnable")
186 // require that given action is runnable
187 std::string arg = getEnclosedString(line, '"', '"', 0);
188 auto action = Actions::get_(arg);
189 if (action)
190 result = std::static_pointer_cast<Actions::BaseAction>(
191 std::make_shared<Actions::RequireRunnable>(action));
192 else
193 error() << "unknown action passed to require_runnable: '" << arg << "'\n";
195 else if (action_name == "run_external_command")
197 std::string command = getEnclosedString(line, '"', '"', 0);
198 if (!command.empty())
199 result = std::static_pointer_cast<Actions::BaseAction>(
200 std::make_shared<Actions::RunExternalCommand>(std::move(command)));
201 else
202 error() << "empty command passed to run_external_command\n";
205 return result;
210 NC::Key::Type readKey(NC::Window &w)
212 NC::Key::Type result = NC::Key::None;
213 std::string tmp;
214 NC::Key::Type input;
215 bool alt_pressed = false;
216 while (true)
218 input = w.readKey();
219 if (input == NC::Key::None)
220 break;
221 if (input & NC::Key::Alt)
223 // Complete the key and reapply the mask at the end.
224 alt_pressed = true;
225 input &= ~NC::Key::Alt;
227 if (input > 255) // NC special character
229 result = input;
230 break;
232 else
234 wchar_t wc;
235 tmp += input;
236 size_t conv_res = mbrtowc(&wc, tmp.c_str(), MB_CUR_MAX, 0);
237 if (conv_res == size_t(-1)) // incomplete multibyte character
238 continue;
239 else if (conv_res == size_t(-2)) // garbage character sequence
240 break;
241 else // character complete
243 result = wc;
244 break;
248 if (alt_pressed)
249 result |= NC::Key::Alt;
250 return result;
253 std::wstring keyToWString(const NC::Key::Type key)
255 std::wstring result;
257 if (key == NC::Key::Tab)
258 result += L"Tab";
259 else if (key == NC::Key::Enter)
260 result += L"Enter";
261 else if (key == NC::Key::Escape)
262 result += L"Escape";
263 else if (key >= NC::Key::Ctrl_A && key <= NC::Key::Ctrl_Z)
265 result += L"Ctrl-";
266 result += 'A' + (key - NC::Key::Ctrl_A);
268 else if (key == NC::Key::Ctrl_LeftBracket)
269 result += L"Ctrl-[";
270 else if (key == NC::Key::Ctrl_Backslash)
271 result += L"Ctrl-\\";
272 else if (key == NC::Key::Ctrl_RightBracket)
273 result += L"Ctrl-]";
274 else if (key == NC::Key::Ctrl_Caret)
275 result += L"Ctrl-^";
276 else if (key == NC::Key::Ctrl_Underscore)
277 result += L"Ctrl-_";
278 else if (key & NC::Key::Alt)
280 result += L"Alt-";
281 result += keyToWString(key & ~NC::Key::Alt);
283 else if (key & NC::Key::Ctrl)
285 result += L"Ctrl-";
286 result += keyToWString(key & ~NC::Key::Ctrl);
288 else if (key & NC::Key::Shift)
290 result += L"Shift-";
291 result += keyToWString(key & ~NC::Key::Shift);
293 else if (key == NC::Key::Space)
294 result += L"Space";
295 else if (key == NC::Key::Backspace)
296 result += L"Backspace";
297 else if (key == NC::Key::Insert)
298 result += L"Insert";
299 else if (key == NC::Key::Delete)
300 result += L"Delete";
301 else if (key == NC::Key::Home)
302 result += L"Home";
303 else if (key == NC::Key::End)
304 result += L"End";
305 else if (key == NC::Key::PageUp)
306 result += L"PageUp";
307 else if (key == NC::Key::PageDown)
308 result += L"PageDown";
309 else if (key == NC::Key::Up)
310 result += L"Up";
311 else if (key == NC::Key::Down)
312 result += L"Down";
313 else if (key == NC::Key::Left)
314 result += L"Left";
315 else if (key == NC::Key::Right)
316 result += L"Right";
317 else if (key >= NC::Key::F1 && key <= NC::Key::F9)
319 result += L"F";
320 result += '1' + (key - NC::Key::F1);
322 else if (key >= NC::Key::F10 && key <= NC::Key::F12)
324 result += L"F1";
325 result += '0' + (key - NC::Key::F10);
327 else
328 result += std::wstring(1, key);
330 return result;
333 bool BindingsConfiguration::read(const std::string &file)
335 enum class InProgress { None, Command, Key };
337 bool result = true;
339 std::ifstream f(file);
340 if (!f.is_open())
341 return result;
343 // shared variables
344 InProgress in_progress = InProgress::None;
345 size_t line_no = 0;
346 std::string line;
347 Binding::ActionChain actions;
349 // def_key specific variables
350 NC::Key::Type key = NC::Key::None;
351 std::string strkey;
353 // def_command specific variables
354 bool cmd_immediate = false;
355 std::string cmd_name;
357 auto error = [&]() -> std::ostream & {
358 std::cerr << file << ":" << line_no << ": error: ";
359 in_progress = InProgress::None;
360 result = false;
361 return std::cerr;
364 auto bind_in_progress = [&]() -> bool {
365 if (in_progress == InProgress::Command)
367 if (!actions.empty())
369 m_commands.insert(std::make_pair(cmd_name, Command(std::move(actions), cmd_immediate)));
370 actions.clear();
371 return true;
373 else
375 error() << "definition of command '" << cmd_name << "' cannot be empty\n";
376 return false;
379 else if (in_progress == InProgress::Key)
381 if (!actions.empty())
383 bind(key, actions);
384 actions.clear();
385 return true;
387 else
389 error() << "definition of key '" << strkey << "' cannot be empty\n";
390 return false;
393 return true;
396 const char def_command[] = "def_command";
397 const char def_key[] = "def_key";
399 while (!f.eof() && ++line_no)
401 getline(f, line);
402 if (line.empty() || line[0] == '#')
403 continue;
405 // beginning of command definition
406 if (!line.compare(0, const_strlen(def_command), def_command))
408 if (!bind_in_progress())
409 break;
410 in_progress = InProgress::Command;
411 cmd_name = getEnclosedString(line, '"', '"', 0);
412 if (cmd_name.empty())
414 error() << "command must have non-empty name\n";
415 break;
417 if (m_commands.find(cmd_name) != m_commands.end())
419 error() << "redefinition of command '" << cmd_name << "'\n";
420 break;
422 std::string cmd_type = getEnclosedString(line, '[', ']', 0);
423 if (cmd_type == "immediate")
424 cmd_immediate = true;
425 else if (cmd_type == "deferred")
426 cmd_immediate = false;
427 else
429 error() << "invalid type of command: '" << cmd_type << "'\n";
430 break;
433 // beginning of key definition
434 else if (!line.compare(0, const_strlen(def_key), def_key))
436 if (!bind_in_progress())
437 break;
438 in_progress = InProgress::Key;
439 strkey = getEnclosedString(line, '"', '"', 0);
440 key = stringToKey(strkey);
441 if (key == NC::Key::None)
443 error() << "invalid key: '" << strkey << "'\n";
444 break;
447 else if (isspace(line[0])) // name of action to be bound
449 boost::trim(line);
450 auto action = parseActionLine(line, error);
451 if (action)
452 actions.push_back(action);
453 else
455 error() << "unknown action: '" << line << "'\n";
456 break;
459 else
461 error() << "invalid line: '" << line << "'\n";
462 break;
465 bind_in_progress();
466 f.close();
467 return result;
470 void BindingsConfiguration::generateDefaults()
472 NC::Key::Type k = NC::Key::None;
473 bind(NC::Key::EoF, Actions::Type::Quit);
474 if (notBound(k = stringToKey("mouse")))
475 bind(k, Actions::Type::MouseEvent);
476 if (notBound(k = stringToKey("up")))
477 bind(k, Actions::Type::ScrollUp);
478 if (notBound(k = stringToKey("shift-up")))
479 bind(k, Binding::ActionChain({Actions::get_(Actions::Type::SelectItem), Actions::get_(Actions::Type::ScrollUp)}));
480 if (notBound(k = stringToKey("down")))
481 bind(k, Actions::Type::ScrollDown);
482 if (notBound(k = stringToKey("shift-down")))
483 bind(k, Binding::ActionChain({Actions::get_(Actions::Type::SelectItem), Actions::get_(Actions::Type::ScrollDown)}));
484 if (notBound(k = stringToKey("[")))
485 bind(k, Actions::Type::ScrollUpAlbum);
486 if (notBound(k = stringToKey("]")))
487 bind(k, Actions::Type::ScrollDownAlbum);
488 if (notBound(k = stringToKey("{")))
489 bind(k, Actions::Type::ScrollUpArtist);
490 if (notBound(k = stringToKey("}")))
491 bind(k, Actions::Type::ScrollDownArtist);
492 if (notBound(k = stringToKey("page_up")))
493 bind(k, Actions::Type::PageUp);
494 if (notBound(k = stringToKey("page_down")))
495 bind(k, Actions::Type::PageDown);
496 if (notBound(k = stringToKey("home")))
497 bind(k, Actions::Type::MoveHome);
498 if (notBound(k = stringToKey("end")))
499 bind(k, Actions::Type::MoveEnd);
500 if (notBound(k = stringToKey("insert")))
501 bind(k, Actions::Type::SelectItem);
502 if (notBound(k = stringToKey("enter")))
504 bind(k, Actions::Type::EnterDirectory);
505 bind(k, Actions::Type::ToggleOutput);
506 bind(k, Actions::Type::RunAction);
507 bind(k, Actions::Type::PlayItem);
509 if (notBound(k = stringToKey("space")))
511 bind(k, Actions::Type::AddItemToPlaylist);
512 bind(k, Actions::Type::ToggleLyricsUpdateOnSongChange);
513 bind(k, Actions::Type::ToggleVisualizationType);
515 if (notBound(k = stringToKey("delete")))
517 bind(k, Actions::Type::DeletePlaylistItems);
518 bind(k, Actions::Type::DeleteBrowserItems);
519 bind(k, Actions::Type::DeleteStoredPlaylist);
521 if (notBound(k = stringToKey("right")))
523 bind(k, Actions::Type::NextColumn);
524 bind(k, Actions::Type::SlaveScreen);
525 bind(k, Actions::Type::VolumeUp);
527 if (notBound(k = stringToKey("+")))
528 bind(k, Actions::Type::VolumeUp);
529 if (notBound(k = stringToKey("left")))
531 bind(k, Actions::Type::PreviousColumn);
532 bind(k, Actions::Type::MasterScreen);
533 bind(k, Actions::Type::VolumeDown);
535 if (notBound(k = stringToKey("-")))
536 bind(k, Actions::Type::VolumeDown);
537 if (notBound(k = stringToKey(":")))
538 bind(k, Actions::Type::ExecuteCommand);
539 if (notBound(k = stringToKey("tab")))
540 bind(k, Actions::Type::NextScreen);
541 if (notBound(k = stringToKey("shift-tab")))
542 bind(k, Actions::Type::PreviousScreen);
543 if (notBound(k = stringToKey("f1")))
544 bind(k, Actions::Type::ShowHelp);
545 if (notBound(k = stringToKey("1")))
546 bind(k, Actions::Type::ShowPlaylist);
547 if (notBound(k = stringToKey("2")))
549 bind(k, Actions::Type::ShowBrowser);
550 bind(k, Actions::Type::ChangeBrowseMode);
552 if (notBound(k = stringToKey("3")))
554 bind(k, Actions::Type::ShowSearchEngine);
555 bind(k, Actions::Type::ResetSearchEngine);
557 if (notBound(k = stringToKey("4")))
559 bind(k, Actions::Type::ShowMediaLibrary);
560 bind(k, Actions::Type::ToggleMediaLibraryColumnsMode);
562 if (notBound(k = stringToKey("5")))
563 bind(k, Actions::Type::ShowPlaylistEditor);
564 if (notBound(k = stringToKey("6")))
565 bind(k, Actions::Type::ShowTagEditor);
566 if (notBound(k = stringToKey("7")))
567 bind(k, Actions::Type::ShowOutputs);
568 if (notBound(k = stringToKey("8")))
569 bind(k, Actions::Type::ShowVisualizer);
570 if (notBound(k = stringToKey("=")))
571 bind(k, Actions::Type::ShowClock);
572 if (notBound(k = stringToKey("@")))
573 bind(k, Actions::Type::ShowServerInfo);
574 if (notBound(k = stringToKey("s")))
575 bind(k, Actions::Type::Stop);
576 if (notBound(k = stringToKey("p")))
577 bind(k, Actions::Type::Pause);
578 if (notBound(k = stringToKey(">")))
579 bind(k, Actions::Type::Next);
580 if (notBound(k = stringToKey("<")))
581 bind(k, Actions::Type::Previous);
582 if (notBound(k = stringToKey("ctrl-h")))
584 bind(k, Actions::Type::JumpToParentDirectory);
585 bind(k, Actions::Type::ReplaySong);
587 if (notBound(k = stringToKey("backspace")))
589 bind(k, Actions::Type::JumpToParentDirectory);
590 bind(k, Actions::Type::ReplaySong);
592 if (notBound(k = stringToKey("f")))
593 bind(k, Actions::Type::SeekForward);
594 if (notBound(k = stringToKey("b")))
595 bind(k, Actions::Type::SeekBackward);
596 if (notBound(k = stringToKey("r")))
597 bind(k, Actions::Type::ToggleRepeat);
598 if (notBound(k = stringToKey("z")))
599 bind(k, Actions::Type::ToggleRandom);
600 if (notBound(k = stringToKey("y")))
602 bind(k, Actions::Type::SaveTagChanges);
603 bind(k, Actions::Type::StartSearching);
604 bind(k, Actions::Type::ToggleSingle);
606 if (notBound(k = stringToKey("R")))
607 bind(k, Actions::Type::ToggleConsume);
608 if (notBound(k = stringToKey("Y")))
609 bind(k, Actions::Type::ToggleReplayGainMode);
610 if (notBound(k = stringToKey("T")))
611 bind(k, Actions::Type::ToggleAddMode);
612 if (notBound(k = stringToKey("|")))
613 bind(k, Actions::Type::ToggleMouse);
614 if (notBound(k = stringToKey("#")))
615 bind(k, Actions::Type::ToggleBitrateVisibility);
616 if (notBound(k = stringToKey("Z")))
617 bind(k, Actions::Type::Shuffle);
618 if (notBound(k = stringToKey("x")))
619 bind(k, Actions::Type::ToggleCrossfade);
620 if (notBound(k = stringToKey("X")))
621 bind(k, Actions::Type::SetCrossfade);
622 if (notBound(k = stringToKey("u")))
623 bind(k, Actions::Type::UpdateDatabase);
624 if (notBound(k = stringToKey("ctrl-s")))
626 bind(k, Actions::Type::SortPlaylist);
627 bind(k, Actions::Type::ToggleBrowserSortMode);
628 bind(k, Actions::Type::ToggleMediaLibrarySortMode);
630 if (notBound(k = stringToKey("ctrl-r")))
631 bind(k, Actions::Type::ReversePlaylist);
632 if (notBound(k = stringToKey("ctrl-f")))
633 bind(k, Actions::Type::ApplyFilter);
634 if (notBound(k = stringToKey("ctrl-_")))
635 bind(k, Actions::Type::SelectFoundItems);
636 if (notBound(k = stringToKey("/")))
638 bind(k, Actions::Type::Find);
639 bind(k, Actions::Type::FindItemForward);
641 if (notBound(k = stringToKey("?")))
643 bind(k, Actions::Type::Find);
644 bind(k, Actions::Type::FindItemBackward);
646 if (notBound(k = stringToKey(".")))
647 bind(k, Actions::Type::NextFoundItem);
648 if (notBound(k = stringToKey(",")))
649 bind(k, Actions::Type::PreviousFoundItem);
650 if (notBound(k = stringToKey("w")))
651 bind(k, Actions::Type::ToggleFindMode);
652 if (notBound(k = stringToKey("e")))
654 bind(k, Actions::Type::EditSong);
655 bind(k, Actions::Type::EditLibraryTag);
656 bind(k, Actions::Type::EditLibraryAlbum);
657 bind(k, Actions::Type::EditDirectoryName);
658 bind(k, Actions::Type::EditPlaylistName);
659 bind(k, Actions::Type::EditLyrics);
661 if (notBound(k = stringToKey("i")))
662 bind(k, Actions::Type::ShowSongInfo);
663 if (notBound(k = stringToKey("I")))
664 bind(k, Actions::Type::ShowArtistInfo);
665 if (notBound(k = stringToKey("g")))
666 bind(k, Actions::Type::JumpToPositionInSong);
667 if (notBound(k = stringToKey("l")))
668 bind(k, Actions::Type::ShowLyrics);
669 if (notBound(k = stringToKey("ctrl-v")))
670 bind(k, Actions::Type::SelectRange);
671 if (notBound(k = stringToKey("v")))
672 bind(k, Actions::Type::ReverseSelection);
673 if (notBound(k = stringToKey("V")))
674 bind(k, Actions::Type::RemoveSelection);
675 if (notBound(k = stringToKey("B")))
676 bind(k, Actions::Type::SelectAlbum);
677 if (notBound(k = stringToKey("a")))
678 bind(k, Actions::Type::AddSelectedItems);
679 if (notBound(k = stringToKey("c")))
681 bind(k, Actions::Type::ClearPlaylist);
682 bind(k, Actions::Type::ClearMainPlaylist);
684 if (notBound(k = stringToKey("C")))
686 bind(k, Actions::Type::CropPlaylist);
687 bind(k, Actions::Type::CropMainPlaylist);
689 if (notBound(k = stringToKey("m")))
691 bind(k, Actions::Type::MoveSortOrderUp);
692 bind(k, Actions::Type::MoveSelectedItemsUp);
694 if (notBound(k = stringToKey("n")))
696 bind(k, Actions::Type::MoveSortOrderDown);
697 bind(k, Actions::Type::MoveSelectedItemsDown);
699 if (notBound(k = stringToKey("M")))
700 bind(k, Actions::Type::MoveSelectedItemsTo);
701 if (notBound(k = stringToKey("A")))
702 bind(k, Actions::Type::Add);
703 if (notBound(k = stringToKey("S")))
704 bind(k, Actions::Type::SavePlaylist);
705 if (notBound(k = stringToKey("o")))
706 bind(k, Actions::Type::JumpToPlayingSong);
707 if (notBound(k = stringToKey("G")))
709 bind(k, Actions::Type::JumpToBrowser);
710 bind(k, Actions::Type::JumpToPlaylistEditor);
712 if (notBound(k = stringToKey("~")))
713 bind(k, Actions::Type::JumpToMediaLibrary);
714 if (notBound(k = stringToKey("E")))
715 bind(k, Actions::Type::JumpToTagEditor);
716 if (notBound(k = stringToKey("U")))
717 bind(k, Actions::Type::TogglePlayingSongCentering);
718 if (notBound(k = stringToKey("P")))
719 bind(k, Actions::Type::ToggleDisplayMode);
720 if (notBound(k = stringToKey("\\")))
721 bind(k, Actions::Type::ToggleInterface);
722 if (notBound(k = stringToKey("!")))
723 bind(k, Actions::Type::ToggleSeparatorsBetweenAlbums);
724 if (notBound(k = stringToKey("L")))
725 bind(k, Actions::Type::ToggleLyricsFetcher);
726 if (notBound(k = stringToKey("F")))
727 bind(k, Actions::Type::FetchLyricsInBackground);
728 if (notBound(k = stringToKey("alt-l")))
729 bind(k, Actions::Type::ToggleFetchingLyricsInBackground);
730 if (notBound(k = stringToKey("ctrl-l")))
731 bind(k, Actions::Type::ToggleScreenLock);
732 if (notBound(k = stringToKey("`")))
734 bind(k, Actions::Type::ToggleLibraryTagType);
735 bind(k, Actions::Type::RefetchLyrics);
736 bind(k, Actions::Type::AddRandomItems);
738 if (notBound(k = stringToKey("ctrl-p")))
739 bind(k, Actions::Type::SetSelectedItemsPriority);
740 if (notBound(k = stringToKey("q")))
741 bind(k, Actions::Type::Quit);
744 const Command *BindingsConfiguration::findCommand(const std::string &name)
746 const Command *ptr = nullptr;
747 auto it = m_commands.find(name);
748 if (it != m_commands.end())
749 ptr = &it->second;
750 return ptr;
753 BindingsConfiguration::BindingIteratorPair BindingsConfiguration::get(const NC::Key::Type &k)
755 std::pair<BindingIterator, BindingIterator> result;
756 auto it = m_bindings.find(k);
757 if (it != m_bindings.end()) {
758 result.first = it->second.begin();
759 result.second = it->second.end();
760 } else {
761 auto list_end = m_bindings.begin()->second.end();
762 result.first = list_end;
763 result.second = list_end;
765 return result;