Commit 9a461fa6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Store thumbnails to a user defined location

parent ae90cfa7
...@@ -40,7 +40,7 @@ class IMediaLibrary : public IDiscovererCb ...@@ -40,7 +40,7 @@ class IMediaLibrary : public IDiscovererCb
/// \param dbPath Path to the database /// \param dbPath Path to the database
/// \return true in case of success, false otherwise /// \return true in case of success, false otherwise
/// ///
virtual bool initialize( const std::string& dbPath, std::shared_ptr<factory::IFileSystem> fsFactory ) = 0; virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory ) = 0;
/// Adds a stand alone file /// Adds a stand alone file
virtual FilePtr addFile( const std::string& path ) = 0; virtual FilePtr addFile( const std::string& path ) = 0;
virtual FilePtr file( const std::string& path ) = 0; virtual FilePtr file( const std::string& path ) = 0;
...@@ -81,6 +81,7 @@ class IMediaLibrary : public IDiscovererCb ...@@ -81,6 +81,7 @@ class IMediaLibrary : public IDiscovererCb
* @param entryPoint What to discover. * @param entryPoint What to discover.
*/ */
virtual void discover( const std::string& entryPoint ) = 0; virtual void discover( const std::string& entryPoint ) = 0;
virtual const std::string& snapshotPath() const = 0;
}; };
class MediaLibraryFactory class MediaLibraryFactory
......
...@@ -56,12 +56,13 @@ MediaLibrary::~MediaLibrary() ...@@ -56,12 +56,13 @@ MediaLibrary::~MediaLibrary()
AudioTrack::clear(); AudioTrack::clear();
} }
bool MediaLibrary::initialize( const std::string& dbPath, std::shared_ptr<factory::IFileSystem> fsFactory ) bool MediaLibrary::initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory )
{ {
if ( fsFactory != nullptr ) if ( fsFactory != nullptr )
m_fsFactory = fsFactory; m_fsFactory = fsFactory;
else else
m_fsFactory.reset( new factory::FileSystemDefaultFactory ); m_fsFactory.reset( new factory::FileSystemDefaultFactory );
m_snapshotPath = snapshotPath;
sqlite3* dbConnection; sqlite3* dbConnection;
int res = sqlite3_open( dbPath.c_str(), &dbConnection ); int res = sqlite3_open( dbPath.c_str(), &dbConnection );
...@@ -224,6 +225,11 @@ FilePtr MediaLibrary::onNewFile( const fs::IFile *file, FolderPtr parent ) ...@@ -224,6 +225,11 @@ FilePtr MediaLibrary::onNewFile( const fs::IFile *file, FolderPtr parent )
return addFile( file, parent == nullptr ? 0 : parent->id() ); return addFile( file, parent == nullptr ? 0 : parent->id() );
} }
const std::string& MediaLibrary::snapshotPath() const
{
return m_snapshotPath;
}
bool MediaLibrary::loadFolders() bool MediaLibrary::loadFolders()
{ {
//FIXME: This should probably be in a sql transaction //FIXME: This should probably be in a sql transaction
......
...@@ -13,7 +13,7 @@ class MediaLibrary : public IMediaLibrary ...@@ -13,7 +13,7 @@ class MediaLibrary : public IMediaLibrary
public: public:
MediaLibrary(); MediaLibrary();
~MediaLibrary(); ~MediaLibrary();
virtual bool initialize( const std::string& dbPath, std::shared_ptr<factory::IFileSystem> fsFactory ); virtual bool initialize( const std::string& dbPath, const std::string& snapshotPath, std::shared_ptr<factory::IFileSystem> fsFactory );
virtual std::vector<FilePtr> files(); virtual std::vector<FilePtr> files();
virtual FilePtr file( const std::string& path ); virtual FilePtr file( const std::string& path );
...@@ -46,6 +46,8 @@ class MediaLibrary : public IMediaLibrary ...@@ -46,6 +46,8 @@ class MediaLibrary : public IMediaLibrary
virtual FolderPtr onNewFolder( const fs::IDirectory* directory, FolderPtr parent ) override; virtual FolderPtr onNewFolder( const fs::IDirectory* directory, FolderPtr parent ) override;
virtual FilePtr onNewFile(const fs::IFile* file, FolderPtr parent ) override; virtual FilePtr onNewFile(const fs::IFile* file, FolderPtr parent ) override;
virtual const std::string& snapshotPath() const override;
private: private:
static const std::vector<std::string> supportedExtensions; static const std::vector<std::string> supportedExtensions;
...@@ -57,8 +59,15 @@ class MediaLibrary : public IMediaLibrary ...@@ -57,8 +59,15 @@ class MediaLibrary : public IMediaLibrary
private: private:
std::shared_ptr<sqlite3> m_dbConnection; std::shared_ptr<sqlite3> m_dbConnection;
std::unique_ptr<Parser> m_parser;
std::shared_ptr<factory::IFileSystem> m_fsFactory; std::shared_ptr<factory::IFileSystem> m_fsFactory;
std::vector<std::unique_ptr<IDiscoverer>> m_discoverers; std::vector<std::unique_ptr<IDiscoverer>> m_discoverers;
std::string m_snapshotPath;
// Keep the parser as last field.
// The parser holds a (raw) pointer to the media library. When MediaLibrary's destructor gets called
// it might still finish a few operations before exiting the parser thread. Those operations are
// likely to require a valid MediaLibrary, which would be compromised if some fields have already been
// deleted/destroyed.
std::unique_ptr<Parser> m_parser;
}; };
#endif // MEDIALIBRARY_H #endif // MEDIALIBRARY_H
...@@ -53,7 +53,9 @@ bool VLCThumbnailer::run( FilePtr file, void *data ) ...@@ -53,7 +53,9 @@ bool VLCThumbnailer::run( FilePtr file, void *data )
if ( seekAhead( file, mp, data ) == false ) if ( seekAhead( file, mp, data ) == false )
return false; return false;
std::string path( "/tmp/test.jpg" ); auto path = m_ml->snapshotPath();
path += "/";
path += std::to_string( file->id() ) + ".jpg";
if ( mp.takeSnapshot( 0, path, 320, 240 ) == false ) if ( mp.takeSnapshot( 0, path, 320, 240 ) == false )
{ {
m_cb->done( file, StatusError, data ); m_cb->done( file, StatusError, data );
......
...@@ -37,7 +37,7 @@ void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /* = nullptr */ ) ...@@ -37,7 +37,7 @@ void Tests::Reload(std::shared_ptr<factory::IFileSystem> fs /* = nullptr */ )
{ {
fs = std::shared_ptr<factory::IFileSystem>( new mock::NoopFsFactory ); fs = std::shared_ptr<factory::IFileSystem>( new mock::NoopFsFactory );
} }
bool res = ml->initialize( "test.db", fs ); bool res = ml->initialize( "test.db", "/tmp", fs );
ASSERT_TRUE( res ); ASSERT_TRUE( res );
} }
......
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