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

Album: Add sort by artist

Fix https://trac.videolan.org/vlc/ticket/16038
parent 8b296948
......@@ -66,6 +66,7 @@ enum class SortingCriteria
LastModificationDate,
ReleaseDate,
FileSize,
Artist,
};
class IMediaLibraryCb
......
......@@ -476,6 +476,17 @@ std::vector<AlbumPtr> Album::fromGenre( MediaLibraryPtr ml, int64_t genreId, Sor
std::vector<AlbumPtr> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc )
{
if ( sort == SortingCriteria::Artist )
{
std::string req = "SELECT alb.* FROM " + policy::AlbumTable::Name + " alb "
"INNER JOIN " + policy::ArtistTable::Name + " art ON alb.artist_id = art.id_artist "
"WHERE alb.is_present = 1 "
"ORDER BY art.name ";
if ( desc == true )
req += "DESC ";
req += ", alb.title";
return fetchAll<IAlbum>( ml, req );
}
std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE is_present=1";
req += orderBy( sort, desc );
......
......@@ -409,6 +409,34 @@ TEST_F( Albums, Sort )
ASSERT_EQ( a1->id(), albums[2]->id() );
}
TEST_F( Albums, SortByArtist )
{
auto artist1 = ml->createArtist( "Artist" );
auto artist2 = ml->createArtist( "tsitrA" );
// Create albums with a non-alphabetical order to avoid a false positive (where sorting by pkey
// is the same as sorting by title)
auto a1 = ml->createAlbum( "C" );
a1->setAlbumArtist( artist1 );
auto a2 = ml->createAlbum( "B" );
a2->setAlbumArtist( artist2 );
auto a3 = ml->createAlbum( "A" );
a3->setAlbumArtist( artist1 );
auto albums = ml->albums( SortingCriteria::Artist, false );
ASSERT_EQ( 3u, albums.size() );
ASSERT_EQ( a3->id(), albums[0]->id() );
ASSERT_EQ( a1->id(), albums[1]->id() );
ASSERT_EQ( a2->id(), albums[2]->id() );
albums = ml->albums( SortingCriteria::Artist, true );
ASSERT_EQ( 3u, albums.size() );
// We expect Artist to be sorted in reverse order, but still in alphabetical order for albums
ASSERT_EQ( a2->id(), albums[0]->id() );
ASSERT_EQ( a3->id(), albums[1]->id() );
ASSERT_EQ( a1->id(), albums[2]->id() );
}
TEST_F( Albums, Duration )
{
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