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

Specify thumbnail origins when setting those

parent 3c9ce59e
......@@ -151,11 +151,11 @@ const std::string& Album::artworkMrl() const
return m_thumbnail.get()->mrl();
}
bool Album::setArtworkMrl( const std::string& artworkMrl )
bool Album::setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin )
{
if ( m_thumbnailId != 0 )
return Thumbnail::setMrlFromPrimaryKey( m_ml, m_thumbnail, m_thumbnailId,
artworkMrl );
artworkMrl, origin );
std::unique_ptr<sqlite::Transaction> t;
if ( sqlite::Transaction::transactionInProgress() == false )
......
......@@ -31,6 +31,7 @@
#include "database/DatabaseHelpers.h"
#include "medialibrary/IAlbum.h"
#include "utils/Cache.h"
#include "Thumbnail.h"
namespace medialibrary
{
......@@ -39,7 +40,6 @@ class Album;
class AlbumTrack;
class Artist;
class Media;
class Thumbnail;
namespace policy
{
......@@ -74,7 +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;
bool setArtworkMrl( const std::string& artworkMrl );
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;
///
......
......@@ -166,11 +166,11 @@ const std::string& Artist::artworkMrl() const
return m_thumbnail.get()->mrl();
}
bool Artist::setArtworkMrl( const std::string& artworkMrl )
bool Artist::setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin )
{
if ( m_thumbnailId != 0 )
return Thumbnail::setMrlFromPrimaryKey( m_ml, m_thumbnail, m_thumbnailId,
artworkMrl );
artworkMrl, origin );
std::unique_ptr<sqlite::Transaction> t;
if ( sqlite::Transaction::transactionInProgress() == false )
......
......@@ -26,6 +26,7 @@
#include "medialibrary/IArtist.h"
#include "medialibrary/IMediaLibrary.h"
#include "utils/Cache.h"
#include "Thumbnail.h"
namespace medialibrary
{
......@@ -33,7 +34,6 @@ namespace medialibrary
class Artist;
class Album;
class Media;
class Thumbnail;
namespace policy
{
......@@ -59,7 +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;
bool setArtworkMrl( const std::string& artworkMrl );
bool setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin );
bool updateNbAlbum( int increment );
bool updateNbTrack( int increment );
std::shared_ptr<Album> unknownAlbum();
......
......@@ -374,7 +374,7 @@ bool Media::setThumbnail( const std::string& thumbnailMrl, Thumbnail::Origin ori
{
if ( m_thumbnailId != 0 )
return Thumbnail::setMrlFromPrimaryKey( m_ml, m_thumbnail, m_thumbnailId,
thumbnailMrl );
thumbnailMrl, origin );
std::unique_ptr<sqlite::Transaction> t;
if ( sqlite::Transaction::transactionInProgress() == false )
......
......@@ -39,7 +39,8 @@ int64_t Thumbnail::*const ThumbnailTable::PrimaryKey = &Thumbnail::m_id;
const std::string Thumbnail::EmptyMrl;
Thumbnail::Thumbnail(MediaLibraryPtr ml, sqlite::Row& row)
Thumbnail::Thumbnail( MediaLibraryPtr ml, sqlite::Row& row )
: m_ml( ml )
{
row >> m_id
>> m_mrl
......@@ -64,15 +65,16 @@ const std::string& Thumbnail::mrl() const
return m_mrl;
}
bool Thumbnail::update( std::string mrl )
bool Thumbnail::update( std::string mrl, Origin origin )
{
if ( m_mrl == mrl )
if ( m_mrl == mrl && m_origin == origin )
return true;
static const std::string req = "UPDATE " + policy::ThumbnailTable::Name +
" SET mrl = ? WHERE id_thumbnail = ?";
if( sqlite::Tools::executeUpdate( m_ml->getConn(), req, mrl, m_id ) == false )
" SET mrl = ?, origin = ? WHERE id_thumbnail = ?";
if( sqlite::Tools::executeUpdate( m_ml->getConn(), req, mrl, origin, m_id ) == false )
return false;
m_mrl = std::move( mrl );
m_origin = origin;
return true;
}
......@@ -83,7 +85,8 @@ Thumbnail::Origin Thumbnail::origin() const
bool Thumbnail::setMrlFromPrimaryKey( MediaLibraryPtr ml,
Cache<std::shared_ptr<Thumbnail>>& thumbnail,
int64_t thumbnailId, std::string mrl )
int64_t thumbnailId, std::string mrl,
Origin origin )
{
auto lock = thumbnail.lock();
if ( thumbnail.isCached() == false )
......@@ -95,7 +98,7 @@ bool Thumbnail::setMrlFromPrimaryKey( MediaLibraryPtr ml,
return false;
}
}
return thumbnail.get()->update( std::move( mrl ) );
return thumbnail.get()->update( std::move( mrl ), origin );
}
void Thumbnail::createTable( sqlite::Connection* dbConnection )
......
......@@ -59,7 +59,7 @@ public:
int64_t id() const;
const std::string& mrl() const;
bool update( std::string mrl );
bool update( std::string mrl, Origin origin );
Origin origin() const;
/**
......@@ -71,7 +71,8 @@ public:
*/
static bool setMrlFromPrimaryKey( MediaLibraryPtr ml,
Cache<std::shared_ptr<Thumbnail>>& thumbnail,
int64_t thumbnailId, std::string mrl );
int64_t thumbnailId, std::string mrl,
Origin origin );
static void createTable( sqlite::Connection* dbConnection );
static std::shared_ptr<Thumbnail> create( MediaLibraryPtr ml, std::string mrl,
......
......@@ -718,7 +718,7 @@ bool MetadataParser::link( Media& media, std::shared_ptr<Album> album,
albumArtist->id() != VariousArtistID &&
albumArtist->artworkMrl().empty() == true &&
album != nullptr && album->artworkMrl().empty() == false )
albumArtist->setArtworkMrl( album->artworkMrl() );
albumArtist->setArtworkMrl( album->artworkMrl(), Thumbnail::Origin::Album );
// Until we have a better artwork extraction/assignation, simply do the same
// for artists
......@@ -726,7 +726,7 @@ bool MetadataParser::link( Media& media, std::shared_ptr<Album> album,
artist->id() != VariousArtistID &&
artist->artworkMrl().empty() == true &&
album != nullptr && album->artworkMrl().empty() == false )
artist->setArtworkMrl( album->artworkMrl() );
artist->setArtworkMrl( album->artworkMrl(), Thumbnail::Origin::Album );
if ( albumArtist != nullptr )
albumArtist->addMedia( media );
......
......@@ -169,7 +169,7 @@ TEST_F( Albums, SetArtworkMrl )
{
auto a = ml->createAlbum( "album" );
a->setArtworkMrl( "artwork" );
a->setArtworkMrl( "artwork", Thumbnail::Origin::UserProvided );
ASSERT_EQ( a->artworkMrl(), "artwork" );
Reload();
......
......@@ -82,7 +82,7 @@ TEST_F( Artists, ArtworkMrl )
ASSERT_EQ( a->artworkMrl(), "" );
std::string artwork("/tmp/otter.png");
a->setArtworkMrl( artwork );
a->setArtworkMrl( artwork, Thumbnail::Origin::UserProvided );
ASSERT_EQ( a->artworkMrl(), artwork );
Reload();
......
......@@ -64,14 +64,28 @@ TEST_F( Thumbnails, Update )
std::string mrl = "/path/to/thumbnail.png";
auto t = Thumbnail::create( ml.get(), mrl, Thumbnail::Origin::UserProvided );
ASSERT_EQ( t->mrl(), mrl );
ASSERT_EQ( t->origin(), Thumbnail::Origin::UserProvided );
mrl = "/better/thumbnail.gif";
auto res = t->update( mrl );
auto res = t->update( mrl, Thumbnail::Origin::UserProvided );
ASSERT_TRUE( res );
ASSERT_EQ( t->mrl(), mrl );
ASSERT_EQ( t->origin(), Thumbnail::Origin::UserProvided );
Reload();
t = Thumbnail::fetch( ml.get(), t->id() );
ASSERT_EQ( t->mrl(), mrl );
ASSERT_EQ( t->origin(), Thumbnail::Origin::UserProvided );
res = t->update( mrl, Thumbnail::Origin::AlbumArtist );
ASSERT_TRUE( res );
ASSERT_EQ( t->mrl(), mrl );
ASSERT_EQ( t->origin(), Thumbnail::Origin::AlbumArtist );
Reload();
t = Thumbnail::fetch( ml.get(), t->id() );
ASSERT_EQ( t->mrl(), mrl );
ASSERT_EQ( t->origin(), Thumbnail::Origin::AlbumArtist );
}
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