command: return bool for success/failure
[ncmpc.git] / src / command.h
blobe770a1d62aa96124f3443197bb9c31f6e1758f67
1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2010 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.
20 #ifndef COMMAND_H
21 #define COMMAND_H
23 #include "config.h"
24 #include "Compiler.h"
26 #include <stddef.h>
27 #include <stdbool.h>
29 #ifndef NCMPC_MINI
30 #include <stdio.h>
31 #endif
33 #define MAX_COMMAND_KEYS 3
35 /* commands */
36 typedef enum {
37 CMD_NONE = 0,
38 CMD_PLAY,
39 CMD_SELECT,
40 CMD_SELECT_ALL,
41 CMD_PAUSE,
42 CMD_STOP,
43 CMD_CROP,
44 CMD_TRACK_NEXT,
45 CMD_TRACK_PREVIOUS,
46 CMD_SEEK_FORWARD,
47 CMD_SEEK_BACKWARD,
48 CMD_SHUFFLE,
49 CMD_RANDOM,
50 CMD_CLEAR,
51 CMD_DELETE,
52 CMD_REPEAT,
53 CMD_SINGLE,
54 CMD_CONSUME,
55 CMD_CROSSFADE,
56 CMD_DB_UPDATE,
57 CMD_VOLUME_UP,
58 CMD_VOLUME_DOWN,
59 CMD_ADD,
60 CMD_SAVE_PLAYLIST,
61 CMD_TOGGLE_FIND_WRAP,
62 CMD_TOGGLE_AUTOCENTER,
63 CMD_SELECT_PLAYING,
64 CMD_SEARCH_MODE,
65 CMD_LIST_PREVIOUS,
66 CMD_LIST_NEXT,
67 CMD_LIST_TOP,
68 CMD_LIST_MIDDLE,
69 CMD_LIST_BOTTOM,
70 CMD_LIST_FIRST,
71 CMD_LIST_LAST,
72 CMD_LIST_NEXT_PAGE,
73 CMD_LIST_PREVIOUS_PAGE,
74 CMD_LIST_FIND,
75 CMD_LIST_FIND_NEXT,
76 CMD_LIST_RFIND,
77 CMD_LIST_RFIND_NEXT,
78 CMD_LIST_JUMP,
79 CMD_LIST_MOVE_UP,
80 CMD_LIST_MOVE_DOWN,
81 CMD_LIST_RANGE_SELECT,
82 CMD_LIST_SCROLL_UP_LINE,
83 CMD_LIST_SCROLL_DOWN_LINE,
84 CMD_LIST_SCROLL_UP_HALF,
85 CMD_LIST_SCROLL_DOWN_HALF,
86 CMD_MOUSE_EVENT,
87 CMD_SCREEN_UPDATE,
88 CMD_SCREEN_PREVIOUS,
89 CMD_SCREEN_NEXT,
90 CMD_SCREEN_SWAP,
91 CMD_SCREEN_PLAY,
92 CMD_SCREEN_FILE,
93 CMD_SCREEN_ARTIST,
94 CMD_SCREEN_SEARCH,
95 CMD_SCREEN_SONG,
96 CMD_SCREEN_KEYDEF,
97 CMD_SCREEN_HELP,
98 CMD_SCREEN_LYRICS,
99 CMD_SCREEN_OUTPUTS,
100 CMD_SCREEN_CHAT,
101 CMD_LYRICS_UPDATE,
102 CMD_EDIT,
103 CMD_INTERRUPT,
104 CMD_GO_ROOT_DIRECTORY,
105 CMD_GO_PARENT_DIRECTORY,
106 CMD_LOCATE,
107 CMD_QUIT
108 } command_t;
111 #ifndef NCMPC_MINI
112 /* command definition flags */
113 #define COMMAND_KEY_MODIFIED 0x01
114 #define COMMAND_KEY_CONFLICT 0x02
115 #endif
117 /* write key bindings flags */
118 #define KEYDEF_WRITE_HEADER 0x01
119 #define KEYDEF_WRITE_ALL 0x02
120 #define KEYDEF_COMMENT_ALL 0x04
122 typedef struct {
123 int keys[MAX_COMMAND_KEYS];
124 char flags;
125 command_t command;
126 const char *name;
127 const char *description;
128 } command_definition_t;
130 #ifdef ENABLE_KEYDEF_SCREEN
131 command_definition_t *get_command_definitions(void);
132 size_t get_cmds_max_name_width(command_definition_t *cmds);
133 #endif
135 gcc_pure
136 command_t
137 find_key_command(int key, const command_definition_t *cmds);
139 void command_dump_keys(void);
141 #ifndef NCMPC_MINI
144 * @return true on success, false on error
146 bool
147 check_key_bindings(command_definition_t *cmds, char *buf, size_t size);
150 * @return true on success, false on error
152 bool
153 write_key_bindings(FILE *f, int all);
155 #endif
157 gcc_pure
158 const char *key2str(int key);
160 gcc_pure
161 const char *get_key_description(command_t command);
163 gcc_pure
164 const char *get_key_command_name(command_t command);
166 gcc_pure
167 const char *get_key_names(command_t command, bool all);
169 gcc_pure
170 command_t get_key_command(int key);
172 gcc_pure
173 command_t
174 get_key_command_from_name(const char *name);
177 * @return true on success, false on error
179 bool
180 assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]);
182 gcc_pure
183 command_t get_keyboard_command(void);
185 #endif