aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-09-30 23:13:13 +0200
committerMax Kellermann <max@duempel.org>2009-09-30 23:13:13 +0200
commit31cabc751d2dc6721706d878a0694afc83ef6a0c (patch)
tree68a4f6b3d36d1ee3530d8ee9983f10f862ce624e /src
parent0478a8e2880a26f9993c5adeb10f29acc11deb72 (diff)
downloadmpd-31cabc751d2dc6721706d878a0694afc83ef6a0c.tar.gz
mpd-31cabc751d2dc6721706d878a0694afc83ef6a0c.tar.xz
mpd-31cabc751d2dc6721706d878a0694afc83ef6a0c.zip
command: range support for "delete"
Diffstat (limited to 'src')
-rw-r--r--src/command.c6
-rw-r--r--src/playlist.h9
-rw-r--r--src/playlist_edit.c26
3 files changed, 38 insertions, 3 deletions
diff --git a/src/command.c b/src/command.c
index f69bdf632..165e21c96 100644
--- a/src/command.c
+++ b/src/command.c
@@ -632,13 +632,13 @@ handle_addid(struct client *client, int argc, char *argv[])
static enum command_return
handle_delete(struct client *client, G_GNUC_UNUSED int argc, char *argv[])
{
- int song;
+ unsigned start, end;
enum playlist_result result;
- if (!check_int(client, &song, argv[1], need_positive))
+ if (!check_range(client, &start, &end, argv[1], need_range))
return COMMAND_RETURN_ERROR;
- result = playlist_delete(&g_playlist, song);
+ result = playlist_delete_range(&g_playlist, start, end);
return print_playlist_result(client, result);
}
diff --git a/src/playlist.h b/src/playlist.h
index 4126c67c3..311163e8b 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -141,6 +141,15 @@ playlist_append_song(struct playlist *playlist,
enum playlist_result
playlist_delete(struct playlist *playlist, unsigned song);
+/**
+ * Deletes a range of songs from the playlist.
+ *
+ * @param start the position of the first song to delete
+ * @param end the position after the last song to delete
+ */
+enum playlist_result
+playlist_delete_range(struct playlist *playlist, unsigned start, unsigned end);
+
enum playlist_result
playlist_delete_id(struct playlist *playlist, unsigned song);
diff --git a/src/playlist_edit.c b/src/playlist_edit.c
index 6b15f56cb..473305f17 100644
--- a/src/playlist_edit.c
+++ b/src/playlist_edit.c
@@ -280,6 +280,32 @@ playlist_delete(struct playlist *playlist, unsigned song)
}
enum playlist_result
+playlist_delete_range(struct playlist *playlist, unsigned start, unsigned end)
+{
+ const struct song *queued;
+
+ if (start >= queue_length(&playlist->queue))
+ return PLAYLIST_RESULT_BAD_RANGE;
+
+ if (end > queue_length(&playlist->queue))
+ end = queue_length(&playlist->queue);
+
+ if (start >= end)
+ return PLAYLIST_RESULT_SUCCESS;
+
+ queued = playlist_get_queued_song(playlist);
+
+ do {
+ playlist_delete_internal(playlist, --end, &queued);
+ } while (end != start);
+
+ playlist_increment_version(playlist);
+ playlist_update_queued_song(playlist, queued);
+
+ return PLAYLIST_RESULT_SUCCESS;
+}
+
+enum playlist_result
playlist_delete_id(struct playlist *playlist, unsigned id)
{
int song = queue_id_to_position(&playlist->queue, id);