aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c39
-rw-r--r--src/mpdclient.c21
-rw-r--r--src/mpdclient.h4
3 files changed, 43 insertions, 21 deletions
diff --git a/src/main.c b/src/main.c
index 8d3a82fd2..e996233a0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
+#include <string.h>
#include <glib.h>
#include "config.h"
@@ -37,22 +38,41 @@ static mpdclient_t *mpd = NULL;
static gboolean connected = FALSE;
static GTimer *timer = NULL;
+static gchar *
+error_msg(gchar *msg)
+{
+ gchar *p;
+
+ if( (p=strchr(msg, '}' )) == NULL )
+ return msg;
+ while( p && *p && (*p=='}' || *p==' ') )
+ p++;
+
+ return p;
+}
+
static void
-error_callback(mpdclient_t *c, int error, char *msg)
+error_callback(mpdclient_t *c, gint error, gchar *msg)
{
- D("error_callback> error=%d errorCode=%d errorAt=%d\n",
- error, c->connection->errorCode, c->connection->errorAt);
- D("error_callback> \"%s\"\n", msg);
+ gint code = GET_ACK_ERROR_CODE(error);
+
+ error = error & 0xFF;
+ D("Error [%d:%d]> \"%s\"\n", error, c->connection->errorCode, msg);
switch(error)
{
+ case MPD_ERROR_CONNPORT:
+ case MPD_ERROR_NORESPONSE:
+ break;
case MPD_ERROR_ACK:
- screen_status_printf("%s", msg);
+ screen_status_printf("%s", error_msg(msg));
+ beep();
break;
default:
- screen_status_printf(_("Lost connection to %s"), options.host);
+ screen_status_printf("%s", msg);
+ doupdate();
+ beep();
connected = FALSE;
}
- doupdate();
}
void
@@ -203,7 +223,6 @@ main(int argc, const char *argv[])
{
screen_status_printf(_("Connecting to %s... [Press %s to abort]"),
options->host, get_key_names(CMD_QUIT,0) );
- doupdate();
if( get_keyboard_command_with_timeout(MPD_RECONNECT_TIME)==CMD_QUIT)
exit(EXIT_SUCCESS);
@@ -211,13 +230,13 @@ main(int argc, const char *argv[])
if( mpdclient_connect(mpd,
options->host,
options->port,
- 1.0,
+ 1.5,
options->password) == 0 )
{
screen_status_printf(_("Connected to %s!"), options->host);
- doupdate();
connected = TRUE;
}
+ doupdate();
}
t = g_timer_elapsed(timer, NULL);
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 89ed29e2a..5256413d5 100644
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
@@ -46,7 +46,7 @@ error_cb(mpdclient_t *c, gint error, gchar *msg)
GList *list = c->error_callbacks;
if( list==NULL )
- fprintf(stderr, "error [%d]: %s\n", error, msg);
+ fprintf(stderr, "error [%d]: %s\n", (error & 0xFF), msg);
while(list)
{
@@ -85,11 +85,14 @@ mpdclient_finish_command(mpdclient_t *c)
if( c->connection->error )
{
gchar *msg = locale_to_utf8(c->connection->errorStr);
- gint retval = c->connection->error;
+ gint error = c->connection->error;
+
+ if( error == MPD_ERROR_ACK )
+ error = error | (c->connection->errorCode << 8);
- error_cb(c, c->connection->error, msg);
+ error_cb(c, error, msg);
g_free(msg);
- return retval;
+ return error;
}
return 0;
@@ -120,7 +123,6 @@ mpdclient_free(mpdclient_t *c)
gint
mpdclient_disconnect(mpdclient_t *c)
{
- D("mpdclient_disconnect()...\n");
if( c->connection )
mpd_closeConnection(c->connection);
c->connection = NULL;
@@ -152,7 +154,6 @@ mpdclient_connect(mpdclient_t *c,
mpdclient_disconnect(c);
/* connect to MPD */
- D("mpdclient_connect(%s, %d)...\n", host, port);
c->connection = mpd_newConnection(host, port, timeout);
if( c->connection->error )
return error_cb(c, c->connection->error, c->connection->errorStr);
@@ -163,6 +164,7 @@ mpdclient_connect(mpdclient_t *c,
mpd_sendPasswordCommand(c->connection, password);
retval = mpdclient_finish_command(c);
}
+ c->need_update = TRUE;
return retval;
}
@@ -568,8 +570,7 @@ mpdclient_playlist_free(mpdclient_playlist_t *playlist)
list=list->next;
}
g_list_free(playlist->list);
- playlist->list = NULL;
- playlist->length = 0;
+ memset(playlist, 0, sizeof(mpdclient_playlist_t));
return 0;
}
@@ -587,9 +588,6 @@ mpdclient_playlist_update(mpdclient_t *c)
if( c->playlist.list )
mpdclient_playlist_free(&c->playlist);
- c->song = NULL;
- c->playlist.updated = TRUE;
-
mpd_sendPlaylistInfoCommand(c->connection,-1);
while( (entity=mpd_getNextInfoEntity(c->connection)) )
{
@@ -604,6 +602,7 @@ mpdclient_playlist_update(mpdclient_t *c)
}
c->playlist.id = c->status->playlist;
c->song = NULL;
+ c->playlist.updated = TRUE;
/* call playlist updated callbacks */
mpdclient_playlist_callback(c, PLAYLIST_EVENT_UPDATED, NULL);
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 86f1b0ce8..391a5d224 100644
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
@@ -91,6 +91,10 @@ gint mpdclient_cmd_delete_playlist(mpdclient_t *c, gchar *filename_utf8);
/*** error callbacks *****************************************************/
+
+#define IS_ACK_ERROR(n) (n & MPD_ERROR_ACK)
+#define GET_ACK_ERROR_CODE(n) ((n & 0xFF00) >> 8)
+
typedef void (*mpdc_error_cb_t) (mpdclient_t *c, gint error, gchar *msg);
void mpdclient_install_error_callback(mpdclient_t *c, mpdc_error_cb_t cb);