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);
|
editor.Insert(position, uri);
|
||||||
} else {
|
} else {
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
const auto &db = client.GetDatabaseOrThrow();
|
|
||||||
const auto *storage = client.GetStorage();
|
|
||||||
const DatabaseSelection selection(uri, true, nullptr);
|
const DatabaseSelection selection(uri, true, nullptr);
|
||||||
|
|
||||||
db.Visit(selection, [&editor, &position, storage](const auto &song){
|
SearchInsertIntoPlaylist(client.GetDatabaseOrThrow(),
|
||||||
editor.Insert(position,
|
client.GetStorage(),
|
||||||
DatabaseDetachSong(storage, song));
|
selection,
|
||||||
++position;
|
editor, position);
|
||||||
});
|
|
||||||
#else
|
#else
|
||||||
(void)client;
|
(void)client;
|
||||||
r.Error(ACK_ERROR_NO_EXIST, "No database");
|
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); };
|
const auto f = [=](auto && arg1) { return AddSong(storage, playlist_path_utf8, arg1); };
|
||||||
db.Visit(selection, f);
|
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 Database;
|
||||||
class Storage;
|
class Storage;
|
||||||
struct DatabaseSelection;
|
struct DatabaseSelection;
|
||||||
|
class PlaylistFileEditor;
|
||||||
|
|
||||||
gcc_nonnull(3)
|
gcc_nonnull(3)
|
||||||
void
|
void
|
||||||
|
@ -32,4 +33,10 @@ search_add_to_playlist(const Database &db, const Storage *storage,
|
||||||
const char *playlist_path_utf8,
|
const char *playlist_path_utf8,
|
||||||
const DatabaseSelection &selection);
|
const DatabaseSelection &selection);
|
||||||
|
|
||||||
|
void
|
||||||
|
SearchInsertIntoPlaylist(const Database &db, const Storage *storage,
|
||||||
|
const DatabaseSelection &selection,
|
||||||
|
PlaylistFileEditor &playlist,
|
||||||
|
unsigned position);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue