SongPrint: remove Storage::MapToRelativeUTF8() call

This code (added 7 years ago with commit b233c145f) has been obsoleted
by the SongLoader class (added 3 years ago).
This commit is contained in:
Max Kellermann 2017-02-24 13:56:13 +01:00
parent cd522f524d
commit 71ce1a25dd
12 changed files with 71 additions and 107 deletions

View File

@ -33,17 +33,15 @@
#define SONG_TIME "Time: "
void
playlist_print_uris(Response &r, Partition &partition,
const playlist &playlist)
playlist_print_uris(Response &r, const playlist &playlist)
{
const Queue &queue = playlist.queue;
queue_print_uris(r, partition, queue, 0, queue.GetLength());
queue_print_uris(r, queue, 0, queue.GetLength());
}
void
playlist_print_info(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_info(Response &r, const playlist &playlist,
unsigned start, unsigned end)
{
const Queue &queue = playlist.queue;
@ -56,11 +54,11 @@ playlist_print_info(Response &r, Partition &partition,
/* an invalid "start" offset is fatal */
throw PlaylistError::BadRange();
queue_print_info(r, partition, queue, start, end);
queue_print_info(r, queue, start, end);
}
void
playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
playlist_print_id(Response &r, const playlist &playlist,
unsigned id)
{
int position;
@ -70,38 +68,34 @@ playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
/* no such song */
throw PlaylistError::NoSuchSong();
playlist_print_info(r, partition,
playlist, position, position + 1);
playlist_print_info(r, playlist, position, position + 1);
}
bool
playlist_print_current(Response &r, Partition &partition,
const playlist &playlist)
playlist_print_current(Response &r, const playlist &playlist)
{
int current_position = playlist.GetCurrentPosition();
if (current_position < 0)
return false;
queue_print_info(r, partition, playlist.queue,
queue_print_info(r, playlist.queue,
current_position, current_position + 1);
return true;
}
void
playlist_print_find(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_find(Response &r, const playlist &playlist,
const SongFilter &filter)
{
queue_find(r, partition, playlist.queue, filter);
queue_find(r, playlist.queue, filter);
}
void
playlist_print_changes_info(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_changes_info(Response &r, const playlist &playlist,
uint32_t version,
unsigned start, unsigned end)
{
queue_print_changes_info(r, partition, playlist.queue, version,
queue_print_changes_info(r, playlist.queue, version,
start, end);
}

View File

@ -23,7 +23,6 @@
#include <stdint.h>
struct playlist;
struct Partition;
class SongFilter;
class Response;
@ -31,8 +30,7 @@ class Response;
* Sends the whole playlist to the client, song URIs only.
*/
void
playlist_print_uris(Response &r, Partition &partition,
const playlist &playlist);
playlist_print_uris(Response &r, const playlist &playlist);
/**
* Sends a range of the playlist to the client, including all known
@ -43,8 +41,7 @@ playlist_print_uris(Response &r, Partition &partition,
* Throws #PlaylistError if the range is invalid.
*/
void
playlist_print_info(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_info(Response &r, const playlist &playlist,
unsigned start, unsigned end);
/**
@ -53,8 +50,7 @@ playlist_print_info(Response &r, Partition &partition,
* Throws #PlaylistError if the range is invalid.
*/
void
playlist_print_id(Response &r, Partition &partition,
const playlist &playlist, unsigned id);
playlist_print_id(Response &r, const playlist &playlist, unsigned id);
/**
* Sends the current song to the client.
@ -62,23 +58,20 @@ playlist_print_id(Response &r, Partition &partition,
* @return true on success, false if there is no current song
*/
bool
playlist_print_current(Response &r, Partition &partition,
const playlist &playlist);
playlist_print_current(Response &r, const playlist &playlist);
/**
* Find songs in the playlist.
*/
void
playlist_print_find(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_find(Response &r, const playlist &playlist,
const SongFilter &filter);
/**
* Print detailed changes since the specified playlist version.
*/
void
playlist_print_changes_info(Response &r, Partition &partition,
const playlist &playlist,
playlist_print_changes_info(Response &r, const playlist &playlist,
uint32_t version,
unsigned start, unsigned end);

View File

@ -33,24 +33,13 @@
#define SONG_FILE "file: "
static void
song_print_uri(Response &r, Partition &partition, const char *uri, bool base)
song_print_uri(Response &r, const char *uri, bool base)
{
std::string allocated;
if (base) {
uri = PathTraitsUTF8::GetBase(uri);
} else {
#ifdef ENABLE_DATABASE
const Storage *storage = partition.instance.storage;
if (storage != nullptr) {
const char *suffix = storage->MapToRelativeUTF8(uri);
if (suffix != nullptr)
uri = suffix;
}
#else
(void)partition;
#endif
allocated = uri_remove_auth(uri);
if (!allocated.empty())
uri = allocated.c_str();
@ -60,20 +49,18 @@ song_print_uri(Response &r, Partition &partition, const char *uri, bool base)
}
void
song_print_uri(Response &r, Partition &partition,
const LightSong &song, bool base)
song_print_uri(Response &r, const LightSong &song, bool base)
{
if (!base && song.directory != nullptr)
r.Format(SONG_FILE "%s/%s\n", song.directory, song.uri);
else
song_print_uri(r, partition, song.uri, base);
song_print_uri(r, song.uri, base);
}
void
song_print_uri(Response &r, Partition &partition,
const DetachedSong &song, bool base)
song_print_uri(Response &r, const DetachedSong &song, bool base)
{
song_print_uri(r, partition, song.GetURI(), base);
song_print_uri(r, song.GetURI(), base);
}
static void
@ -95,10 +82,9 @@ PrintRange(Response &r, SongTime start_time, SongTime end_time)
}
void
song_print_info(Response &r, Partition &partition,
const LightSong &song, bool base)
song_print_info(Response &r, const LightSong &song, bool base)
{
song_print_uri(r, partition, song, base);
song_print_uri(r, song, base);
PrintRange(r, song.start_time, song.end_time);
@ -109,10 +95,9 @@ song_print_info(Response &r, Partition &partition,
}
void
song_print_info(Response &r, Partition &partition,
const DetachedSong &song, bool base)
song_print_info(Response &r, const DetachedSong &song, bool base)
{
song_print_uri(r, partition, song, base);
song_print_uri(r, song, base);
PrintRange(r, song.GetStartTime(), song.GetEndTime());

View File

@ -23,22 +23,17 @@
struct LightSong;
class DetachedSong;
class Response;
struct Partition;
void
song_print_info(Response &r, Partition &partition,
const DetachedSong &song, bool base=false);
song_print_info(Response &r, const DetachedSong &song, bool base=false);
void
song_print_info(Response &r, Partition &partition,
const LightSong &song, bool base=false);
song_print_info(Response &r, const LightSong &song, bool base=false);
void
song_print_uri(Response &r, Partition &partition,
const LightSong &song, bool base=false);
song_print_uri(Response &r, const LightSong &song, bool base=false);
void
song_print_uri(Response &r, Partition &partition,
const DetachedSong &song, bool base=false);
song_print_uri(Response &r, const DetachedSong &song, bool base=false);
#endif

View File

@ -193,7 +193,7 @@ handle_lsinfo_relative(Client &client, Response &r, const char *uri)
}
static CommandResult
handle_lsinfo_path(Client &client, Response &r,
handle_lsinfo_path(Client &, Response &r,
const char *path_utf8, Path path_fs)
{
DetachedSong song(path_utf8);
@ -202,7 +202,7 @@ handle_lsinfo_path(Client &client, Response &r,
return CommandResult::ERROR;
}
song_print_info(r, client.partition, song);
song_print_info(r, song);
return CommandResult::OK;
}

View File

@ -86,7 +86,7 @@ handle_stop(Client &client, gcc_unused Request args, gcc_unused Response &r)
CommandResult
handle_currentsong(Client &client, gcc_unused Request args, Response &r)
{
playlist_print_current(r, client.partition, client.playlist);
playlist_print_current(r, client.playlist);
return CommandResult::OK;
}

View File

@ -188,7 +188,7 @@ handle_deleteid(Client &client, Request args, gcc_unused Response &r)
CommandResult
handle_playlist(Client &client, gcc_unused Request args, Response &r)
{
playlist_print_uris(r, client.partition, client.playlist);
playlist_print_uris(r, client.playlist);
return CommandResult::OK;
}
@ -212,8 +212,7 @@ handle_plchanges(Client &client, Request args, Response &r)
{
uint32_t version = ParseCommandArgU32(args.front());
RangeArg range = args.ParseOptional(1, RangeArg::All());
playlist_print_changes_info(r, client.partition,
client.playlist, version,
playlist_print_changes_info(r, client.playlist, version,
range.start, range.end);
return CommandResult::OK;
}
@ -233,7 +232,7 @@ handle_playlistinfo(Client &client, Request args, Response &r)
{
RangeArg range = args.ParseOptional(0, RangeArg::All());
playlist_print_info(r, client.partition, client.playlist,
playlist_print_info(r, client.playlist,
range.start, range.end);
return CommandResult::OK;
}
@ -243,10 +242,9 @@ handle_playlistid(Client &client, Request args, Response &r)
{
if (!args.IsEmpty()) {
unsigned id = args.ParseUnsigned(0);
playlist_print_id(r, client.partition,
client.playlist, id);
playlist_print_id(r, client.playlist, id);
} else {
playlist_print_info(r, client.partition, client.playlist,
playlist_print_info(r, client.playlist,
0, std::numeric_limits<unsigned>::max());
}
@ -263,7 +261,7 @@ handle_playlist_match(Client &client, Request args, Response &r,
return CommandResult::ERROR;
}
playlist_print_find(r, client.partition, client.playlist, filter);
playlist_print_find(r, client.playlist, filter);
return CommandResult::OK;
}

View File

@ -33,7 +33,6 @@
struct sticker_song_find_data {
Response &r;
Partition &partition;
const char *name;
};
@ -44,7 +43,7 @@ sticker_song_find_print_cb(const LightSong &song, const char *value,
struct sticker_song_find_data *data =
(struct sticker_song_find_data *)user_data;
song_print_uri(data->r, data->partition, song);
song_print_uri(data->r, song);
sticker_print_value(data->r, data->name, value);
}
@ -137,7 +136,6 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
struct sticker_song_find_data data = {
r,
partition,
args[3],
};

View File

@ -96,10 +96,9 @@ print_playlist_in_directory(Response &r, bool base,
}
static void
PrintSongBrief(Response &r, Partition &partition,
bool base, const LightSong &song)
PrintSongBrief(Response &r, bool base, const LightSong &song)
{
song_print_uri(r, partition, song, base);
song_print_uri(r, song, base);
if (song.tag->has_playlist)
/* this song file has an embedded CUE sheet */
@ -108,10 +107,9 @@ PrintSongBrief(Response &r, Partition &partition,
}
static void
PrintSongFull(Response &r, Partition &partition,
bool base, const LightSong &song)
PrintSongFull(Response &r, bool base, const LightSong &song)
{
song_print_info(r, partition, song, base);
song_print_info(r, song, base);
if (song.tag->has_playlist)
/* this song file has an embedded CUE sheet */
@ -182,7 +180,7 @@ db_selection_print(Response &r, Partition &partition,
std::ref(r), base, _1)
: VisitDirectory();
VisitSong s = std::bind(full ? PrintSongFull : PrintSongBrief,
std::ref(r), std::ref(partition), base, _1);
std::ref(r), base, _1);
const auto p = selection.filter == nullptr
? std::bind(full ? PrintPlaylistFull : PrintPlaylistBrief,
std::ref(r), base, _1, _2)
@ -248,9 +246,9 @@ db_selection_print(Response &r, Partition &partition,
}
static void
PrintSongURIVisitor(Response &r, Partition &partition, const LightSong &song)
PrintSongURIVisitor(Response &r, const LightSong &song)
{
song_print_uri(r, partition, song);
song_print_uri(r, song);
}
static void
@ -279,7 +277,7 @@ PrintUniqueTags(Response &r, Partition &partition,
if (type == LOCATE_TAG_FILE_TYPE) {
using namespace std::placeholders;
const auto f = std::bind(PrintSongURIVisitor,
std::ref(r), std::ref(partition), _1);
std::ref(r), _1);
db.Visit(selection, f);
} else {
assert(type < TAG_NUM_OF_ITEM_TYPES);

View File

@ -31,7 +31,7 @@
#include "Instance.hxx"
static void
playlist_provider_print(Response &r, Partition &partition,
playlist_provider_print(Response &r,
const SongLoader &loader,
const char *uri,
SongEnumerator &e, bool detail)
@ -45,11 +45,11 @@ playlist_provider_print(Response &r, Partition &partition,
if (playlist_check_translate_song(*song, base_uri.c_str(),
loader) &&
detail)
song_print_info(r, partition, *song);
song_print_info(r, *song);
else
/* fallback if no detail was requested or no
detail was available */
song_print_uri(r, partition, *song);
song_print_uri(r, *song);
}
}
@ -61,6 +61,10 @@ playlist_file_print(Response &r, Partition &partition,
Mutex mutex;
Cond cond;
#ifndef ENABLE_DATABASE
(void)partition;
#endif
SongEnumerator *playlist = playlist_open_any(uri,
#ifdef ENABLE_DATABASE
partition.instance.storage,
@ -69,7 +73,7 @@ playlist_file_print(Response &r, Partition &partition,
if (playlist == nullptr)
return false;
playlist_provider_print(r, partition, loader, uri, *playlist, detail);
playlist_provider_print(r, loader, uri, *playlist, detail);
delete playlist;
return true;
}

View File

@ -33,10 +33,10 @@
* @param end the index of the last song (excluding)
*/
static void
queue_print_song_info(Response &r, Partition &partition, const Queue &queue,
queue_print_song_info(Response &r, const Queue &queue,
unsigned position)
{
song_print_info(r, partition, queue.Get(position));
song_print_info(r, queue.Get(position));
r.Format("Pos: %u\nId: %u\n",
position, queue.PositionToId(position));
@ -46,18 +46,18 @@ queue_print_song_info(Response &r, Partition &partition, const Queue &queue,
}
void
queue_print_info(Response &r, Partition &partition, const Queue &queue,
queue_print_info(Response &r, const Queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
assert(end <= queue.GetLength());
for (unsigned i = start; i < end; ++i)
queue_print_song_info(r, partition, queue, i);
queue_print_song_info(r, queue, i);
}
void
queue_print_uris(Response &r, Partition &partition, const Queue &queue,
queue_print_uris(Response &r, const Queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
@ -65,12 +65,12 @@ queue_print_uris(Response &r, Partition &partition, const Queue &queue,
for (unsigned i = start; i < end; ++i) {
r.Format("%i:", i);
song_print_uri(r, partition, queue.Get(i));
song_print_uri(r, queue.Get(i));
}
}
void
queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
queue_print_changes_info(Response &r, const Queue &queue,
uint32_t version,
unsigned start, unsigned end)
{
@ -84,7 +84,7 @@ queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
for (unsigned i = start; i < end; i++)
if (queue.IsNewerAtPosition(i, version))
queue_print_song_info(r, partition, queue, i);
queue_print_song_info(r, queue, i);
}
void
@ -107,13 +107,13 @@ queue_print_changes_position(Response &r, const Queue &queue,
}
void
queue_find(Response &r, Partition &partition, const Queue &queue,
queue_find(Response &r, const Queue &queue,
const SongFilter &filter)
{
for (unsigned i = 0; i < queue.GetLength(); i++) {
const DetachedSong &song = queue.Get(i);
if (filter.Match(song))
queue_print_song_info(r, partition, queue, i);
queue_print_song_info(r, queue, i);
}
}

View File

@ -28,20 +28,19 @@
#include <stdint.h>
struct Queue;
struct Partition;
class SongFilter;
class Response;
void
queue_print_info(Response &r, Partition &partition, const Queue &queue,
queue_print_info(Response &r, const Queue &queue,
unsigned start, unsigned end);
void
queue_print_uris(Response &r, Partition &partition, const Queue &queue,
queue_print_uris(Response &r, const Queue &queue,
unsigned start, unsigned end);
void
queue_print_changes_info(Response &r, Partition &partition, const Queue &queue,
queue_print_changes_info(Response &r, const Queue &queue,
uint32_t version,
unsigned start, unsigned end);
@ -51,7 +50,7 @@ queue_print_changes_position(Response &r, const Queue &queue,
unsigned start, unsigned end);
void
queue_find(Response &response, Partition &partition, const Queue &queue,
queue_find(Response &response, const Queue &queue,
const SongFilter &filter);
#endif