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;
15 struct mpd_status *status;
16 const struct mpd_song *song;
18 int volume;
19 unsigned update_id;
21 /**
22 * A bit mask of idle events occured since the last update.
23 */
24 enum mpd_idle events;
25 };
27 /** functions ***************************************************************/
29 bool
30 mpdclient_handle_error(struct mpdclient *c);
32 struct mpdclient *
33 mpdclient_new(void);
35 void mpdclient_free(struct mpdclient *c);
37 static inline bool
38 mpdclient_is_connected(const struct mpdclient *c)
39 {
40 return c->connection != NULL;
41 }
43 static inline const struct mpd_song *
44 mpdclient_get_current_song(const struct mpdclient *c)
45 {
46 return c->song != NULL && c->status != NULL &&
47 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
48 mpd_status_get_state(c->status) == MPD_STATE_PAUSE)
49 ? c->song
50 : NULL;
51 }
53 bool
54 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
55 gfloat timeout_, const gchar *password);
57 void
58 mpdclient_disconnect(struct mpdclient *c);
60 bool
61 mpdclient_update(struct mpdclient *c);
63 /**
64 * To be implemented by the application: mpdclient.c calls this to
65 * display an error message.
66 */
67 void
68 mpdclient_ui_error(const char *message);
70 /*** MPD Commands **********************************************************/
72 bool
73 mpdclient_cmd_play(struct mpdclient *c, gint index);
75 bool
76 mpdclient_cmd_crop(struct mpdclient *c);
78 bool
79 mpdclient_cmd_clear(struct mpdclient *c);
81 bool
82 mpdclient_cmd_volume(struct mpdclient *c, gint value);
84 bool
85 mpdclient_cmd_volume_up(struct mpdclient *c);
87 bool
88 mpdclient_cmd_volume_down(struct mpdclient *c);
90 bool
91 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
93 bool
94 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
96 bool
97 mpdclient_cmd_delete(struct mpdclient *c, gint index);
99 bool
100 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
102 bool
103 mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
105 /* list functions */
106 GList *mpdclient_get_artists(struct mpdclient *c);
107 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
109 /*** playlist functions **************************************************/
111 /* update the complete playlist */
112 bool
113 mpdclient_playlist_update(struct mpdclient *c);
115 /* get playlist changes */
116 bool
117 mpdclient_playlist_update_changes(struct mpdclient *c);
119 /* add all songs in filelist to the playlist */
120 bool
121 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
123 /* sort by list-format */
124 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
126 #endif