Commit 8e6f99eb authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

File: Add snapshot()/setSnapshot methods

parent b176f343
......@@ -43,6 +43,10 @@ class IFile
virtual bool addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels ) = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
// Returns the location of this file snapshot.
// This is likely to be used for album arts as well.
virtual const std::string& snapshot() = 0;
virtual bool setSnapshot( const std::string& snapshot ) = 0;
/// Returns wether the file has been added as a stand alone file (true), or as
/// part of a folder (false)
virtual bool isStandAlone() = 0;
......
......@@ -32,6 +32,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_movieId = sqlite::Traits<unsigned int>::Load( stmt, 7 );
m_folderId = sqlite::Traits<unsigned int>::Load( stmt, 8 );
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 9 );
m_snapshot = sqlite::Traits<std::string>::Load( stmt, 10 );
m_isReady = m_type != UnknownType;
}
......@@ -201,6 +202,21 @@ std::vector<AudioTrackPtr> File::audioTracks()
return sqlite::Tools::fetchAll<AudioTrack, IAudioTrack>( m_dbConnection, req, m_id );
}
const std::string &File::snapshot()
{
return m_snapshot;
}
bool File::setSnapshot(const std::string &snapshot)
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET snapshot = ? WHERE id_file = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, snapshot, m_id ) == false )
return false;
m_snapshot = snapshot;
return true;
}
bool File::isStandAlone()
{
return m_folderId == 0;
......@@ -240,6 +256,7 @@ bool File::createTable( DBConnection connection )
"movie_id UNSIGNED INTEGER,"
"folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"FOREIGN KEY (album_track_id) REFERENCES " + policy::AlbumTrackTable::Name
+ "(id_track) ON DELETE CASCADE,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
......
......@@ -64,6 +64,9 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual std::vector<VideoTrackPtr> videoTracks();
virtual bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
virtual std::vector<AudioTrackPtr> audioTracks();
virtual const std::string& snapshot() override;
virtual bool setSnapshot( const std::string& snapshot ) override;
virtual bool isStandAlone() override;
virtual unsigned int lastModificationDate() override;
......@@ -84,6 +87,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
unsigned int m_movieId;
unsigned int m_folderId;
unsigned int m_lastModificationDate;
std::string m_snapshot;
// Auto fetched related properties
Album* m_album;
......
......@@ -90,3 +90,19 @@ TEST_F( Files, Duration )
f = ml->file( "/some/file" );
ASSERT_EQ( f->duration(), 123u );
}
TEST_F( Files, Snapshot )
{
auto f = ml->addFile( "/some/file" );
ASSERT_EQ( f->snapshot(), "" );
std::string newSnapshot( "/path/to/snapshot" );
f->setSnapshot( newSnapshot );
ASSERT_EQ( f->snapshot(), newSnapshot );
Reload();
f = ml->file( "/some/file" );
ASSERT_EQ( f->snapshot(), newSnapshot );
}
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