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

Album: Provide a getter for the associated thumbnail object

parent e6306f36
......@@ -151,6 +151,21 @@ const std::string& Album::artworkMrl() const
return m_thumbnail.get()->mrl();
}
std::shared_ptr<Thumbnail> Album::thumbnail()
{
if ( m_thumbnailId == 0 )
return nullptr;
auto lock = m_thumbnail.lock();
if ( m_thumbnail.isCached() == false )
{
auto thumbnail = Thumbnail::fetch( m_ml, m_thumbnailId );
if ( thumbnail == nullptr )
return nullptr;
m_thumbnail = std::move( thumbnail );
}
return m_thumbnail.get();
}
bool Album::setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin )
{
if ( m_thumbnailId != 0 )
......
......@@ -74,6 +74,7 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
virtual const std::string& shortSummary() const override;
bool setShortSummary( const std::string& summary );
virtual const std::string& artworkMrl() const override;
std::shared_ptr<Thumbnail> thumbnail();
bool setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin );
virtual std::vector<MediaPtr> tracks( SortingCriteria sort, bool desc ) const override;
virtual std::vector<MediaPtr> tracks( GenrePtr genre, SortingCriteria sort, bool desc ) const override;
......
......@@ -178,6 +178,28 @@ TEST_F( Albums, SetArtworkMrl )
ASSERT_EQ( a->artworkMrl(), a2->artworkMrl() );
}
TEST_F( Albums, Thumbnail )
{
auto a = ml->createAlbum( "album" );
auto t = a->thumbnail();
ASSERT_EQ( nullptr, t );
std::string mrl = "/path/to/sea/otter/artwork.png";
auto res = a->setArtworkMrl( mrl, Thumbnail::Origin::UserProvided );
ASSERT_TRUE( res );
t = a->thumbnail();
ASSERT_NE( nullptr, t );
ASSERT_EQ( mrl, t->mrl() );
Reload();
a = std::static_pointer_cast<Album>( ml->album( a->id() ) );
t = a->thumbnail();
ASSERT_NE( nullptr, t );
ASSERT_EQ( mrl, t->mrl() );
}
TEST_F( Albums, FetchAlbumFromTrack )
{
auto a = ml->createAlbum( "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