Code

glib_compat.h: remove obsolete header
[ncmpc.git] / src / mpdclient.h
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
6 #include <mpd/client.h>
8 struct filelist;
10 struct mpdclient {
11         /* playlist */
12         struct mpdclient_playlist playlist;
14         struct mpd_connection *connection;
16         /**
17          * This attribute is incremented whenever the connection changes
18          * (i.e. on disconnection and (re-)connection).
19          */
20         unsigned connection_id;
22         /**
23          * If this object is non-NULL, it tracks idle events.  It is
24          * automatically called by mpdclient_get_connection() and
25          * mpdclient_put_connection().  It is not created by the
26          * mpdclient library; the user of this library has to
27          * initialize it.  However, it is freed when the MPD
28          * connection is closed.
29          */
30         struct mpd_glib_source *source;
32         /**
33          * This attribute is true when the connection is currently in
34          * "idle" mode, and the #mpd_glib_source waits for an event.
35          */
36         bool idle;
38         struct mpd_status *status;
39         const struct mpd_song *song;
41         int volume;
42         unsigned update_id;
44         /**
45          * A bit mask of idle events occurred since the last update.
46          */
47         enum mpd_idle events;
48 };
50 enum {
51         /**
52          * all idle events the version of libmpdclient, ncmpc is compiled
53          * against, supports
54          */
55         MPD_IDLE_ALL = MPD_IDLE_DATABASE
56                 | MPD_IDLE_STORED_PLAYLIST
57                 | MPD_IDLE_QUEUE
58                 | MPD_IDLE_PLAYER
59                 | MPD_IDLE_MIXER
60                 | MPD_IDLE_OUTPUT
61                 | MPD_IDLE_OPTIONS
62                 | MPD_IDLE_UPDATE
63 #if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
64                 | MPD_IDLE_STICKER
65                 | MPD_IDLE_SUBSCRIPTION
66                 | MPD_IDLE_MESSAGE
67 #endif
68 };
70 /** functions ***************************************************************/
72 bool
73 mpdclient_handle_error(struct mpdclient *c);
75 static inline bool
76 mpdclient_finish_command(struct mpdclient *c)
77 {
78         return mpd_response_finish(c->connection)
79                 ? true : mpdclient_handle_error(c);
80 }
82 struct mpdclient *
83 mpdclient_new(void);
85 void mpdclient_free(struct mpdclient *c);
87 G_GNUC_PURE
88 static inline bool
89 mpdclient_is_connected(const struct mpdclient *c)
90 {
91         return c->connection != NULL;
92 }
94 G_GNUC_PURE
95 static inline bool
96 mpdclient_is_playing(const struct mpdclient *c)
97 {
98         return c->status != NULL &&
99                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
100                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
103 G_GNUC_PURE
104 static inline const struct mpd_song *
105 mpdclient_get_current_song(const struct mpdclient *c)
107         return c->song != NULL && mpdclient_is_playing(c)
108                 ? c->song
109                 : NULL;
112 bool
113 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
114                   unsigned timeout_ms, const gchar *password);
116 void
117 mpdclient_disconnect(struct mpdclient *c);
119 bool
120 mpdclient_update(struct mpdclient *c);
122 struct mpd_connection *
123 mpdclient_get_connection(struct mpdclient *c);
125 void
126 mpdclient_put_connection(struct mpdclient *c);
128 /**
129  * To be implemented by the application: mpdclient.c calls this to
130  * display an error message.
131  */
132 void
133 mpdclient_ui_error(const char *message);
135 /*** MPD Commands  **********************************************************/
137 bool
138 mpdclient_cmd_crop(struct mpdclient *c);
140 bool
141 mpdclient_cmd_clear(struct mpdclient *c);
143 bool
144 mpdclient_cmd_volume(struct mpdclient *c, gint value);
146 bool
147 mpdclient_cmd_volume_up(struct mpdclient *c);
149 bool
150 mpdclient_cmd_volume_down(struct mpdclient *c);
152 bool
153 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
155 bool
156 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
158 bool
159 mpdclient_cmd_delete(struct mpdclient *c, gint index);
161 bool
162 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
164 bool
165 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
167 #if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
168 bool
169 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
171 bool
172 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
174 bool
175 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
176                            const char *text);
178 bool
179 mpdclient_send_read_messages(struct mpdclient *c);
181 struct mpd_message *
182 mpdclient_recv_message(struct mpdclient *c);
183 #endif
185 /*** playlist functions  **************************************************/
187 /* update the complete playlist */
188 bool
189 mpdclient_playlist_update(struct mpdclient *c);
191 /* get playlist changes */
192 bool
193 mpdclient_playlist_update_changes(struct mpdclient *c);
195 /* add all songs in filelist to the playlist */
196 bool
197 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
199 /* sort by list-format */
200 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
202 #endif