Commit 7377c51f authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Rework network filesystem factories management

parent ec036d25
......@@ -330,6 +330,7 @@ bool MediaLibrary::start()
if ( m_parser != nullptr )
return false;
populateFsFactories();
for ( auto& fsFactory : m_fsFactories )
refreshDevices( *fsFactory );
startDiscoverer();
......@@ -767,6 +768,13 @@ bool MediaLibrary::startThumbnailer()
#endif
}
void MediaLibrary::populateFsFactories()
{
#ifdef HAVE_LIBVLC
m_externalFsFactories.emplace_back( std::make_shared<factory::NetworkFileSystemFactory>( "smb", "dsm-sd" ) );
#endif
}
void MediaLibrary::addLocalFsFactory()
{
m_fsFactories.insert( begin( m_fsFactories ), std::make_shared<factory::FileSystemFactory>( m_deviceLister ) );
......@@ -1218,25 +1226,20 @@ void MediaLibrary::discover( const std::string& entryPoint )
bool MediaLibrary::setDiscoverNetworkEnabled( bool enabled )
{
#ifdef HAVE_LIBVLC
if ( enabled )
{
auto it = std::find_if( begin( m_fsFactories ), end( m_fsFactories ), []( const std::shared_ptr<fs::IFileSystemFactory> fs ) {
return fs->isNetworkFileSystem();
});
if ( it == end( m_fsFactories ) )
m_fsFactories.push_back( std::make_shared<factory::NetworkFileSystemFactory>( "smb", "dsm-sd" ) );
}
else
{
m_fsFactories.erase( std::remove_if( begin( m_fsFactories ), end( m_fsFactories ), []( const std::shared_ptr<fs::IFileSystemFactory> fs ) {
return fs->isNetworkFileSystem();
}), end( m_fsFactories ) );
auto previousSize = m_fsFactories.size();
std::copy_if( begin( m_externalFsFactories ), end( m_externalFsFactories ),
std::back_inserter( m_fsFactories ), []( const std::shared_ptr<fs::IFileSystemFactory> fs ) {
return fs->isNetworkFileSystem();
});
return m_fsFactories.size() == previousSize;
}
m_fsFactories.erase( std::remove_if( begin( m_fsFactories ), end( m_fsFactories ), []( const std::shared_ptr<fs::IFileSystemFactory> fs ) {
return fs->isNetworkFileSystem();
}), end( m_fsFactories ) );
return true;
#else
return false;
#endif
}
Query<IFolder> MediaLibrary::entryPoints() const
......
......@@ -178,6 +178,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual void startDiscoverer();
virtual void startDeletionNotifier();
virtual bool startThumbnailer();
virtual void populateFsFactories();
private:
bool recreateDatabase( const std::string& dbPath );
......@@ -211,6 +212,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
protected:
std::shared_ptr<sqlite::Connection> m_dbConnection;
std::vector<std::shared_ptr<fs::IFileSystemFactory>> m_fsFactories;
std::vector<std::shared_ptr<fs::IFileSystemFactory>> m_externalFsFactories;
std::string m_thumbnailPath;
IMediaLibraryCb* m_callback;
DeviceListerPtr m_deviceLister;
......
......@@ -195,3 +195,7 @@ bool MediaLibraryTester::startThumbnailer()
{
return true;
}
void MediaLibraryTester::populateFsFactories()
{
}
......@@ -73,6 +73,7 @@ public:
std::pair<std::shared_ptr<Playlist>, unsigned int> parentPlaylist ) override;
sqlite::Connection* getDbConn();
virtual bool startThumbnailer();
virtual void populateFsFactories();
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