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 * If this object is non-NULL, it tracks idle events. It is
18 * automatically called by mpdclient_get_connection() and
19 * mpdclient_put_connection(). It is not created by the
20 * mpdclient library; the user of this library has to
21 * initialize it. However, it is freed when the MPD
22 * connection is closed.
23 */
24 struct mpd_glib_source *source;
26 /**
27 * This attribute is true when the connection is currently in
28 * "idle" mode, and the #mpd_glib_source waits for an event.
29 */
30 bool idle;
32 struct mpd_status *status;
33 const struct mpd_song *song;
35 int volume;
36 unsigned update_id;
38 /**
39 * A bit mask of idle events occured since the last update.
40 */
41 enum mpd_idle events;
42 };
44 /** functions ***************************************************************/
46 bool
47 mpdclient_handle_error(struct mpdclient *c);
49 struct mpdclient *
50 mpdclient_new(void);
52 void mpdclient_free(struct mpdclient *c);
54 static inline bool
55 mpdclient_is_connected(const struct mpdclient *c)
56 {
57 return c->connection != NULL;
58 }
60 static inline const struct mpd_song *
61 mpdclient_get_current_song(const struct mpdclient *c)
62 {
63 return c->song != NULL && c->status != NULL &&
64 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
65 mpd_status_get_state(c->status) == MPD_STATE_PAUSE)
66 ? c->song
67 : NULL;
68 }
70 bool
71 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
72 gfloat timeout_, const gchar *password);
74 void
75 mpdclient_disconnect(struct mpdclient *c);
77 bool
78 mpdclient_update(struct mpdclient *c);
80 struct mpd_connection *
81 mpdclient_get_connection(struct mpdclient *c);
83 void
84 mpdclient_put_connection(struct mpdclient *c);
86 /**
87 * To be implemented by the application: mpdclient.c calls this to
88 * display an error message.
89 */
90 void
91 mpdclient_ui_error(const char *message);
93 /*** MPD Commands **********************************************************/
95 bool
96 mpdclient_cmd_play(struct mpdclient *c, gint index);
98 bool
99 mpdclient_cmd_crop(struct mpdclient *c);
101 bool
102 mpdclient_cmd_clear(struct mpdclient *c);
104 bool
105 mpdclient_cmd_volume(struct mpdclient *c, gint value);
107 bool
108 mpdclient_cmd_volume_up(struct mpdclient *c);
110 bool
111 mpdclient_cmd_volume_down(struct mpdclient *c);
113 bool
114 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
116 bool
117 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
119 bool
120 mpdclient_cmd_delete(struct mpdclient *c, gint index);
122 bool
123 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
125 bool
126 mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
128 /*** playlist functions **************************************************/
130 /* update the complete playlist */
131 bool
132 mpdclient_playlist_update(struct mpdclient *c);
134 /* get playlist changes */
135 bool
136 mpdclient_playlist_update_changes(struct mpdclient *c);
138 /* add all songs in filelist to the playlist */
139 bool
140 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
142 /* sort by list-format */
143 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
145 #endif