Code

mpdclient: added mpdclient_is_connected()
[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         gboolean       need_update;
25         int volume;
26         unsigned updatingdb;
27 };
29 /** functions ***************************************************************/
31 gint
32 mpdclient_finish_command(struct mpdclient *c);
34 struct mpdclient *
35 mpdclient_new(void);
37 void mpdclient_free(struct mpdclient *c);
39 static inline bool
40 mpdclient_is_connected(const struct mpdclient *c)
41 {
42         return c->connection != NULL;
43 }
45 gint mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
46                        gfloat timeout_, const gchar *password);
47 gint mpdclient_disconnect(struct mpdclient *c);
48 gint mpdclient_update(struct mpdclient *c);
51 /*** MPD Commands  **********************************************************/
52 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
53 gint mpdclient_cmd_pause(struct mpdclient *c, gint value);
54 gint
55 mpdclient_cmd_crop(struct mpdclient *c);
56 gint mpdclient_cmd_stop(struct mpdclient *c);
57 gint mpdclient_cmd_next(struct mpdclient *c);
58 gint mpdclient_cmd_prev(struct mpdclient *c);
59 gint mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos);
60 gint mpdclient_cmd_shuffle(struct mpdclient *c);
61 gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
62 gint mpdclient_cmd_clear(struct mpdclient *c);
63 gint mpdclient_cmd_repeat(struct mpdclient *c, gint value);
64 gint mpdclient_cmd_random(struct mpdclient *c, gint value);
65 gint mpdclient_cmd_single(struct mpdclient *c, gint value);
66 gint mpdclient_cmd_consume(struct mpdclient *c, gint value);
67 gint mpdclient_cmd_crossfade(struct mpdclient *c, gint value);
68 gint mpdclient_cmd_db_update(struct mpdclient *c, const gchar *path);
69 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
70 gint mpdclient_cmd_volume_up(struct mpdclient *c);
71 gint mpdclient_cmd_volume_down(struct mpdclient *c);
72 gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
74 gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
75 gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
76 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
78 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
79 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
80 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
82 /* list functions */
83 GList *mpdclient_get_artists(struct mpdclient *c);
84 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
87 /*** error callbacks *****************************************************/
89 #define IS_ACK_ERROR(n)       (n & MPD_ERROR_ACK)
90 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
92 typedef void (*mpdc_error_cb_t) (struct mpdclient *c, gint error, const gchar *msg);
94 void mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
95 void mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
97 /*** playlist functions  **************************************************/
99 /* update the complete playlist */
100 gint mpdclient_playlist_update(struct mpdclient *c);
102 /* get playlist changes */
103 gint mpdclient_playlist_update_changes(struct mpdclient *c);
106 /*** mpdclient playlist callbacks *****************************************/
108 #define PLAYLIST_EVENT_UPDATED     0x01
109 #define PLAYLIST_EVENT_CLEAR       0x02
110 #define PLAYLIST_EVENT_DELETE      0x03
111 #define PLAYLIST_EVENT_ADD         0x04
112 #define PLAYLIST_EVENT_MOVE        0x05
115 typedef void (*mpdc_list_cb_t) (struct mpdclient *c, int event, gpointer data);
117 /* install a playlist callback function */
118 void mpdclient_install_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
120 /* remove a playlist callback function */
121 void mpdclient_remove_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
124 /* issue a playlist callback */
125 void mpdclient_playlist_callback(struct mpdclient *c, int event, gpointer data);
128 /*** filelist functions  ***************************************************/
130 struct filelist *
131 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
133 struct filelist *
134 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
135                           enum mpd_tag_type tag,
136                           gchar *filter_utf8);
138 /* add all songs in filelist to the playlist */
139 int
140 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
142 /*** mpdclient browse callbacks ********************************************/
144 #define BROWSE_DB_UPDATED          0x01
145 #define BROWSE_PLAYLIST_SAVED      0x02
146 #define BROWSE_PLAYLIST_DELETED    0x03
149 /* install a playlist callback function */
150 void mpdclient_install_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
152 /* remove a playlist callback function */
153 void mpdclient_remove_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
156 /* issue a playlist callback */
157 void mpdclient_browse_callback(struct mpdclient *c, int event, gpointer data);
159 /* sort by list-format */
160 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
162 #endif