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

Artist: Expose an UnknownAlbum for each artist

parent 4932a6e4
......@@ -56,6 +56,16 @@ Album::Album(const std::string& title )
{
}
Album::Album( const Artist* artist )
: m_id( 0 )
, m_artistId( artist->id() )
, m_releaseYear( ~0u )
, m_lastSyncDate( 0 )
, m_nbTracks( 0 )
, m_tracksCached( false )
{
}
unsigned int Album::id() const
{
return m_id;
......@@ -258,3 +268,14 @@ std::shared_ptr<Album> Album::create(DBConnection dbConnection, const std::strin
album->m_dbConnection = dbConnection;
return album;
}
std::shared_ptr<Album> Album::createUnknownAlbum( DBConnection dbConnection, const Artist* artist )
{
auto album = std::make_shared<Album>( artist );
static const std::string req = "INSERT INTO " + policy::AlbumTable::Name +
"(id_album, artist_id) VALUES(NULL, ?)";
if ( _Cache::insert( dbConnection, album, req, artist->id() ) == false )
return nullptr;
album->m_dbConnection = dbConnection;
return album;
}
......@@ -54,6 +54,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
public:
Album( DBConnection dbConnection, sqlite::Row& row );
Album( const std::string& title );
Album( const Artist* artist );
virtual unsigned int id() const override;
virtual const std::string& title() const override;
......@@ -85,6 +86,7 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<Album> create(DBConnection dbConnection, const std::string& title );
static std::shared_ptr<Album> createUnknownAlbum( DBConnection dbConnection, const Artist* artist );
protected:
DBConnection m_dbConnection;
......
......@@ -141,6 +141,18 @@ bool Artist::updateNbAlbum( int increment )
return true;
}
std::shared_ptr<Album> Artist::unknownAlbum()
{
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE artist_id = ? AND title IS NULL";
auto album = Album::fetchOne( m_dbConnection, req, m_id );
if ( album == nullptr )
{
album = Album::createUnknownAlbum( m_dbConnection, this );
}
return album;
}
bool Artist::createTable( DBConnection dbConnection )
{
static const std::string req = "CREATE TABLE IF NOT EXISTS " +
......
......@@ -27,6 +27,7 @@
#include "IMediaLibrary.h"
class Artist;
class Album;
class Media;
namespace policy
......@@ -58,6 +59,7 @@ public:
virtual const std::string& artworkUrl() const override;
bool setArtworkUrl( const std::string& artworkUrl );
bool updateNbAlbum( int increment );
std::shared_ptr<Album> unknownAlbum();
static bool createTable( DBConnection dbConnection );
static bool createDefaultArtists( DBConnection dbConnection );
......
......@@ -185,7 +185,6 @@ bool VLCMetadataService::parseAudioFile( std::shared_ptr<Media> media, VLC::Medi
}
/* Album handling */
std::shared_ptr<Album> VLCMetadataService::findAlbum( Media* media, const std::string& title, Artist* albumArtist ) const
{
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
......
......@@ -155,3 +155,21 @@ TEST_F( Artists, GetAll )
auto artists2 = ml->artists();
ASSERT_EQ( artists2.size(), 5u );
}
TEST_F( Artists, UnknownAlbum )
{
auto a = ml->createArtist( "Explotters in the sky" );
auto album = a->unknownAlbum();
auto album2 = a->unknownAlbum();
ASSERT_NE( nullptr, album );
ASSERT_NE( nullptr, album2 );
ASSERT_EQ( album->id(), album2->id() );
Reload();
a = std::static_pointer_cast<Artist>( ml->artist( a->name() ) );
album2 = a->unknownAlbum();
ASSERT_NE( nullptr, album2 );
ASSERT_EQ( album2->id(), album->id() );
}
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