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

Media: Expose a setTitle method

parent 86fe8b41
......@@ -96,6 +96,7 @@ class IMedia
virtual Type type() = 0;
virtual SubType subType() const = 0;
virtual const std::string& title() const = 0;
virtual bool setTitle( const std::string& title ) = 0;
virtual AlbumTrackPtr albumTrack() const = 0;
/**
* @brief duration Returns the media duration in ms
......
......@@ -459,6 +459,17 @@ const std::string &Media::title() const
return m_title;
}
bool Media::setTitle( const std::string& title )
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET title = ? WHERE id_media = ?";
if ( m_title == title )
return true;
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, title, m_id ) == false )
return false;
m_title = title;
return true;
}
void Media::setTitleBuffered( const std::string &title )
{
if ( m_title == title )
......
......@@ -91,6 +91,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual SubType subType() const override;
void setType( Type type );
virtual const std::string& title() const override;
virtual bool setTitle( const std::string& title ) override;
///
/// \brief setTitleBuffered Mark the media as changed but doesn't save the change in DB
/// Querying the title after this method will return the new title, but it won't appear in DB
......
......@@ -518,6 +518,20 @@ TEST_F( Medias, DuplicatedExternalMrl )
ASSERT_EQ( nullptr, m2 );
}
TEST_F( Medias, SetTitle )
{
auto m = ml->addMedia( "media" );
ASSERT_EQ( "media", m->title() );
auto res = m->setTitle( "sea otters" );
ASSERT_TRUE( res );
ASSERT_EQ( "sea otters", m->title() );
Reload();
m = ml->media( m->id() );
ASSERT_EQ( "sea otters", m->title() );
}
class FetchMedia : public Tests
{
protected:
......
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