Commit 782b2be5 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Add a method to enable network discovery

parent d2bf5696
......@@ -220,6 +220,7 @@ class IMediaLibrary
* @param entryPoint What to discover.
*/
virtual void discover( const std::string& entryPoint ) = 0;
virtual void setDiscoverNetworkEnabled( bool enable ) = 0;
/**
* @brief banFolder will blacklist a folder for discovery
*/
......
......@@ -64,6 +64,7 @@
// FileSystem
#include "factory/DeviceListerFactory.h"
#include "factory/FileSystemFactory.h"
#include "factory/NetworkFileSystemFactory.h"
#include "filesystem/IDevice.h"
namespace medialibrary
......@@ -209,10 +210,7 @@ bool MediaLibrary::initialize( const std::string& dbPath, const std::string& thu
return false;
}
}
if ( m_fsFactories.empty() == true )
{
m_fsFactories.push_back( std::make_shared<factory::FileSystemFactory>( m_deviceLister ) );
}
addLocalFsFactory();
#ifdef _WIN32
if ( mkdir( thumbnailPath.c_str() ) != 0 )
#else
......@@ -593,6 +591,11 @@ void MediaLibrary::startDeletionNotifier()
m_modificationNotifier->start();
}
void MediaLibrary::addLocalFsFactory()
{
m_fsFactories.insert( begin( m_fsFactories ), std::make_shared<factory::FileSystemFactory>( m_deviceLister ) );
}
bool MediaLibrary::updateDatabaseModel( unsigned int previousVersion )
{
if ( previousVersion == 1 )
......@@ -677,6 +680,24 @@ void MediaLibrary::discover( const std::string &entryPoint )
m_discoverer->discover( entryPoint );
}
void MediaLibrary::setDiscoverNetworkEnabled( bool enabled )
{
if ( enabled )
{
auto it = std::find_if( begin( m_fsFactories ), end( m_fsFactories ), []( const std::shared_ptr<factory::IFileSystem> fs ) {
return fs->isNetworkFileSystem();
});
if ( it == end( m_fsFactories ) )
m_fsFactories.push_back( std::make_shared<factory::NetworkFileSystemFactory>( "smb", "dsm-sd" ) );
}
else
{
std::remove_if( begin( m_fsFactories ), end( m_fsFactories ), []( const std::shared_ptr<factory::IFileSystem> fs ) {
return fs->isNetworkFileSystem();
});
}
}
bool MediaLibrary::banFolder( const std::string& path )
{
return Folder::blacklist( this, path );
......
......@@ -114,6 +114,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual SearchAggregate search( const std::string& pattern ) const override;
virtual void discover( const std::string& entryPoint ) override;
virtual void setDiscoverNetworkEnabled( bool enabled ) override;
virtual bool banFolder( const std::string& path ) override;
virtual bool unbanFolder( const std::string& path ) override;
......@@ -149,6 +150,9 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
void registerEntityHooks();
static bool validateSearchPattern( const std::string& pattern );
protected:
virtual void addLocalFsFactory();
// Mark IDeviceListerCb callbacks as private. They must be invoked through the interface.
private:
virtual void onDevicePlugged(const std::string& uuid, const std::string& mountpoint) override;
......
......@@ -72,6 +72,19 @@ std::shared_ptr<Media> MediaLibraryTester::addFile( fs::IFile& file )
return MediaLibrary::addFile( file, dummyFolder, *dummyDirectory );
}
void MediaLibraryTester::addLocalFsFactory()
{
if ( fsFactory != nullptr )
{
m_fsFactories.clear();
m_fsFactories.push_back( fsFactory );
}
else
{
MediaLibrary::addLocalFsFactory();
}
}
std::shared_ptr<Playlist> MediaLibraryTester::playlist( int64_t playlistId )
{
return Playlist::fetch( this, playlistId );
......@@ -102,9 +115,9 @@ std::shared_ptr<Device> MediaLibraryTester::addDevice( const std::string& uuid,
return Device::create( this, uuid, isRemovable );
}
void MediaLibraryTester::setFsFactory(std::shared_ptr<factory::IFileSystem> fsFactory)
void MediaLibraryTester::setFsFactory( std::shared_ptr<factory::IFileSystem> fsf )
{
m_fsFactories.push_back( fsFactory );
fsFactory = fsf;
}
void MediaLibraryTester::deleteTrack( int64_t trackId )
......
......@@ -55,9 +55,11 @@ public:
void deleteTrack( int64_t trackId );
std::shared_ptr<AlbumTrack> albumTrack( int64_t id );
std::shared_ptr<Media> addFile(fs::IFile& file);
virtual void addLocalFsFactory() override;
private:
std::unique_ptr<fs::IDirectory> dummyDirectory;
std::shared_ptr<factory::IFileSystem> fsFactory;
Folder dummyFolder;
};
......
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