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

File: Allow duration to be set

parent 6f020c87
......@@ -27,6 +27,7 @@ class IFile
virtual AlbumTrackPtr albumTrack() = 0;
virtual bool setAlbumTrack(AlbumTrackPtr albumTrack ) = 0;
virtual unsigned int duration() const = 0;
virtual bool setDuration( unsigned int duration) = 0;
virtual std::shared_ptr<IShowEpisode> showEpisode() = 0;
virtual bool setShowEpisode( ShowEpisodePtr showEpisode ) = 0;
virtual int playCount() const = 0;
......
......@@ -88,6 +88,16 @@ unsigned int File::duration() const
return m_duration;
}
bool File::setDuration( unsigned int duration )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET duration = ? "
"WHERE id_file = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, duration, m_id ) == false )
return false;
m_duration = duration;
return true;
}
std::shared_ptr<IShowEpisode> File::showEpisode()
{
if ( m_showEpisode == nullptr && m_showEpisodeId != 0 )
......
......@@ -49,6 +49,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual AlbumTrackPtr albumTrack();
virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual unsigned int duration() const;
virtual bool setDuration( unsigned int duration) override;
virtual std::shared_ptr<IShowEpisode> showEpisode();
virtual bool setShowEpisode( ShowEpisodePtr showEpisode );
virtual bool addLabel( LabelPtr label );
......
......@@ -76,3 +76,17 @@ TEST_F( Files, LastModificationDate )
auto f2 = ml->file( "/dev/seaotter" );
ASSERT_EQ( f->lastModificationDate(), f2->lastModificationDate() );
}
TEST_F( Files, Duration )
{
auto f = ml->addFile( "/some/file" );
ASSERT_EQ( f->duration(), 0u );
f->setDuration( 123u );
ASSERT_EQ( f->duration(), 123u );
Reload();
f = ml->file( "/some/file" );
ASSERT_EQ( f->duration(), 123u );
}
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