From cdcb2028d9a86e31ff2ed968f08d39fee4712477 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Sun, 1 Sep 2024 16:21:01 +0200 Subject: [PATCH] Print positions in the list playlists function. For simple listing this can be done by the client, but for the search case the client can not determine the correct position. I hope this does not break existing client implementations. --- src/playlist/Print.cxx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/playlist/Print.cxx b/src/playlist/Print.cxx index 10fecfa9df..c2efd1b453 100644 --- a/src/playlist/Print.cxx +++ b/src/playlist/Print.cxx @@ -17,6 +17,8 @@ #include "Partition.hxx" #include "Instance.hxx" #include "PlaylistError.hxx" +#include +#include "client/Response.hxx" static void playlist_provider_print(Response &r, @@ -43,12 +45,16 @@ playlist_provider_print(Response &r, if (playlist_check_translate_song(*song, base_uri, loader) && - detail) + detail) { song_print_info(r, *song); - else + r.Fmt(FMT_STRING("Pos: {}\n"), i); + } + else { /* fallback if no detail was requested or no detail was available */ song_print_uri(r, *song); + r.Fmt(FMT_STRING("Pos: {}\n"), i); + } } } @@ -69,27 +75,35 @@ playlist_provider_search_print(Response &r, unsigned skip = start_index; unsigned n = end_index - start_index; + unsigned position = 0; while ((song = e.NextSong()) != nullptr) { const bool detail = playlist_check_translate_song(*song, base_uri, loader); - if (!filter->Match(static_cast(*song))) + if (!filter->Match(static_cast(*song))) { + ++position; continue; + } if (skip > 0) { --skip; + ++position; continue; } - if (detail) + if (detail) { song_print_info(r, *song); - else + r.Fmt(FMT_STRING("Pos: {}\n"), position); + } else { /* fallback if no detail was requested or no detail was available */ song_print_uri(r, *song); + } if (--n == 0) break; + + ++position; } }