From ca36ac2ba196ee2bbe4b54ee9a71d49174803277 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 2 Feb 2014 14:37:52 +0100 Subject: SongLoader: new class that merges duplicate code There was quite a lot of duplicate code for loading DetachedSong objects, with different semantics for "securely" loading local files. --- src/PlaylistEdit.cxx | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'src/PlaylistEdit.cxx') diff --git a/src/PlaylistEdit.cxx b/src/PlaylistEdit.cxx index 11b867546..8d2c76e6e 100644 --- a/src/PlaylistEdit.cxx +++ b/src/PlaylistEdit.cxx @@ -30,9 +30,8 @@ #include "util/UriUtil.hxx" #include "util/Error.hxx" #include "DetachedSong.hxx" -#include "Mapper.hxx" +#include "SongLoader.hxx" #include "Idle.hxx" -#include "db/DatabaseSong.hxx" #include "Log.hxx" #include @@ -56,17 +55,6 @@ playlist::Clear(PlayerControl &pc) OnModified(); } -PlaylistResult -playlist::AppendFile(PlayerControl &pc, - const char *path_utf8, unsigned *added_id) -{ - DetachedSong song(path_utf8); - if (!song.Update()) - return PlaylistResult::NO_SUCH_SONG; - - return AppendSong(pc, std::move(song), added_id); -} - PlaylistResult playlist::AppendSong(PlayerControl &pc, DetachedSong &&song, unsigned *added_id) @@ -81,7 +69,7 @@ playlist::AppendSong(PlayerControl &pc, id = queue.Append(std::move(song), 0); if (queue.random) { - /* shuffle the new song into the list of remaining + /* shuffle the new song into the list of remaning songs to play */ unsigned start; @@ -104,19 +92,19 @@ playlist::AppendSong(PlayerControl &pc, PlaylistResult playlist::AppendURI(PlayerControl &pc, + const SongLoader &loader, const char *uri, unsigned *added_id) { FormatDebug(playlist_domain, "add to playlist: %s", uri); - DetachedSong *song; - if (uri_has_scheme(uri)) { - song = new DetachedSong(uri); - } else { -#ifdef ENABLE_DATABASE - song = DatabaseDetachSong(uri, IgnoreError()); - if (song == nullptr) -#endif - return PlaylistResult::NO_SUCH_SONG; + Error error; + DetachedSong *song = loader.LoadSong(uri, error); + if (song == nullptr) { + // TODO: return the Error + LogError(error); + return error.IsDomain(playlist_domain) + ? PlaylistResult(error.GetCode()) + : PlaylistResult::NO_SUCH_SONG; } PlaylistResult result = AppendSong(pc, std::move(*song), added_id); -- cgit v1.2.3