conf: merge two translatable strings
[ncmpc.git] / src / mpdclient.h
blob1d3b6e0b547d61f292480d6eff9da533230e4a03
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "config.h"
5 #include "playlist.h"
6 #include "Compiler.h"
8 #include <mpd/client.h>
10 struct filelist;
12 struct mpdclient {
13 #ifdef ENABLE_ASYNC_CONNECT
14 /**
15 * These settings are used to connect to MPD asynchronously.
17 struct mpd_settings *settings;
19 #ifndef WIN32
20 /**
21 * A second set of settings, just in case #settings did not
22 * work. This is only used if #settings refers to a local
23 * socket path, and this one is supposed to be a fallback to
24 * IP on the default port (6600).
26 struct mpd_settings *settings2;
27 #endif
29 #else
30 const char *host;
31 unsigned port;
32 #endif
34 unsigned timeout_ms;
36 const char *password;
38 /* playlist */
39 struct mpdclient_playlist playlist;
41 #ifdef ENABLE_ASYNC_CONNECT
42 struct aconnect *async_connect;
43 #endif
45 struct mpd_connection *connection;
47 /**
48 * Tracks idle events. It is automatically called by
49 * mpdclient_get_connection().
51 struct mpd_glib_source *source;
53 struct mpd_status *status;
54 const struct mpd_song *song;
56 /**
57 * The GLib source id which re-enters MPD idle mode before the
58 * next main loop interation.
60 unsigned enter_idle_source_id;
62 /**
63 * This attribute is incremented whenever the connection changes
64 * (i.e. on disconnection and (re-)connection).
66 unsigned connection_id;
68 int volume;
70 /**
71 * A bit mask of idle events occurred since the last update.
73 enum mpd_idle events;
75 #if defined(ENABLE_ASYNC_CONNECT) && !defined(WIN32)
76 bool connecting2;
77 #endif
79 /**
80 * This attribute is true when the connection is currently in
81 * "idle" mode, and the #mpd_glib_source waits for an event.
83 bool idle;
85 /**
86 * Is MPD currently playing?
88 bool playing;
91 enum {
92 /**
93 * all idle events the version of libmpdclient, ncmpc is compiled
94 * against, supports
96 MPD_IDLE_ALL = MPD_IDLE_DATABASE
97 | MPD_IDLE_STORED_PLAYLIST
98 | MPD_IDLE_QUEUE
99 | MPD_IDLE_PLAYER
100 | MPD_IDLE_MIXER
101 | MPD_IDLE_OUTPUT
102 | MPD_IDLE_OPTIONS
103 | MPD_IDLE_UPDATE
104 | MPD_IDLE_STICKER
105 | MPD_IDLE_SUBSCRIPTION
106 | MPD_IDLE_MESSAGE
109 /** functions ***************************************************************/
111 bool
112 mpdclient_handle_error(struct mpdclient *c);
114 static inline bool
115 mpdclient_finish_command(struct mpdclient *c)
117 return mpd_response_finish(c->connection)
118 ? true : mpdclient_handle_error(c);
121 struct mpdclient *
122 mpdclient_new(const gchar *host, unsigned port,
123 unsigned timeout_ms, const gchar *password);
125 void mpdclient_free(struct mpdclient *c);
128 * Determine a human-readable "name" of the settings currently used to
129 * connect to MPD.
131 * @return an allocated string that needs to be freed (with g_free())
132 * by the caller
134 char *
135 mpdclient_settings_name(const struct mpdclient *c);
137 gcc_pure
138 static inline bool
139 mpdclient_is_connected(const struct mpdclient *c)
141 return c->connection != NULL;
145 * Is this object "dead"? i.e. not connected and not currently doing
146 * anything to connect.
148 gcc_pure
149 static inline bool
150 mpdclient_is_dead(const struct mpdclient *c)
152 return c->connection == NULL
153 #ifdef ENABLE_ASYNC_CONNECT
154 && c->async_connect == NULL
155 #endif
159 gcc_pure
160 static inline bool
161 mpdclient_is_playing(const struct mpdclient *c)
163 return c->status != NULL &&
164 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
165 mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
168 gcc_pure
169 static inline const struct mpd_song *
170 mpdclient_get_current_song(const struct mpdclient *c)
172 return c->song != NULL && mpdclient_is_playing(c)
173 ? c->song
174 : NULL;
177 void
178 mpdclient_connect(struct mpdclient *c);
180 void
181 mpdclient_disconnect(struct mpdclient *c);
183 bool
184 mpdclient_update(struct mpdclient *c);
186 struct mpd_connection *
187 mpdclient_get_connection(struct mpdclient *c);
189 /*** MPD Commands **********************************************************/
191 bool
192 mpdclient_cmd_crop(struct mpdclient *c);
194 bool
195 mpdclient_cmd_clear(struct mpdclient *c);
197 bool
198 mpdclient_cmd_volume(struct mpdclient *c, gint value);
200 bool
201 mpdclient_cmd_volume_up(struct mpdclient *c);
203 bool
204 mpdclient_cmd_volume_down(struct mpdclient *c);
206 bool
207 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
209 bool
210 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
212 bool
213 mpdclient_cmd_delete(struct mpdclient *c, gint index);
215 bool
216 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
218 bool
219 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
221 bool
222 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
224 bool
225 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
227 bool
228 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
229 const char *text);
231 bool
232 mpdclient_send_read_messages(struct mpdclient *c);
234 struct mpd_message *
235 mpdclient_recv_message(struct mpdclient *c);
237 /*** playlist functions **************************************************/
239 /* update the complete playlist */
240 bool
241 mpdclient_playlist_update(struct mpdclient *c);
243 /* get playlist changes */
244 bool
245 mpdclient_playlist_update_changes(struct mpdclient *c);
247 /* add all songs in filelist to the playlist */
248 bool
249 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
251 #endif