Code

aa794c64cded5415e9c5cd521cb5c3eaddf6b00d
[ncmpc.git] / src / command.h
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
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 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.
18  */
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_SCREEN_UPDATE,
87         CMD_SCREEN_PREVIOUS,
88         CMD_SCREEN_NEXT,
89         CMD_SCREEN_SWAP,
90         CMD_SCREEN_PLAY,
91         CMD_SCREEN_FILE,
92         CMD_SCREEN_ARTIST,
93         CMD_SCREEN_SEARCH,
94         CMD_SCREEN_SONG,
95         CMD_SCREEN_KEYDEF,
96         CMD_SCREEN_HELP,
97         CMD_SCREEN_LYRICS,
98         CMD_SCREEN_OUTPUTS,
99         CMD_SCREEN_CHAT,
100         CMD_LYRICS_UPDATE,
101         CMD_EDIT,
102         CMD_INTERRUPT,
103         CMD_GO_ROOT_DIRECTORY,
104         CMD_GO_PARENT_DIRECTORY,
105         CMD_LOCATE,
106         CMD_QUIT
107 } command_t;
110 #ifndef NCMPC_MINI
111 /* command definition flags */
112 #define COMMAND_KEY_MODIFIED  0x01
113 #define COMMAND_KEY_CONFLICT  0x02
114 #endif
116 /* write key bindings flags */
117 #define KEYDEF_WRITE_HEADER  0x01
118 #define KEYDEF_WRITE_ALL     0x02
119 #define KEYDEF_COMMENT_ALL   0x04
121 typedef struct  {
122         int keys[MAX_COMMAND_KEYS];
123         char flags;
124         command_t command;
125         const char *name;
126         const char *description;
127 } command_definition_t;
129 #ifdef ENABLE_KEYDEF_SCREEN
130 command_definition_t *get_command_definitions(void);
131 size_t get_cmds_max_name_width(command_definition_t *cmds);
132 #endif
134 gcc_pure
135 command_t
136 find_key_command(int key, const command_definition_t *cmds);
138 void command_dump_keys(void);
140 #ifndef NCMPC_MINI
142 /**
143  * @return true on success, false on error
144  */
145 bool
146 check_key_bindings(command_definition_t *cmds, char *buf, size_t size);
148 /**
149  * @return true on success, false on error
150  */
151 bool
152 write_key_bindings(FILE *f, int all);
154 #endif
156 gcc_pure
157 const char *key2str(int key);
159 gcc_pure
160 const char *get_key_description(command_t command);
162 gcc_pure
163 const char *get_key_command_name(command_t command);
165 gcc_pure
166 const char *get_key_names(command_t command, bool all);
168 gcc_pure
169 command_t get_key_command(int key);
171 gcc_pure
172 command_t
173 get_key_command_from_name(const char *name);
175 /**
176  * @return true on success, false on error
177  */
178 bool
179 assign_keys(command_t command, int keys[MAX_COMMAND_KEYS]);
181 #endif