Commit 5a931a70 authored by Alexandre Fernandez's avatar Alexandre Fernandez

Task: Allow parser to give optional Playlist context to a task

parent 180cde93
......@@ -443,10 +443,12 @@ std::shared_ptr<Media> MediaLibrary::addFile( std::shared_ptr<fs::IFile> fileFs,
void MediaLibrary::addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist )
{
if ( m_parser != nullptr )
m_parser->parse( std::move( fileFs ), std::move( parentFolder ), std::move( parentFolderFs ) );
m_parser->parse( std::move( fileFs ), std::move( parentFolder ),
std::move( parentFolderFs ), std::move( parentPlaylist ) );
}
bool MediaLibrary::deleteFolder( const Folder& folder )
......
......@@ -45,6 +45,7 @@ class Show;
class Device;
class Folder;
class Genre;
class Playlist;
namespace factory
{
......@@ -76,9 +77,11 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
virtual void addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist );
bool deleteFolder(const Folder& folder );
......
......@@ -330,7 +330,7 @@ void FsDiscoverer::checkFiles( std::shared_ptr<fs::IDirectory> parentFolderFs,
}
// Insert all files at once to avoid SQL write contention
for ( auto& p : filesToAdd )
m_ml->addDiscoveredFile( p, parentFolder, parentFolderFs );
m_ml->addDiscoveredFile( p, parentFolder, parentFolderFs, { nullptr, 0 } );
t->commit();
LOG_INFO( "Done checking files in ", parentFolderFs->mrl() );
}, std::move( files ), std::move( filesToAdd ), std::move( filesToRemove ) );
......
......@@ -72,13 +72,15 @@ void Parser::parse( std::shared_ptr<File> file, std::shared_ptr<Media> media,
void Parser::parse( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist )
{
if ( m_services.empty() == true )
return;
std::string mrl = fileFs->mrl();
m_services[0]->parse( std::unique_ptr<parser::Task>( new parser::Task(
std::move( fileFs ), std::move( parentFolder ), std::move( parentFolderFs ), mrl ) ) );
std::move( fileFs ), std::move( parentFolder ), std::move( parentFolderFs ),
std::move( parentPlaylist.first ), parentPlaylist.second, mrl ) ) );
m_opToDo += m_services.size();
updateStats();
}
......
......@@ -54,7 +54,8 @@ public:
const std::string& mrl );
void parse( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist );
void start();
void pause();
void resume();
......
......@@ -49,10 +49,14 @@ Task::Task( std::shared_ptr<File> file, std::shared_ptr<Media> media,
Task::Task( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::shared_ptr<Playlist> parentPlaylist,
unsigned int parentPlaylistIndex,
std::string mrl )
: fileFs( std::move( fileFs ) )
, parentFolder( std::move( parentFolder ) )
, parentFolderFs( std::move( parentFolderFs ) )
, parentPlaylist( std::move( parentPlaylist ) )
, parentPlaylistIndex( parentPlaylistIndex )
, mrl( std::move( mrl ) )
, currentService( 0 )
, step( ParserStep::None )
......
......@@ -41,6 +41,7 @@ class IFile;
class Media;
class File;
class Folder;
class Playlist;
namespace parser
{
......@@ -81,6 +82,8 @@ struct Task
Task( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::shared_ptr<Playlist> parentPlaylist,
unsigned int parentPlaylistIndex,
std::string mrl );
void markStepCompleted( ParserStep stepCompleted );
......@@ -91,6 +94,8 @@ struct Task
std::shared_ptr<fs::IFile> fileFs;
std::shared_ptr<Folder> parentFolder;
std::shared_ptr<fs::IDirectory> parentFolderFs;
std::shared_ptr<Playlist> parentPlaylist;
unsigned int parentPlaylistIndex;
std::string mrl;
VLC::Media vlcMedia;
unsigned int currentService;
......
......@@ -157,7 +157,8 @@ std::vector<const char*> MediaLibraryTester::getSupportedExtensions() const
void MediaLibraryTester::addDiscoveredFile(std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs)
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int>)
{
MediaLibrary::addFile( fileFs, parentFolder, parentFolderFs );
}
......@@ -63,7 +63,8 @@ public:
std::vector<const char*> getSupportedExtensions() const;
virtual void addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs ) override;
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist ) override;
private:
std::shared_ptr<fs::IDirectory> dummyDirectory;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment