diff options
author | Yannick LM <yannicklm1337@gmail.com> | 2008-09-21 13:50:26 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-21 13:50:26 +0200 |
commit | 7f0340e99ab01219199af30b7393ca0d61ad1213 (patch) | |
tree | 59d4ab43fd378496bf75f5b5195a7662104de4e9 /src/mpdclient.c | |
parent | 36acd5f8c2988c2b73fee670b2d37cb38f5c518b (diff) | |
download | mpd-7f0340e99ab01219199af30b7393ca0d61ad1213.tar.gz mpd-7f0340e99ab01219199af30b7393ca0d61ad1213.tar.xz mpd-7f0340e99ab01219199af30b7393ca0d61ad1213.zip |
Adding crop feature in ncmpc
The "crop" command deletes all songs from the playlist, except the one
currently being played.
Diffstat (limited to 'src/mpdclient.c')
-rw-r--r-- | src/mpdclient.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mpdclient.c b/src/mpdclient.c index 2c46d8e90..6d9d72b9c 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -300,6 +300,41 @@ mpdclient_cmd_pause(mpdclient_t *c, gint value) } gint +mpdclient_cmd_crop(mpdclient_t *c) +{ + mpd_Status *status; + int length; + + mpd_sendStatusCommand(c->connection); + status = mpd_getStatus(c->connection); + length = status->playlistLength - 1; + + if (length <= 0) { + mpd_freeStatus(status); + screen_status_message("You have to have a playlist longer than 1 song in length to crop"); + } else if (status->state == 3 || status->state == 2) { + /* If playing or paused */ + + mpd_sendCommandListBegin( c->connection ); + + while (length >= 0) { + if (length != status->song) + mpd_sendDeleteCommand(c->connection, length); + + length--; + } + + mpd_sendCommandListEnd(c->connection); + mpd_freeStatus(status); + } else { + mpd_freeStatus(status); + screen_status_message("You need to be playing to crop the playlist\n"); + } + + return mpdclient_finish_command(c); +} + +gint mpdclient_cmd_stop(mpdclient_t *c) { mpd_sendStopCommand(c->connection); |