Code

mpdclient: mpdclient_update() returns bool
[ncmpc.git] / src / mpdclient.h
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
6 #include <mpd/tag.h>
8 struct filelist;
10 struct mpdclient {
11         /* playlist */
12         struct mpdclient_playlist playlist;
14         /* Callbacks */
15         GList *error_callbacks;
16         GList *playlist_callbacks;
17         GList *browse_callbacks;
19         struct mpd_connection *connection;
20         struct mpd_status *status;
21         const struct mpd_song *song;
23         int volume;
24         unsigned updatingdb;
25 };
27 /** functions ***************************************************************/
29 gint
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 bool
44 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
45                   gfloat timeout_, const gchar *password);
47 void
48 mpdclient_disconnect(struct mpdclient *c);
50 bool
51 mpdclient_update(struct mpdclient *c);
54 /*** MPD Commands  **********************************************************/
55 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
56 gint mpdclient_cmd_pause(struct mpdclient *c, gint value);
57 gint
58 mpdclient_cmd_crop(struct mpdclient *c);
59 gint mpdclient_cmd_stop(struct mpdclient *c);
60 gint mpdclient_cmd_next(struct mpdclient *c);
61 gint mpdclient_cmd_prev(struct mpdclient *c);
62 gint mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos);
63 gint mpdclient_cmd_shuffle(struct mpdclient *c);
64 gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
65 gint mpdclient_cmd_clear(struct mpdclient *c);
66 gint mpdclient_cmd_repeat(struct mpdclient *c, gint value);
67 gint mpdclient_cmd_random(struct mpdclient *c, gint value);
68 gint mpdclient_cmd_single(struct mpdclient *c, gint value);
69 gint mpdclient_cmd_consume(struct mpdclient *c, gint value);
70 gint mpdclient_cmd_crossfade(struct mpdclient *c, gint value);
71 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
72 gint mpdclient_cmd_volume_up(struct mpdclient *c);
73 gint mpdclient_cmd_volume_down(struct mpdclient *c);
74 gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
76 gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
77 gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
78 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
80 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
81 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
82 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
84 /* list functions */
85 GList *mpdclient_get_artists(struct mpdclient *c);
86 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
89 /*** error callbacks *****************************************************/
91 #define IS_ACK_ERROR(n)       (n & MPD_ERROR_ACK)
92 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
94 typedef void (*mpdc_error_cb_t) (struct mpdclient *c, gint error, const gchar *msg);
96 void mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
97 void mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
99 /*** playlist functions  **************************************************/
101 /* update the complete playlist */
102 bool
103 mpdclient_playlist_update(struct mpdclient *c);
105 /* get playlist changes */
106 bool
107 mpdclient_playlist_update_changes(struct mpdclient *c);
110 /*** mpdclient playlist callbacks *****************************************/
112 #define PLAYLIST_EVENT_UPDATED     0x01
113 #define PLAYLIST_EVENT_CLEAR       0x02
114 #define PLAYLIST_EVENT_DELETE      0x03
115 #define PLAYLIST_EVENT_ADD         0x04
116 #define PLAYLIST_EVENT_MOVE        0x05
119 typedef void (*mpdc_list_cb_t) (struct mpdclient *c, int event, gpointer data);
121 /* install a playlist callback function */
122 void mpdclient_install_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
124 /* remove a playlist callback function */
125 void mpdclient_remove_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
128 /* issue a playlist callback */
129 void mpdclient_playlist_callback(struct mpdclient *c, int event, gpointer data);
132 /*** filelist functions  ***************************************************/
134 struct filelist *
135 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
137 struct filelist *
138 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
139                           enum mpd_tag_type tag,
140                           gchar *filter_utf8);
142 /* add all songs in filelist to the playlist */
143 int
144 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
146 /*** mpdclient browse callbacks ********************************************/
148 #define BROWSE_DB_UPDATED          0x01
149 #define BROWSE_PLAYLIST_SAVED      0x02
150 #define BROWSE_PLAYLIST_DELETED    0x03
153 /* install a playlist callback function */
154 void mpdclient_install_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
156 /* remove a playlist callback function */
157 void mpdclient_remove_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
160 /* issue a playlist callback */
161 void mpdclient_browse_callback(struct mpdclient *c, int event, gpointer data);
163 /* sort by list-format */
164 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
166 #endif