diff options
author | Max Kellermann <max@duempel.org> | 2014-02-02 14:37:52 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-02-03 23:32:10 +0100 |
commit | ca36ac2ba196ee2bbe4b54ee9a71d49174803277 (patch) | |
tree | d365b1ac7872e1785befdcebf254885c1c27a268 /src/PlaylistEdit.cxx | |
parent | ba675d6a55769a6e82a6efaa2f4a812a4eea2362 (diff) | |
download | mpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.tar.gz mpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.tar.xz mpd-ca36ac2ba196ee2bbe4b54ee9a71d49174803277.zip |
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.
Diffstat (limited to 'src/PlaylistEdit.cxx')
-rw-r--r-- | src/PlaylistEdit.cxx | 34 |
1 files changed, 11 insertions, 23 deletions
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 <stdlib.h> @@ -57,17 +56,6 @@ playlist::Clear(PlayerControl &pc) } 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); |