command/queue: add position parameter to "load"

Another one from https://github.com/MusicPlayerDaemon/MPD/issues/888
This commit is contained in:
Max Kellermann
2021-10-14 15:11:04 +02:00
parent 2e5ca1cbd2
commit 608896571c
4 changed files with 24 additions and 3 deletions

View File

@@ -79,11 +79,16 @@ handle_load(Client &client, Request args, [[maybe_unused]] Response &r)
);
RangeArg range = args.ParseOptional(1, RangeArg::All());
const ScopeBulkEdit bulk_edit(client.GetPartition());
auto &partition = client.GetPartition();
const ScopeBulkEdit bulk_edit(partition);
auto &playlist = client.GetPlaylist();
const unsigned old_size = playlist.GetLength();
const unsigned position = args.size > 2
? args.ParseUnsigned(2, old_size)
: old_size;
const SongLoader loader(client);
playlist_open_into_queue(uri,
range.start, range.end,
@@ -96,6 +101,16 @@ handle_load(Client &client, Request args, [[maybe_unused]] Response &r)
for (unsigned i = old_size; i < new_size; ++i)
instance.LookupRemoteTag(playlist.queue.Get(i).GetRealURI());
if (position < old_size) {
const RangeArg move_range{old_size, new_size};
try {
partition.MoveRange(move_range, position);
} catch (...) {
/* ignore - shall we handle it? */
}
}
return CommandResult::OK;
}