db/LightSong: pass URI to constructor

This commit is contained in:
Max Kellermann 2018-07-06 16:56:12 +02:00
parent 80cb680fca
commit 45139f94bb
5 changed files with 20 additions and 19 deletions

View File

@ -33,9 +33,8 @@ DetachedSong::DetachedSong(const LightSong &other)
DetachedSong::operator LightSong() const noexcept DetachedSong::operator LightSong() const noexcept
{ {
LightSong result(tag); LightSong result(uri.c_str(), tag);
result.directory = nullptr; result.directory = nullptr;
result.uri = uri.c_str();
result.real_uri = real_uri.empty() ? nullptr : real_uri.c_str(); result.real_uri = real_uri.empty() ? nullptr : real_uri.c_str();
result.mtime = mtime; result.mtime = mtime;
result.start_time = start_time; result.start_time = start_time;

View File

@ -78,8 +78,8 @@ struct LightSong {
*/ */
SongTime end_time = SongTime::zero(); SongTime end_time = SongTime::zero();
explicit LightSong(const Tag &_tag) noexcept LightSong(const char *_uri, const Tag &_tag) noexcept
:tag(_tag) {} :uri(_uri), tag(_tag) {}
gcc_pure gcc_pure
std::string GetURI() const noexcept { std::string GetURI() const noexcept {

View File

@ -203,10 +203,8 @@ Copy(TagBuilder &tag, TagType d_tag,
} }
ProxySong::ProxySong(const mpd_song *song) ProxySong::ProxySong(const mpd_song *song)
:LightSong(tag2) :LightSong(mpd_song_get_uri(song), tag2)
{ {
uri = mpd_song_get_uri(song);
const auto _mtime = mpd_song_get_last_modified(song); const auto _mtime = mpd_song_get_last_modified(song);
if (_mtime > 0) if (_mtime > 0)
mtime = std::chrono::system_clock::from_time_t(_mtime); mtime = std::chrono::system_clock::from_time_t(_mtime);

View File

@ -98,10 +98,9 @@ Song::GetURI() const noexcept
LightSong LightSong
Song::Export() const noexcept Song::Export() const noexcept
{ {
LightSong dest(tag); LightSong dest(uri, tag);
dest.directory = parent->IsRoot() dest.directory = parent->IsRoot()
? nullptr : parent->GetPath(); ? nullptr : parent->GetPath();
dest.uri = uri;
dest.real_uri = nullptr; dest.real_uri = nullptr;
dest.mtime = mtime; dest.mtime = mtime;
dest.start_time = start_time; dest.start_time = start_time;

View File

@ -48,18 +48,24 @@
static const char *const rootid = "0"; static const char *const rootid = "0";
class UpnpSong : public LightSong { class UpnpSongData {
std::string uri2, real_uri2; protected:
std::string uri;
Tag tag;
Tag tag2; template<typename U, typename T>
UpnpSongData(U &&_uri, T &&_tag) noexcept
:uri(std::forward<U>(_uri)), tag(std::forward<T>(_tag)) {}
};
class UpnpSong : UpnpSongData, public LightSong {
std::string real_uri2;
public: public:
UpnpSong(UPnPDirObject &&object, std::string &&_uri) UpnpSong(UPnPDirObject &&object, std::string &&_uri)
:LightSong(tag2), :UpnpSongData(std::move(_uri), std::move(object.tag)),
uri2(std::move(_uri)), LightSong(UpnpSongData::uri.c_str(), UpnpSongData::tag),
real_uri2(std::move(object.url)), real_uri2(std::move(object.url)) {
tag2(std::move(object.tag)) {
uri = uri2.c_str();
real_uri = real_uri2.c_str(); real_uri = real_uri2.c_str();
} }
}; };
@ -318,8 +324,7 @@ visitSong(const UPnPDirObject &meta, const char *path,
if (!visit_song) if (!visit_song)
return; return;
LightSong song(meta.tag); LightSong song(path, meta.tag);
song.uri = path;
song.real_uri = meta.url.c_str(); song.real_uri = meta.url.c_str();
if (selection.Match(song)) if (selection.Match(song))