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

Artist: Add a getter for the associated thumbnail object

parent 2f8837e6
......@@ -166,6 +166,21 @@ const std::string& Artist::artworkMrl() const
return m_thumbnail.get()->mrl();
}
std::shared_ptr<Thumbnail> Artist::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 Artist::setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin )
{
if ( m_thumbnailId != 0 )
......
......@@ -59,6 +59,7 @@ public:
virtual std::vector<MediaPtr> media(SortingCriteria sort, bool desc) const override;
bool addMedia( Media& media );
virtual const std::string& artworkMrl() const override;
std::shared_ptr<Thumbnail> thumbnail();
bool setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin );
bool updateNbAlbum( int increment );
bool updateNbTrack( int increment );
......
......@@ -92,6 +92,28 @@ TEST_F( Artists, ArtworkMrl )
ASSERT_EQ( a2->artworkMrl(), artwork );
}
TEST_F( Artists, Thumbnail )
{
auto a = ml->createArtist( "artist" );
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<Artist>( ml->artist( a->id() ) );
t = a->thumbnail();
ASSERT_NE( nullptr, t );
ASSERT_EQ( mrl, t->mrl() );
}
// Test the number of albums based on the artist tracks
TEST_F( Artists, Albums )
{
......
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