Commit 6dc49920 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Add an isIndexed helper

To simplify checking for the indexed state of an mrl
parent 3352c4ef
Pipeline #3089 passed with stages
in 12 minutes and 53 seconds
......@@ -396,6 +396,13 @@ class IMediaLibrary
*/
virtual bool setDiscoverNetworkEnabled( bool enable ) = 0;
virtual Query<IFolder> entryPoints() const = 0;
/**
* @brief isIndexed Returns true if the mrl point to a file of folder in an
* indexed entrypoint
* @param mrl The MRL to probe
* @return true if the mrl is indexed, false otherwise
*/
virtual bool isIndexed( const std::string& mrl ) const = 0;
/**
* @brief folders Returns a flattened list of all folders containing at least a media
* @param params A query parameters object
......
......@@ -1409,6 +1409,13 @@ Query<IFolder> MediaLibrary::entryPoints() const
return make_query<Folder, IFolder>( this, "*", req, "" );
}
bool MediaLibrary::isIndexed( const std::string& mrl ) const
{
auto folderMrl = utils::file::directory( mrl );
auto folder = Folder::fromMrl( this, folderMrl );
return folder != nullptr;
}
Query<IFolder> MediaLibrary::folders( const QueryParameters* params ) const
{
return Folder::withMedia( this, params );
......
......@@ -144,6 +144,7 @@ class MediaLibrary : public IMediaLibrary
virtual void discover( const std::string& entryPoint ) override;
virtual bool setDiscoverNetworkEnabled( bool enabled ) override;
virtual Query<IFolder> entryPoints() const override;
virtual bool isIndexed( const std::string& mrl ) const override;
virtual Query<IFolder> folders( const QueryParameters* params = nullptr ) const override;
virtual Query<IFolder> searchFolders( const std::string& pattern,
const QueryParameters* params ) const override;
......
......@@ -476,6 +476,53 @@ TEST_F( Folders, NbMedia )
ASSERT_EQ( 0u, subFolder->media( IMedia::Type::Unknown, nullptr )->count() );
}
TEST_F( Folders, IsIndexed )
{
// Check with a couple of indexed folders
auto res = ml->isIndexed( mock::FileSystemFactory::Root );
ASSERT_TRUE( res );
res = ml->isIndexed( mock::FileSystemFactory::SubFolder );
ASSERT_TRUE( res );
// Check with a random non-indexed folder
res = ml->isIndexed( "file:///path/to/another/folder" );
ASSERT_FALSE( res );
// Check with a file
res = ml->isIndexed( mock::FileSystemFactory::Root + "video.avi" );
ASSERT_TRUE( res );
}
TEST_F( FoldersNoDiscover, IsIndexed )
{
// The previous test checks for a non-existing folder. This time, try with
// an existing folder that wasn't indexed
ml->discover( mock::FileSystemFactory::SubFolder );
bool discovered = cbMock->waitDiscovery();
ASSERT_TRUE( discovered );
auto res = ml->isIndexed( mock::FileSystemFactory::Root );
ASSERT_FALSE( res );
res = ml->isIndexed( mock::FileSystemFactory::SubFolder );
ASSERT_TRUE( res );
}
TEST_F( FoldersNoDiscover, IsBannedFolderIndexed )
{
ml->banFolder( mock::FileSystemFactory::SubFolder );
cbMock->waitBanFolder();
ml->discover( mock::FileSystemFactory::Root );
bool discovered = cbMock->waitDiscovery();
ASSERT_TRUE( discovered );
auto res = ml->isIndexed( mock::FileSystemFactory::Root );
ASSERT_TRUE( res );
res = ml->isIndexed( mock::FileSystemFactory::SubFolder );
ASSERT_FALSE( res );
ml->unbanFolder( mock::FileSystemFactory::SubFolder );
cbMock->waitUnbanFolder();
cbMock->waitReload();
res = ml->isIndexed( mock::FileSystemFactory::SubFolder );
ASSERT_TRUE( res );
}
TEST_F( FoldersNoDiscover, ListWithMedia )
{
auto newFolder = mock::FileSystemFactory::Root + "empty/";
......
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