1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2018 The Music Player Daemon Project
3 * Project homepage: http://musicpd.org
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "Command.hxx"
25 #include "util/Compiler.h"
36 #define MAX_COMMAND_KEYS 3
39 std::array<int, MAX_COMMAND_KEYS> keys;
42 bool modified = false;
46 bool HasKey(int key) const {
47 return std::find(keys.begin(), keys.end(), key) != keys.end();
51 size_t GetKeyCount() const {
52 return std::distance(keys.begin(),
53 std::find(keys.begin(), keys.end(), 0));
56 void SetKey(const std::array<int, MAX_COMMAND_KEYS> &_keys) {
64 void WriteToFile(FILE *f, const command_definition_t &cmd,
70 std::array<KeyBinding, size_t(Command::NONE)> key_bindings;
73 Command FindKey(int key) const;
76 const char *GetKeyNames(Command command, bool all) const;
78 void SetKey(Command command,
79 const std::array<int, MAX_COMMAND_KEYS> &keys) {
80 auto &b = key_bindings[size_t(command)];
86 * @return true on success, false on error
88 bool Check(char *buf, size_t size) const;
91 * @return true on success, false on error
93 bool WriteToFile(FILE *f, int all) const;
97 /* write key bindings flags */
98 #define KEYDEF_WRITE_HEADER 0x01
99 #define KEYDEF_WRITE_ALL 0x02
100 #define KEYDEF_COMMENT_ALL 0x04