X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fmpdclient.c;h=ce1eed5972de92bda9ef4db76a0aa7682d60dc92;hb=44c4e177bf52c70f307d6d528fb62b5c9176a3aa;hp=ca7a7b61ba2352d53b47b889d0f14914b38c000e;hpb=1edc4f1f1cf5928a20dbd474040107324653a69e;p=ncmpc.git diff --git a/src/mpdclient.c b/src/mpdclient.c index ca7a7b6..ce1eed5 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -1,5 +1,5 @@ /* ncmpc (Ncurses MPD Client) - * (c) 2004-2009 The Music Player Daemon Project + * (c) 2004-2010 The Music Player Daemon Project * Project homepage: http://musicpd.org * This program is free software; you can redistribute it and/or modify @@ -83,13 +83,6 @@ mpdclient_handle_error(struct mpdclient *c) return false; } -static bool -mpdclient_finish_command(struct mpdclient *c) -{ - return mpd_response_finish(c->connection) - ? true : mpdclient_handle_error(c); -} - struct mpdclient * mpdclient_new(void) { @@ -136,24 +129,22 @@ mpdclient_disconnect(struct mpdclient *c) c->song = NULL; /* everything has changed after a disconnect */ - c->events |= MPD_IDLE_DATABASE|MPD_IDLE_STORED_PLAYLIST| - MPD_IDLE_QUEUE|MPD_IDLE_PLAYER|MPD_IDLE_MIXER|MPD_IDLE_OUTPUT| - MPD_IDLE_OPTIONS|MPD_IDLE_UPDATE; + c->events |= MPD_IDLE_ALL; } bool mpdclient_connect(struct mpdclient *c, const gchar *host, gint port, - gfloat _timeout, + unsigned timeout_ms, const gchar *password) { /* close any open connection */ - if( c->connection ) + if (c->connection) mpdclient_disconnect(c); /* connect to MPD */ - c->connection = mpd_connection_new(host, port, _timeout * 1000); + c->connection = mpd_connection_new(host, port, timeout_ms); if (c->connection == NULL) g_error("Out of memory"); @@ -229,7 +220,7 @@ mpdclient_update(struct mpdclient *c) } /* update the current song */ - if (!c->song || mpd_status_get_song_id(c->status)) { + if (!c->song || mpd_status_get_song_id(c->status) >= 0) { c->song = playlist_get_song(&c->playlist, mpd_status_get_song_pos(c->status)); } @@ -348,6 +339,7 @@ mpdclient_cmd_clear(struct mpdclient *c) reducing the UI latency */ playlist_clear(&c->playlist); c->playlist.version = mpd_status_get_queue_version(status); + c->song = NULL; } c->events |= MPD_IDLE_QUEUE; @@ -411,8 +403,8 @@ mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path_utf8) if (connection == NULL) return false; - mpd_send_add(connection, path_utf8); - return mpdclient_finish_command(c); + return mpd_send_add(connection, path_utf8)? + mpdclient_finish_command(c) : false; } bool