diff options
Diffstat (limited to '')
-rw-r--r-- | src/command/PlaylistCommands.cxx | 93 |
1 files changed, 40 insertions, 53 deletions
diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index c4441293e..c2b18064c 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,26 +19,25 @@ #include "config.h" #include "PlaylistCommands.hxx" -#include "DatabasePlaylist.hxx" +#include "db/DatabasePlaylist.hxx" #include "CommandError.hxx" #include "PlaylistPrint.hxx" #include "PlaylistSave.hxx" #include "PlaylistFile.hxx" -#include "PlaylistVector.hxx" -#include "PlaylistQueue.hxx" +#include "db/PlaylistVector.hxx" +#include "SongLoader.hxx" #include "BulkEdit.hxx" +#include "playlist/PlaylistQueue.hxx" +#include "playlist/Print.hxx" +#include "queue/Playlist.hxx" #include "TimePrint.hxx" -#include "Client.hxx" +#include "client/Client.hxx" #include "protocol/ArgParser.hxx" #include "protocol/Result.hxx" #include "ls.hxx" -#include "Playlist.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" -#include <assert.h> -#include <stdlib.h> - static void print_spl_list(Client &client, const PlaylistVector &list) { @@ -51,14 +50,14 @@ print_spl_list(Client &client, const PlaylistVector &list) } CommandResult -handle_save(Client &client, gcc_unused int argc, char *argv[]) +handle_save(Client &client, gcc_unused unsigned argc, char *argv[]) { PlaylistResult result = spl_save_playlist(argv[1], client.playlist); return print_playlist_result(client, result); } CommandResult -handle_load(Client &client, int argc, char *argv[]) +handle_load(Client &client, unsigned argc, char *argv[]) { unsigned start_index, end_index; @@ -70,36 +69,19 @@ handle_load(Client &client, int argc, char *argv[]) const ScopeBulkEdit bulk_edit(client.partition); - const PlaylistResult result = - playlist_open_into_queue(argv[1], - start_index, end_index, - client.playlist, - client.player_control, true); - if (result != PlaylistResult::NO_SUCH_LIST) - return print_playlist_result(client, result); - Error error; - if (playlist_load_spl(client.playlist, client.player_control, - argv[1], start_index, end_index, - error)) - return CommandResult::OK; - - if (error.IsDomain(playlist_domain) && - PlaylistResult(error.GetCode()) == PlaylistResult::BAD_NAME) { - /* the message for BAD_NAME is confusing when the - client wants to load a playlist file from the music - directory; patch the Error object to show "no such - playlist" instead */ - Error error2(playlist_domain, int(PlaylistResult::NO_SUCH_LIST), - error.GetMessage()); - error = std::move(error2); - } + const SongLoader loader(client); + if (!playlist_open_into_queue(argv[1], + start_index, end_index, + client.playlist, + client.player_control, loader, error)) + return print_error(client, error); - return print_error(client, error); + return CommandResult::OK; } CommandResult -handle_listplaylist(Client &client, gcc_unused int argc, char *argv[]) +handle_listplaylist(Client &client, gcc_unused unsigned argc, char *argv[]) { if (playlist_file_print(client, argv[1], false)) return CommandResult::OK; @@ -112,7 +94,7 @@ handle_listplaylist(Client &client, gcc_unused int argc, char *argv[]) CommandResult handle_listplaylistinfo(Client &client, - gcc_unused int argc, char *argv[]) + gcc_unused unsigned argc, char *argv[]) { if (playlist_file_print(client, argv[1], true)) return CommandResult::OK; @@ -124,7 +106,7 @@ handle_listplaylistinfo(Client &client, } CommandResult -handle_rm(Client &client, gcc_unused int argc, char *argv[]) +handle_rm(Client &client, gcc_unused unsigned argc, char *argv[]) { Error error; return spl_delete(argv[1], error) @@ -133,7 +115,7 @@ handle_rm(Client &client, gcc_unused int argc, char *argv[]) } CommandResult -handle_rename(Client &client, gcc_unused int argc, char *argv[]) +handle_rename(Client &client, gcc_unused unsigned argc, char *argv[]) { Error error; return spl_rename(argv[1], argv[2], error) @@ -143,7 +125,7 @@ handle_rename(Client &client, gcc_unused int argc, char *argv[]) CommandResult handle_playlistdelete(Client &client, - gcc_unused int argc, char *argv[]) { + gcc_unused unsigned argc, char *argv[]) { char *playlist = argv[1]; unsigned from; @@ -157,7 +139,7 @@ handle_playlistdelete(Client &client, } CommandResult -handle_playlistmove(Client &client, gcc_unused int argc, char *argv[]) +handle_playlistmove(Client &client, gcc_unused unsigned argc, char *argv[]) { char *playlist = argv[1]; unsigned from, to; @@ -174,7 +156,7 @@ handle_playlistmove(Client &client, gcc_unused int argc, char *argv[]) } CommandResult -handle_playlistclear(Client &client, gcc_unused int argc, char *argv[]) +handle_playlistclear(Client &client, gcc_unused unsigned argc, char *argv[]) { Error error; return spl_clear(argv[1], error) @@ -183,7 +165,7 @@ handle_playlistclear(Client &client, gcc_unused int argc, char *argv[]) } CommandResult -handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) +handle_playlistadd(Client &client, gcc_unused unsigned argc, char *argv[]) { char *playlist = argv[1]; char *uri = argv[2]; @@ -191,16 +173,21 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) bool success; Error error; if (uri_has_scheme(uri)) { - if (!uri_supported_scheme(uri)) { - command_error(client, ACK_ERROR_NO_EXIST, - "unsupported URI scheme"); - return CommandResult::ERROR; - } - - success = spl_append_uri(uri, playlist, error); - } else - success = search_add_to_playlist(uri, playlist, nullptr, + const SongLoader loader(client); + success = spl_append_uri(playlist, loader, uri, error); + } else { +#ifdef ENABLE_DATABASE + const Database *db = client.GetDatabase(error); + if (db == nullptr) + return print_error(client, error); + + success = search_add_to_playlist(*db, *client.GetStorage(), + uri, playlist, nullptr, error); +#else + success = false; +#endif + } if (!success && !error.IsDefined()) { command_error(client, ACK_ERROR_NO_EXIST, @@ -213,7 +200,7 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[]) CommandResult handle_listplaylists(Client &client, - gcc_unused int argc, gcc_unused char *argv[]) + gcc_unused unsigned argc, gcc_unused char *argv[]) { Error error; const auto list = ListPlaylistFiles(error); |