command/playlist: move code to SearchInsertIntoPlaylist()
This commit is contained in:
parent
061dd2dfef
commit
b4e72aba6c
|
@ -231,15 +231,12 @@ handle_playlistadd_position(Client &client, const char *playlist_name,
|
|||
editor.Insert(position, uri);
|
||||
} else {
|
||||
#ifdef ENABLE_DATABASE
|
||||
const auto &db = client.GetDatabaseOrThrow();
|
||||
const auto *storage = client.GetStorage();
|
||||
const DatabaseSelection selection(uri, true, nullptr);
|
||||
|
||||
db.Visit(selection, [&editor, &position, storage](const auto &song){
|
||||
editor.Insert(position,
|
||||
DatabaseDetachSong(storage, song));
|
||||
++position;
|
||||
});
|
||||
SearchInsertIntoPlaylist(client.GetDatabaseOrThrow(),
|
||||
client.GetStorage(),
|
||||
selection,
|
||||
editor, position);
|
||||
#else
|
||||
(void)client;
|
||||
r.Error(ACK_ERROR_NO_EXIST, "No database");
|
||||
|
|
|
@ -41,3 +41,18 @@ search_add_to_playlist(const Database &db, const Storage *storage,
|
|||
const auto f = [=](auto && arg1) { return AddSong(storage, playlist_path_utf8, arg1); };
|
||||
db.Visit(selection, f);
|
||||
}
|
||||
|
||||
void
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
PlaylistFileEditor &playlist,
|
||||
unsigned position)
|
||||
{
|
||||
assert(position <= playlist.size());
|
||||
|
||||
db.Visit(selection, [&playlist, &position, storage](const auto &song){
|
||||
playlist.Insert(position,
|
||||
DatabaseDetachSong(storage, song));
|
||||
++position;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
class Database;
|
||||
class Storage;
|
||||
struct DatabaseSelection;
|
||||
class PlaylistFileEditor;
|
||||
|
||||
gcc_nonnull(3)
|
||||
void
|
||||
|
@ -32,4 +33,10 @@ search_add_to_playlist(const Database &db, const Storage *storage,
|
|||
const char *playlist_path_utf8,
|
||||
const DatabaseSelection &selection);
|
||||
|
||||
void
|
||||
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||
const DatabaseSelection &selection,
|
||||
PlaylistFileEditor &playlist,
|
||||
unsigned position);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue