Commit 96ee0676 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IFile: Expose type & allow addFile to specify the file type

parent c698bb30
......@@ -43,11 +43,11 @@ File::File( DBConnection dbConnection, sqlite::Row& row )
>> m_isRemovable;
}
File::File( unsigned int mediaId, const fs::IFile& file, unsigned int folderId, bool isRemovable )
File::File( unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable )
: m_id( 0 )
, m_mediaId( mediaId )
, m_mrl( isRemovable == true ? file.name() : file.fullPath() )
, m_type( Type::Unknown )
, m_type( type )
, m_lastModificationDate( file.lastModificationDate() )
, m_isParsed( false )
, m_folderId( folderId )
......@@ -143,13 +143,13 @@ bool File::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, triggerReq );
}
std::shared_ptr<File> File::create( DBConnection dbConnection, unsigned int mediaId, const fs::IFile& fileFs, unsigned int folderId, bool isRemovable )
std::shared_ptr<File> File::create( DBConnection dbConnection, unsigned int mediaId, Type type, const fs::IFile& fileFs, unsigned int folderId, bool isRemovable )
{
auto self = std::make_shared<File>( mediaId, fileFs, folderId, isRemovable );
auto self = std::make_shared<File>( mediaId, type, fileFs, folderId, isRemovable );
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
"(media_id, mrl, folder_id, last_modification_date, is_removable) VALUES(?, ?, ?, ?, ?)";
"(media_id, mrl, type, folder_id, last_modification_date, is_removable) VALUES(?, ?, ?, ?, ?, ?)";
if ( insert( dbConnection, self, req, mediaId, self->m_mrl, sqlite::ForeignKey( folderId ),
if ( insert( dbConnection, self, req, mediaId, self->m_mrl, type, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, isRemovable ) == false )
return nullptr;
self->m_dbConnection = dbConnection;
......
......@@ -45,7 +45,7 @@ class File : public IFile, public DatabaseHelpers<File, policy::FileTable>
{
public:
File( DBConnection dbConnection, sqlite::Row& row );
File(unsigned int mediaId, const fs::IFile& file, unsigned int folderId, bool isRemovable );
File( unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable );
virtual unsigned int id() const override;
virtual const std::string& mrl() const override;
virtual Type type() const override;
......@@ -59,7 +59,7 @@ public:
bool destroy();
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<File> create(DBConnection dbConnection, unsigned int mediaId, const fs::IFile& file, unsigned int folderId, bool isRemovable );
static std::shared_ptr<File> create( DBConnection dbConnection, unsigned int mediaId, Type type, const fs::IFile& file, unsigned int folderId, bool isRemovable );
private:
unsigned int m_id;
......
......@@ -271,9 +271,9 @@ bool Media::save()
return true;
}
std::shared_ptr<File> Media::addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs )
std::shared_ptr<File> Media::addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs, IFile::Type type )
{
auto file = File::create( m_dbConnection, m_id, fileFs, parentFolder.id(), parentFolderFs.device()->isRemovable() );
auto file = File::create( m_dbConnection, m_id, type, fileFs, parentFolder.id(), parentFolderFs.device()->isRemovable() );
if ( file == nullptr )
return nullptr;
auto lock = m_files.lock();
......
......@@ -27,11 +27,11 @@
#include <sqlite3.h>
#include "IMedia.h"
#include "File.h"
#include "database/DatabaseHelpers.h"
#include "utils/Cache.h"
class Album;
class File;
class Folder;
class ShowEpisode;
class AlbumTrack;
......@@ -104,7 +104,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
void setThumbnail( const std::string& thumbnail );
bool save();
std::shared_ptr<File> addFile( const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs );
std::shared_ptr<File> addFile(const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs , IFile::Type type);
void removeFile( File& file );
private:
......
......@@ -234,7 +234,8 @@ std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder& p
LOG_ERROR( "Failed to add media ", fileFs->fullPath(), " to the media library" );
return nullptr;
}
auto file = mptr->addFile( *fileFs, parentFolder, parentFolderFs );
// For now, assume all media are made of a single file
auto file = mptr->addFile( *fileFs, parentFolder, parentFolderFs, File::Type::Entire );
if ( file == nullptr )
{
LOG_ERROR( "Failed to add file ", fileFs->fullPath(), " to media #", mptr->id() );
......
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