Commit 0e93d967 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

File: Expose a name

parent 599674e4
......@@ -24,6 +24,8 @@ class IFile
virtual unsigned int id() const = 0;
virtual Type type() = 0;
virtual bool setType( Type type ) = 0;
virtual const std::string& name() = 0;
virtual bool setName( const std::string& name ) = 0;
virtual AlbumTrackPtr albumTrack() = 0;
virtual bool setAlbumTrack(AlbumTrackPtr albumTrack ) = 0;
virtual unsigned int duration() const = 0;
......
......@@ -35,6 +35,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 9 );
m_snapshot = sqlite::Traits<std::string>::Load( stmt, 10 );
m_isParsed = sqlite::Traits<bool>::Load( stmt, 11 );
m_name = sqlite::Traits<std::string>::Load( stmt, 12 );
}
File::File( const fs::IFile* file, unsigned int folderId )
......@@ -52,6 +53,7 @@ File::File( const fs::IFile* file, unsigned int folderId )
{
}
//FIXME: Pass the guessed type and default name
FilePtr File::create( DBConnection dbConnection, const fs::IFile* file, unsigned int folderId )
{
auto self = std::make_shared<File>( file, folderId );
......@@ -266,6 +268,21 @@ bool File::setType( Type type )
return true;
}
const std::string &File::name()
{
return m_name;
}
bool File::setName( const std::string &name )
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET name = ? WHERE id_file = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, name, m_id ) == false )
return false;
m_name = name;
return true;
}
bool File::createTable( DBConnection connection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
......@@ -281,6 +298,7 @@ bool File::createTable( DBConnection connection )
"last_modification_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"parsed BOOLEAN,"
"name TEXT,"
"FOREIGN KEY (album_track_id) REFERENCES " + policy::AlbumTrackTable::Name
+ "(id_track) ON DELETE CASCADE,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
......
......@@ -48,6 +48,8 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual unsigned int id() const;
virtual Type type() override;
virtual bool setType( Type type ) override;
virtual const std::string& name() override;
virtual bool setName( const std::string& name ) override;
virtual AlbumTrackPtr albumTrack();
virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual unsigned int duration() const;
......@@ -91,6 +93,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
unsigned int m_lastModificationDate;
std::string m_snapshot;
bool m_isParsed;
std::string m_name;
// Auto fetched related properties
Album* m_album;
......
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