summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: abd01cf)
raw | patch | inline | side by side (parent: abd01cf)
author | Kalle Wallin <kaw@linux.se> | |
Mon, 14 Jun 2004 23:05:24 +0000 (23:05 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Mon, 14 Jun 2004 23:05:24 +0000 (23:05 +0000) |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 8d3a82fd2f90e2f2703d0b3395469a18e2b5bc64..e996233a0f2e35d5366337ab11b5342948e3e6a4 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
+#include <string.h>
#include <glib.h>
#include "config.h"
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
{
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);
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 89ed29e2a39c787199ec9e0b61a3de7392fd5a50..5256413d5de6745683e92e10afceaf5b4b9ac064 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
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)
{
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;
gint
mpdclient_disconnect(mpdclient_t *c)
{
- D("mpdclient_disconnect()...\n");
if( c->connection )
mpd_closeConnection(c->connection);
c->connection = NULL;
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);
mpd_sendPasswordCommand(c->connection, password);
retval = mpdclient_finish_command(c);
}
+ c->need_update = TRUE;
return retval;
}
list=list->next;
}
g_list_free(playlist->list);
- playlist->list = NULL;
- playlist->length = 0;
+ memset(playlist, 0, sizeof(mpdclient_playlist_t));
return 0;
}
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)) )
{
}
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 86f1b0ce810c14f09de6060c6a32420c2c962c03..391a5d224576aa7b9f71975ba18f7fd7a2d99883 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
/*** 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);