Code

mpdclient: export mpdclient_handle_error()
[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         struct mpd_song *song;
23         int volume;
24         unsigned updatingdb;
25 };
27 /** functions ***************************************************************/
29 gint
30 mpdclient_handle_error(struct mpdclient *c);
32 gint
33 mpdclient_finish_command(struct mpdclient *c);
35 struct mpdclient *
36 mpdclient_new(void);
38 void mpdclient_free(struct mpdclient *c);
40 static inline bool
41 mpdclient_is_connected(const struct mpdclient *c)
42 {
43         return c->connection != NULL;
44 }
46 gint mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
47                        gfloat timeout_, const gchar *password);
48 gint mpdclient_disconnect(struct mpdclient *c);
49 gint mpdclient_update(struct mpdclient *c);
52 /*** MPD Commands  **********************************************************/
53 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
54 gint mpdclient_cmd_pause(struct mpdclient *c, gint value);
55 gint
56 mpdclient_cmd_crop(struct mpdclient *c);
57 gint mpdclient_cmd_stop(struct mpdclient *c);
58 gint mpdclient_cmd_next(struct mpdclient *c);
59 gint mpdclient_cmd_prev(struct mpdclient *c);
60 gint mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos);
61 gint mpdclient_cmd_shuffle(struct mpdclient *c);
62 gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
63 gint mpdclient_cmd_clear(struct mpdclient *c);
64 gint mpdclient_cmd_repeat(struct mpdclient *c, gint value);
65 gint mpdclient_cmd_random(struct mpdclient *c, gint value);
66 gint mpdclient_cmd_single(struct mpdclient *c, gint value);
67 gint mpdclient_cmd_consume(struct mpdclient *c, gint value);
68 gint mpdclient_cmd_crossfade(struct mpdclient *c, gint value);
69 gint mpdclient_cmd_db_update(struct mpdclient *c, const gchar *path);
70 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
71 gint mpdclient_cmd_volume_up(struct mpdclient *c);
72 gint mpdclient_cmd_volume_down(struct mpdclient *c);
73 gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
75 gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
76 gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
77 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
79 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
80 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
81 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
83 /* list functions */
84 GList *mpdclient_get_artists(struct mpdclient *c);
85 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
88 /*** error callbacks *****************************************************/
90 #define IS_ACK_ERROR(n)       (n & MPD_ERROR_ACK)
91 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
93 typedef void (*mpdc_error_cb_t) (struct mpdclient *c, gint error, const gchar *msg);
95 void mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
96 void mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
98 /*** playlist functions  **************************************************/
100 /* update the complete playlist */
101 gint mpdclient_playlist_update(struct mpdclient *c);
103 /* get playlist changes */
104 gint mpdclient_playlist_update_changes(struct mpdclient *c);
107 /*** mpdclient playlist callbacks *****************************************/
109 #define PLAYLIST_EVENT_UPDATED     0x01
110 #define PLAYLIST_EVENT_CLEAR       0x02
111 #define PLAYLIST_EVENT_DELETE      0x03
112 #define PLAYLIST_EVENT_ADD         0x04
113 #define PLAYLIST_EVENT_MOVE        0x05
116 typedef void (*mpdc_list_cb_t) (struct mpdclient *c, int event, gpointer data);
118 /* install a playlist callback function */
119 void mpdclient_install_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
121 /* remove a playlist callback function */
122 void mpdclient_remove_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
125 /* issue a playlist callback */
126 void mpdclient_playlist_callback(struct mpdclient *c, int event, gpointer data);
129 /*** filelist functions  ***************************************************/
131 struct filelist *
132 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
134 struct filelist *
135 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
136                           enum mpd_tag_type tag,
137                           gchar *filter_utf8);
139 /* add all songs in filelist to the playlist */
140 int
141 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
143 /*** mpdclient browse callbacks ********************************************/
145 #define BROWSE_DB_UPDATED          0x01
146 #define BROWSE_PLAYLIST_SAVED      0x02
147 #define BROWSE_PLAYLIST_DELETED    0x03
150 /* install a playlist callback function */
151 void mpdclient_install_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
153 /* remove a playlist callback function */
154 void mpdclient_remove_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
157 /* issue a playlist callback */
158 void mpdclient_browse_callback(struct mpdclient *c, int event, gpointer data);
160 /* sort by list-format */
161 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
163 #endif