Mapper: move map_song_detach() to db/DatabaseSong.cxx
Use Storage::MapUTF8() internally, don't use global variables.
This commit is contained in:
@@ -19,24 +19,26 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "DatabasePlaylist.hxx"
|
||||
#include "DatabaseSong.hxx"
|
||||
#include "Selection.hxx"
|
||||
#include "PlaylistFile.hxx"
|
||||
#include "DatabasePlugin.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "Mapper.hxx"
|
||||
#include "storage/StorageInterface.hxx"
|
||||
|
||||
#include <functional>
|
||||
|
||||
static bool
|
||||
AddSong(const char *playlist_path_utf8,
|
||||
AddSong(const Storage &storage, const char *playlist_path_utf8,
|
||||
const LightSong &song, Error &error)
|
||||
{
|
||||
return spl_append_song(playlist_path_utf8, map_song_detach(song),
|
||||
return spl_append_song(playlist_path_utf8,
|
||||
DatabaseDetachSong(storage, song),
|
||||
error);
|
||||
}
|
||||
|
||||
bool
|
||||
search_add_to_playlist(const Database &db,
|
||||
search_add_to_playlist(const Database &db, const Storage &storage,
|
||||
const char *uri, const char *playlist_path_utf8,
|
||||
const SongFilter *filter,
|
||||
Error &error)
|
||||
@@ -44,6 +46,7 @@ search_add_to_playlist(const Database &db,
|
||||
const DatabaseSelection selection(uri, true, filter);
|
||||
|
||||
using namespace std::placeholders;
|
||||
const auto f = std::bind(AddSong, playlist_path_utf8, _1, _2);
|
||||
const auto f = std::bind(AddSong, std::ref(storage),
|
||||
playlist_path_utf8, _1, _2);
|
||||
return db.Visit(selection, f, error);
|
||||
}
|
||||
|
@@ -23,12 +23,13 @@
|
||||
#include "Compiler.h"
|
||||
|
||||
class Database;
|
||||
class Storage;
|
||||
class SongFilter;
|
||||
class Error;
|
||||
|
||||
gcc_nonnull(2,3)
|
||||
gcc_nonnull(3,4)
|
||||
bool
|
||||
search_add_to_playlist(const Database &db,
|
||||
search_add_to_playlist(const Database &db, const Storage &storage,
|
||||
const char *uri, const char *path_utf8,
|
||||
const SongFilter *filter,
|
||||
Error &error);
|
||||
|
@@ -19,22 +19,23 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "DatabaseQueue.hxx"
|
||||
#include "DatabaseGlue.hxx"
|
||||
#include "DatabaseSong.hxx"
|
||||
#include "DatabasePlugin.hxx"
|
||||
#include "Partition.hxx"
|
||||
#include "Instance.hxx"
|
||||
#include "util/Error.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "Mapper.hxx"
|
||||
|
||||
#include <functional>
|
||||
|
||||
static bool
|
||||
AddToQueue(Partition &partition, const LightSong &song, Error &error)
|
||||
{
|
||||
const Storage &storage = *partition.instance.storage;
|
||||
PlaylistResult result =
|
||||
partition.playlist.AppendSong(partition.pc,
|
||||
map_song_detach(song),
|
||||
DatabaseDetachSong(storage,
|
||||
song),
|
||||
nullptr);
|
||||
if (result != PlaylistResult::SUCCESS) {
|
||||
error.Set(playlist_domain, int(result), "Playlist error");
|
||||
|
@@ -19,18 +19,35 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "DatabaseSong.hxx"
|
||||
#include "LightSong.hxx"
|
||||
#include "DatabasePlugin.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "Mapper.hxx"
|
||||
#include "storage/StorageInterface.hxx"
|
||||
|
||||
DetachedSong
|
||||
DatabaseDetachSong(const Storage &storage, const LightSong &song)
|
||||
{
|
||||
DetachedSong detached(song);
|
||||
assert(detached.IsInDatabase());
|
||||
|
||||
if (!detached.HasRealURI()) {
|
||||
const auto uri = song.GetURI();
|
||||
detached.SetRealURI(storage.MapUTF8(uri.c_str()));
|
||||
}
|
||||
|
||||
return detached;
|
||||
}
|
||||
|
||||
DetachedSong *
|
||||
DatabaseDetachSong(const Database &db, const char *uri, Error &error)
|
||||
DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri,
|
||||
Error &error)
|
||||
{
|
||||
const LightSong *tmp = db.GetSong(uri, error);
|
||||
if (tmp == nullptr)
|
||||
return nullptr;
|
||||
|
||||
DetachedSong *song = new DetachedSong(map_song_detach(*tmp));
|
||||
DetachedSong *song = new DetachedSong(DatabaseDetachSong(storage,
|
||||
*tmp));
|
||||
db.ReturnSong(tmp);
|
||||
return song;
|
||||
}
|
||||
|
@@ -22,10 +22,20 @@
|
||||
|
||||
#include "Compiler.h"
|
||||
|
||||
struct LightSong;
|
||||
class Database;
|
||||
class Storage;
|
||||
class DetachedSong;
|
||||
class Error;
|
||||
|
||||
/**
|
||||
* "Detach" the #Song object, i.e. convert it to a #DetachedSong
|
||||
* instance.
|
||||
*/
|
||||
gcc_pure
|
||||
DetachedSong
|
||||
DatabaseDetachSong(const Storage &storage, const LightSong &song);
|
||||
|
||||
/**
|
||||
* Look up a song in the database and convert it to a #DetachedSong
|
||||
* instance. The caller is responsible for freeing it.
|
||||
@@ -34,6 +44,7 @@ class Error;
|
||||
*/
|
||||
gcc_malloc gcc_nonnull_all
|
||||
DetachedSong *
|
||||
DatabaseDetachSong(const Database &db, const char *uri, Error &error);
|
||||
DatabaseDetachSong(const Database &db, const Storage &storage, const char *uri,
|
||||
Error &error);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user