aboutsummaryrefslogtreecommitdiffstats
path: root/src/mpc.c
diff options
context:
space:
mode:
authorKalle Wallin <kaw@linux.se>2004-06-08 13:15:03 +0000
committerKalle Wallin <kaw@linux.se>2004-06-08 13:15:03 +0000
commitfadbcce56a23b440a7d7782b235ccc38c20be84e (patch)
treeea8ca8a99edd77eff774d4c75ac9d6f429ddd159 /src/mpc.c
parentd98fbf6d5f1a60d3a6ae561dbc6df955876e10fc (diff)
downloadmpd-fadbcce56a23b440a7d7782b235ccc38c20be84e.tar.gz
mpd-fadbcce56a23b440a7d7782b235ccc38c20be84e.tar.xz
mpd-fadbcce56a23b440a7d7782b235ccc38c20be84e.zip
Check playlist length and remove songs (plchanges command)
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1393 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/mpc.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/mpc.c b/src/mpc.c
index ab25f1964..08ca970f6 100644
--- a/src/mpc.c
+++ b/src/mpc.c
@@ -103,8 +103,9 @@ mpc_error(mpd_client_t *c)
{
if( c == NULL || c->connection == NULL )
return 1;
+
if( c->connection->error )
- return c->connection->error;
+ return c->connection->error;
return 0;
}
@@ -194,7 +195,8 @@ mpc_update_playlist(mpd_client_t *c)
{
mpd_InfoEntity *entity;
- D(fprintf(stderr, "mpc_update_playlist() [%lld]\n", c->status->playlist));
+ D(fprintf(stderr, "mpc_update_playlist() [%lld -> %lld]\n",
+ c->status->playlist, c->playlist_id));
if( mpc_error(c) )
return -1;
@@ -202,9 +204,8 @@ mpc_update_playlist(mpd_client_t *c)
mpd_sendPlChangesCommand(c->connection, c->playlist_id);
if( mpc_error(c) )
return -1;
- if( (entity=mpd_getNextInfoEntity(c->connection)) == NULL )
- return mpc_get_playlist(c);
- while( entity )
+
+ while( (entity=mpd_getNextInfoEntity(c->connection)) != NULL )
{
if(entity->type==MPD_INFO_ENTITY_TYPE_SONG)
{
@@ -212,11 +213,15 @@ mpc_update_playlist(mpd_client_t *c)
GList *item;
if( (song=mpd_songDup(entity->info.song)) == NULL )
- return mpc_get_playlist(c);
+ {
+ D(fprintf(stderr, "song==NULL\n"));
+ return mpc_get_playlist(c);
+ }
item = g_list_nth(c->playlist, song->num);
if( item && item->data)
{
+ /* Update playlist entry */
mpd_freeSong((mpd_Song *) item->data);
item->data = song;
if( c->song_id == song->num )
@@ -226,6 +231,7 @@ mpc_update_playlist(mpd_client_t *c)
}
else
{
+ /* Add a new playlist entry */
D(fprintf(stderr, "Adding num %d - %s\n",
song->num, mpc_get_song_name(song)));
c->playlist = g_list_append(c->playlist,
@@ -233,10 +239,20 @@ mpc_update_playlist(mpd_client_t *c)
c->playlist_length++;
}
}
- mpd_freeInfoEntity(entity);
- entity=mpd_getNextInfoEntity(c->connection);
+ mpd_freeInfoEntity(entity);
}
mpd_finishCommand(c->connection);
+
+ while( g_list_length(c->playlist) > c->status->playlistLength )
+ {
+ GList *item = g_list_last(c->playlist);
+
+ /* Remove the last playlist entry */
+ mpd_freeSong((mpd_Song *) item->data);
+ c->playlist = g_list_delete_link(c->playlist, item);
+ c->playlist_length--;
+ D(fprintf(stderr, "Removed the last playlist entryn\n"));
+ }
c->playlist_id = c->status->playlist;
c->playlist_updated = 1;
@@ -476,9 +492,8 @@ mpc_update_filelist(mpd_client_t *c)
c->filelist_length=0;
- // mpd_sendListallCommand(conn,"");
mpd_sendLsInfoCommand(c->connection, c->cwd);
-
+
if( c->cwd && c->cwd[0] )
{
/* add a dummy entry for ./.. */