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

Media: add setFileName

parent efd23e7e
......@@ -578,6 +578,15 @@ void Media::setTitleBuffered( const std::string& title )
m_changed = true;
}
void Media::setFileName( std::string fileName )
{
if ( fileName == m_filename )
return;
static const std::string req = "UPDATE " + Media::Table::Name + " SET filename = ? WHERE id_media = ?";
sqlite::Tools::executeUpdate( m_ml->getConn(), req, fileName, m_id );
m_filename = std::move( fileName );
}
void Media::createTable( sqlite::Connection* connection )
{
std::string reqs[] = {
......
......@@ -76,6 +76,8 @@ class Media : public IMedia, public DatabaseHelpers<Media>
/// until save() is called
///
void setTitleBuffered( const std::string& title );
// Should only be used by 13->14 migration
void setFileName( std::string fileName );
virtual AlbumTrackPtr albumTrack() const override;
void setAlbumTrack( AlbumTrackPtr albumTrack );
virtual int64_t duration() const override;
......@@ -167,7 +169,7 @@ private:
std::string m_title;
// We store the filename as a shortcut when sorting. The filename (*not* the title
// might be used as a fallback
const std::string m_filename;
std::string m_filename;
bool m_isFavorite;
bool m_isPresent;
mutable std::atomic_uint m_nbPlaylists;
......
......@@ -806,6 +806,20 @@ TEST_F( Medias, SortByAlbum )
ASSERT_EQ( m3->id(), tracks[2]->id() );
}
TEST_F( Medias, SetFilename )
{
auto m = std::static_pointer_cast<Media>( ml->addMedia( "media.mkv" ) );
ASSERT_EQ( "media.mkv", m->fileName() );
m->setFileName( "sea_otter.asf" );
ASSERT_EQ( "sea_otter.asf", m->fileName() );
Reload();
m = ml->media( m->id() );
ASSERT_EQ( "sea_otter.asf", m->fileName() );
}
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