Code

screen_search: clear return value on 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         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);
38 gint mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
39                        gfloat timeout_, const gchar *password);
40 gint mpdclient_disconnect(struct mpdclient *c);
41 gint mpdclient_update(struct mpdclient *c);
44 /*** MPD Commands  **********************************************************/
45 gint mpdclient_cmd_play(struct mpdclient *c, gint index);
46 gint mpdclient_cmd_pause(struct mpdclient *c, gint value);
47 gint
48 mpdclient_cmd_crop(struct mpdclient *c);
49 gint mpdclient_cmd_stop(struct mpdclient *c);
50 gint mpdclient_cmd_next(struct mpdclient *c);
51 gint mpdclient_cmd_prev(struct mpdclient *c);
52 gint mpdclient_cmd_seek(struct mpdclient *c, gint id, gint pos);
53 gint mpdclient_cmd_shuffle(struct mpdclient *c);
54 gint mpdclient_cmd_shuffle_range(struct mpdclient *c, guint start, guint end);
55 gint mpdclient_cmd_clear(struct mpdclient *c);
56 gint mpdclient_cmd_repeat(struct mpdclient *c, gint value);
57 gint mpdclient_cmd_random(struct mpdclient *c, gint value);
58 gint mpdclient_cmd_single(struct mpdclient *c, gint value);
59 gint mpdclient_cmd_consume(struct mpdclient *c, gint value);
60 gint mpdclient_cmd_crossfade(struct mpdclient *c, gint value);
61 gint mpdclient_cmd_db_update(struct mpdclient *c, const gchar *path);
62 gint mpdclient_cmd_volume(struct mpdclient *c, gint value);
63 gint mpdclient_cmd_volume_up(struct mpdclient *c);
64 gint mpdclient_cmd_volume_down(struct mpdclient *c);
65 gint mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
67 gint mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
68 gint mpdclient_cmd_delete(struct mpdclient *c, gint index);
69 gint mpdclient_cmd_move(struct mpdclient *c, gint old_index, gint new_index);
71 gint mpdclient_cmd_save_playlist(struct mpdclient *c, const gchar *filename);
72 gint mpdclient_cmd_load_playlist(struct mpdclient *c, const gchar *filename_utf8);
73 gint mpdclient_cmd_delete_playlist(struct mpdclient *c, const gchar *filename_utf8);
75 /* list functions */
76 GList *mpdclient_get_artists(struct mpdclient *c);
77 GList *mpdclient_get_albums(struct mpdclient *c, const gchar *artist_utf8);
80 /*** error callbacks *****************************************************/
82 #define IS_ACK_ERROR(n)       (n & MPD_ERROR_ACK)
83 #define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
85 typedef void (*mpdc_error_cb_t) (struct mpdclient *c, gint error, const gchar *msg);
87 void mpdclient_install_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
88 void mpdclient_remove_error_callback(struct mpdclient *c, mpdc_error_cb_t cb);
90 /*** playlist functions  **************************************************/
92 /* update the complete playlist */
93 gint mpdclient_playlist_update(struct mpdclient *c);
95 /* get playlist changes */
96 gint mpdclient_playlist_update_changes(struct mpdclient *c);
99 /*** mpdclient playlist callbacks *****************************************/
101 #define PLAYLIST_EVENT_UPDATED     0x01
102 #define PLAYLIST_EVENT_CLEAR       0x02
103 #define PLAYLIST_EVENT_DELETE      0x03
104 #define PLAYLIST_EVENT_ADD         0x04
105 #define PLAYLIST_EVENT_MOVE        0x05
108 typedef void (*mpdc_list_cb_t) (struct mpdclient *c, int event, gpointer data);
110 /* install a playlist callback function */
111 void mpdclient_install_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
113 /* remove a playlist callback function */
114 void mpdclient_remove_playlist_callback(struct mpdclient *c, mpdc_list_cb_t cb);
117 /* issue a playlist callback */
118 void mpdclient_playlist_callback(struct mpdclient *c, int event, gpointer data);
121 /*** filelist functions  ***************************************************/
123 struct filelist *
124 mpdclient_filelist_get(struct mpdclient *c, const gchar *path);
126 struct filelist *
127 mpdclient_filelist_search(struct mpdclient *c, int exact_match,
128                           enum mpd_tag_type tag,
129                           gchar *filter_utf8);
131 /* add all songs in filelist to the playlist */
132 int
133 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
135 /*** mpdclient browse callbacks ********************************************/
137 #define BROWSE_DB_UPDATED          0x01
138 #define BROWSE_PLAYLIST_SAVED      0x02
139 #define BROWSE_PLAYLIST_DELETED    0x03
142 /* install a playlist callback function */
143 void mpdclient_install_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
145 /* remove a playlist callback function */
146 void mpdclient_remove_browse_callback(struct mpdclient *c, mpdc_list_cb_t cb);
149 /* issue a playlist callback */
150 void mpdclient_browse_callback(struct mpdclient *c, int event, gpointer data);
152 /* sort by list-format */
153 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
155 #endif