index 0b12e27e14ed8b64e0a94234e620c3b92725f2da..0a80af4dd1280f7c9b867153e8784ed93df16c06 100644 (file)
--- a/mpc.c
+++ b/mpc.c
-/*
- * $Id: mpc.c,v 1.5 2004/03/17 23:19:21 kalle Exp $
- *
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MAX_SONG_LENGTH 1024
-void
-mpc_update_song(mpd_client_t *c)
-{
- mpd_InfoEntity *entity;
-
- if( mpc_error(c) )
- return;
-
- if( c->song )
- {
- mpd_freeSong(c->song);
- c->song = NULL;
- }
-
- mpd_sendPlaylistInfoCommand(c->connection, c->status->song);
- if( mpc_error(c) )
- return;
- while( (entity=mpd_getNextInfoEntity(c->connection)) )
- {
- mpd_Song *song = entity->info.song;
-
- if(c->connection->error)
- {
- fprintf(stderr,"error: %s\n",c->connection->errorStr);
- exit(EXIT_FAILURE);
- }
- if(entity->type!=MPD_INFO_ENTITY_TYPE_SONG) {
- mpd_freeInfoEntity(entity);
- fprintf(stderr,
- "error: type != MPD_INFO_ENTITY_TYPE_SONG [%d]\n",
- entity->type);
- exit(EXIT_FAILURE);
- }
- c->song = mpd_songDup(song);
- mpd_freeInfoEntity(entity);
- }
-}
+#ifdef DEBUG
+#define D(x) x
+#else
+#define D(x)
+#endif
int
mpc_close(mpd_client_t *c)
if( c->connection )
mpd_closeConnection(c->connection);
if( c->cwd )
- free( c->cwd );
+ g_free( c->cwd );
return 0;
}
mpd_client_t *
-mpc_connect(char *host, int port)
+mpc_connect(char *host, int port, char *password)
{
mpd_Connection *connection;
mpd_client_t *c;
exit(EXIT_FAILURE);
}
- c = malloc(sizeof(mpd_client_t));
+ c = g_malloc(sizeof(mpd_client_t));
memset(c, 0, sizeof(mpd_client_t));
c->connection = connection;
- c->cwd = strdup("");
+ c->cwd = g_strdup("");
+
+ if( password )
+ {
+ mpd_sendPasswordCommand(connection, password);
+ mpd_finishCommand(connection);
+ }
return c;
}
int
-mpc_reconnect(mpd_client_t *c, char *host, int port)
+mpc_reconnect(mpd_client_t *c, char *host, int port, char *password)
{
mpd_Connection *connection;
c->connection = connection;
+ if( password )
+ {
+ mpd_sendPasswordCommand(connection, password);
+ mpd_finishCommand(connection);
+ }
+
return 0;
}
if( c == NULL || c->connection == NULL )
return 1;
if( c->connection->error )
- return 1;
+ return c->connection->error;
return 0;
}
c->playlist=NULL;
c->playlist_length=0;
+ c->song_id = -1;
+ c->song = NULL;
+
return 0;
}
{
mpd_InfoEntity *entity;
- // fprintf(stderr, "mpc_update_playlist(): status->playlist = %d\n", c->status->playlist);
+ D(fprintf(stderr, "mpc_update_playlist() [%d]\n", c->status->playlist));
if( mpc_error(c) )
return -1;
c->playlist_id = c->status->playlist;
c->playlist_updated = 1;
c->song_id = -1;
+ c->song = NULL;
+
+ mpc_filelist_set_selected(c);
return 0;
}
return (mpd_Song *) g_list_nth_data(c->playlist, n);
}
+
char *
mpc_get_song_name(mpd_Song *song)
{
snprintf(buf, MAX_SONG_LENGTH, "%s - %s", song->artist, song->title);
name = utf8_to_locale(buf);
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
else
{
name = utf8_to_locale(song->title);
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
}
- name = utf8_to_locale(song->file);
+ name = utf8_to_locale(basename(song->file));
strncpy(buf, name, MAX_SONG_LENGTH);
- free(name);
+ g_free(name);
return buf;
}
if( c->playlist_id!=c->status->playlist )
mpc_update_playlist(c);
- if( c->status->song != c->song_id )
+ if( !c->song || c->status->song != c->song_id )
{
c->song = mpc_playlist_get_song(c, c->status->song);
c->song_id = c->status->song;
if( entry->entity )
mpd_freeInfoEntity(entry->entity);
- free(entry);
+ g_free(entry);
list=list->next;
}
g_list_free(c->filelist);
if( c->cwd && c->cwd[0] )
{
/* add a dummy entry for ./.. */
- filelist_entry_t *entry = malloc(sizeof(filelist_entry_t));
+ filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t));
memset(entry, 0, sizeof(filelist_entry_t));
entry->entity = NULL;
c->filelist = g_list_append(c->filelist, (gpointer) entry);
while( (entity=mpd_getNextInfoEntity(c->connection)) )
{
- filelist_entry_t *entry = malloc(sizeof(filelist_entry_t));
+ filelist_entry_t *entry = g_malloc(sizeof(filelist_entry_t));
memset(entry, 0, sizeof(filelist_entry_t));
entry->entity = entity;