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

Use a QueryParameter object instead of individual sort & desc parameters

parent b5a23750
......@@ -44,13 +44,13 @@ public:
/**
* @brief tracks fetches album tracks from the database
*/
virtual Query<IMedia> tracks( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> tracks( const QueryParameters* params = nullptr ) const = 0;
/**
* @brief tracks fetches album tracks, filtered by genre
* @param genre A musical genre. Only tracks of this genre will be returned
* @return
*/
virtual Query<IMedia> tracks( GenrePtr genre, SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> tracks( GenrePtr genre, const QueryParameters* params = nullptr ) const = 0;
/**
* @brief albumArtist Returns the album main artist (generally tagged as album-artist)
*/
......
......@@ -42,8 +42,8 @@ public:
* This will return all albums by this artist, and all album the artist
* appeared on, even if they are not the main artist (or AlbumArtist)
*/
virtual Query<IAlbum> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> media( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IAlbum> albums( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> media( const QueryParameters* params = nullptr ) const = 0;
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& musicBrainzId() const = 0;
/**
......
......@@ -34,9 +34,9 @@ public:
virtual int64_t id() const = 0;
virtual const std::string& name() const = 0;
virtual uint32_t nbTracks() const = 0;
virtual Query<IArtist> artists( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> tracks( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IAlbum> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IArtist> artists( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> tracks( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IAlbum> albums( const QueryParameters* params = nullptr ) const = 0;
};
}
......@@ -74,6 +74,13 @@ enum class SortingCriteria
TrackNumber,
};
struct QueryParameters
{
SortingCriteria sort;
bool desc;
};
enum class InitializeResult
{
//< Everything worked out fine
......@@ -252,10 +259,10 @@ class IMediaLibrary
virtual MediaPtr media( int64_t mediaId ) const = 0;
virtual MediaPtr media( const std::string& mrl ) const = 0;
virtual MediaPtr addMedia( const std::string& mrl ) = 0;
virtual Query<IMedia> audioFiles( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> videoFiles( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IMedia> audioFiles( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> videoFiles( const QueryParameters* params = nullptr ) const = 0;
virtual AlbumPtr album( int64_t id ) const = 0;
virtual Query<IAlbum> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IAlbum> albums( const QueryParameters* params = nullptr ) const = 0;
virtual ShowPtr show( const std::string& name ) const = 0;
virtual MoviePtr movie( const std::string& title ) const = 0;
virtual ArtistPtr artist( int64_t id ) const = 0;
......@@ -270,20 +277,19 @@ class IMediaLibrary
* @param desc If true, the provided sorting criteria will be reversed.
*/
virtual Query<IArtist> artists( bool includeAll,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
/**
* @brief genres Return the list of music genres
* @param sort A sorting criteria. So far, this is ignored, and artists are sorted by lexial order
* @param desc If true, the provided sorting criteria will be reversed.
*/
virtual Query<IGenre> genres( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual Query<IGenre> genres( const QueryParameters* params = nullptr ) const = 0;
virtual GenrePtr genre( int64_t id ) const = 0;
/***
* Playlists
*/
virtual PlaylistPtr createPlaylist( const std::string& name ) = 0;
virtual Query<IPlaylist> playlists( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) = 0;
virtual Query<IPlaylist> playlists( const QueryParameters* params = nullptr ) = 0;
virtual PlaylistPtr playlist( int64_t id ) const = 0;
virtual bool deletePlaylist( int64_t playlistId ) = 0;
......@@ -307,21 +313,17 @@ class IMediaLibrary
* Search
*/
virtual MediaSearchAggregate searchMedia( const std::string& pattern,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IPlaylist> searchPlaylists( const std::string& name,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IAlbum> searchAlbums( const std::string& pattern,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
virtual Query<IGenre> searchGenre( const std::string& genre, SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IGenre> searchGenre( const std::string& genre,
const QueryParameters* params = nullptr ) const = 0;
virtual Query<IArtist> searchArtists( const std::string& name,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
virtual SearchAggregate search( const std::string& pattern,
SortingCriteria sort = SortingCriteria::Default,
bool desc = false ) const = 0;
const QueryParameters* params = nullptr ) const = 0;
/**
* @brief discover Launch a discovery on the provided entry point.
......
......@@ -190,9 +190,11 @@ bool Album::setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin orig
return true;
}
std::string Album::orderTracksBy( SortingCriteria sort, bool desc )
std::string Album::orderTracksBy( const QueryParameters* params = nullptr )
{
std::string req = " ORDER BY ";
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
switch ( sort )
{
case SortingCriteria::Alpha:
......@@ -217,9 +219,11 @@ std::string Album::orderTracksBy( SortingCriteria sort, bool desc )
return req;
}
std::string Album::orderBy( SortingCriteria sort, bool desc )
std::string Album::orderBy( const QueryParameters* params )
{
std::string req = " ORDER BY ";
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
switch ( sort )
{
case SortingCriteria::ReleaseDate:
......@@ -247,18 +251,18 @@ std::string Album::orderBy( SortingCriteria sort, bool desc )
return req;
}
Query<IMedia> Album::tracks( SortingCriteria sort, bool desc ) const
Query<IMedia> Album::tracks( const QueryParameters* params ) const
{
// This doesn't return the cached version, because it would be fairly complicated, if not impossible or
// counter productive, to maintain a cache that respects all orderings.
std::string req = "FROM " + policy::MediaTable::Name + " med "
" INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? AND med.is_present != 0";
req += orderTracksBy( sort, desc );
req += orderTracksBy( params );
return make_query<Media, IMedia>( m_ml, "med.*", std::move( req ), m_id );
}
Query<IMedia> Album::tracks( GenrePtr genre, SortingCriteria sort, bool desc ) const
Query<IMedia> Album::tracks( GenrePtr genre, const QueryParameters* params ) const
{
if ( genre == nullptr )
return {};
......@@ -266,7 +270,7 @@ Query<IMedia> Album::tracks( GenrePtr genre, SortingCriteria sort, bool desc ) c
" INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? AND med.is_present != 0"
" AND genre_id = ?";
req += orderTracksBy( sort, desc );
req += orderTracksBy( params );
return make_query<Media, IMedia>( m_ml, "med.*", std::move( req ), m_id, genre->id() );
}
......@@ -274,7 +278,7 @@ std::vector<MediaPtr> Album::cachedTracks() const
{
auto lock = m_tracks.lock();
if ( m_tracks.isCached() == false )
m_tracks = tracks( SortingCriteria::Default, false )->all();
m_tracks = tracks( nullptr )->all();
return m_tracks.get();
}
......@@ -493,18 +497,18 @@ std::shared_ptr<Album> Album::createUnknownAlbum( MediaLibraryPtr ml, const Arti
}
Query<IAlbum> Album::search( MediaLibraryPtr ml, const std::string& pattern,
SortingCriteria sort, bool desc )
const QueryParameters* params )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
"WHERE id_album IN "
"(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " +
policy::AlbumTable::Name + "Fts MATCH '*' || ? || '*')"
"AND is_present != 0";
req += orderBy( sort, desc );
req += orderBy( params );
return make_query<Album, IAlbum>( ml, "*", std::move( req ), pattern );
}
Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc )
Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, const QueryParameters* params )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
"INNER JOIN " + policy::AlbumTrackTable::Name + " att "
......@@ -512,6 +516,8 @@ Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCr
"WHERE (att.artist_id = ? OR alb.artist_id = ?) "
"AND att.is_present != 0 "
"GROUP BY att.album_id ORDER BY ";
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
switch ( sort )
{
case SortingCriteria::Alpha:
......@@ -533,17 +539,19 @@ Query<IAlbum> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCr
return make_query<Album, IAlbum>( ml, "*", req, artistId, artistId );
}
Query<IAlbum> Album::fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc)
Query<IAlbum> Album::fromGenre( MediaLibraryPtr ml, int64_t genreId, const QueryParameters* params )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
"INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.album_id = alb.id_album "
"WHERE att.genre_id = ? GROUP BY att.album_id";
req += orderBy( sort, desc );
req += orderBy( params );
return make_query<Album, IAlbum>( ml, "alb.*", std::move( req ), genreId );
}
Query<IAlbum> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc )
Query<IAlbum> Album::listAll( MediaLibraryPtr ml, const QueryParameters* params )
{
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
if ( sort == SortingCriteria::Artist )
{
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
......@@ -570,7 +578,7 @@ Query<IAlbum> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool des
}
std::string req = "FROM " + policy::AlbumTable::Name + " alb "
" WHERE is_present != 0";
req += orderBy( sort, desc );
req += orderBy( params );
return make_query<Album, IAlbum>( ml, "*", std::move( req ) );
}
......
......@@ -76,8 +76,8 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
virtual const std::string& artworkMrl() const override;
std::shared_ptr<Thumbnail> thumbnail();
bool setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin );
virtual Query<IMedia> tracks( SortingCriteria sort, bool desc ) const override;
virtual Query<IMedia> tracks( GenrePtr genre, SortingCriteria sort, bool desc ) const override;
virtual Query<IMedia> tracks( const QueryParameters* params ) const override;
virtual Query<IMedia> tracks( GenrePtr genre, const QueryParameters* params ) const override;
///
/// \brief cachedTracks Returns a cached list of tracks
/// This has no warranty of ordering, validity, or anything else.
......@@ -110,14 +110,14 @@ class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
/// \return
///
static Query<IAlbum> search( MediaLibraryPtr ml, const std::string& pattern,
SortingCriteria sort, bool desc );
static Query<IAlbum> fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc );
static Query<IAlbum> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
static Query<IAlbum> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
const QueryParameters* params );
static Query<IAlbum> fromArtist( MediaLibraryPtr ml, int64_t artistId, const QueryParameters* params );
static Query<IAlbum> fromGenre( MediaLibraryPtr ml, int64_t genreId, const QueryParameters* params );
static Query<IAlbum> listAll( MediaLibraryPtr ml, const QueryParameters* params );
private:
static std::string orderTracksBy( SortingCriteria sort, bool desc );
static std::string orderBy( SortingCriteria sort, bool desc );
static std::string orderTracksBy( const QueryParameters* params );
static std::string orderBy( const QueryParameters* params );
protected:
MediaLibraryPtr m_ml;
int64_t m_id;
......
......@@ -149,11 +149,13 @@ AlbumTrackPtr AlbumTrack::fromMedia( MediaLibraryPtr ml, int64_t mediaId )
return fetch( ml, req, mediaId );
}
Query<IMedia> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc )
Query<IMedia> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, const QueryParameters* params )
{
std::string req = "FROM " + policy::MediaTable::Name + " m"
" INNER JOIN " + policy::AlbumTrackTable::Name + " t ON m.id_media = t.media_id"
" WHERE t.genre_id = ? AND m.is_present = 1 ORDER BY ";
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
switch ( sort )
{
case SortingCriteria::Duration:
......
......@@ -74,7 +74,7 @@ class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy
unsigned int discNumber, int64_t artistId, int64_t genreId,
int64_t duration );
static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
static Query<IMedia> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
static Query<IMedia> fromGenre( MediaLibraryPtr ml, int64_t genreId, const QueryParameters* params );
private:
MediaLibraryPtr m_ml;
......
......@@ -88,15 +88,17 @@ bool Artist::setShortBio(const std::string& shortBio)
return true;
}
Query<IAlbum> Artist::albums( SortingCriteria sort, bool desc ) const
Query<IAlbum> Artist::albums( const QueryParameters* params ) const
{
return Album::fromArtist( m_ml, m_id, sort, desc );
return Album::fromArtist( m_ml, m_id, params );
}
Query<IMedia> Artist::media( SortingCriteria sort, bool desc ) const
Query<IMedia> Artist::media( const QueryParameters* params ) const
{
std::string req = "FROM " + policy::MediaTable::Name + " med ";
SortingCriteria sort = params != nullptr ? params->sort : SortingCriteria::Default;
bool desc = params != nullptr ? params->desc : false;
// Various artist is a special artist that doesn't have tracks per-se.
// Rather, it's a virtual artist for albums with many artist but no declared
// album artist. When listing its tracks, we need to list those by albums
......@@ -402,17 +404,17 @@ std::shared_ptr<Artist> Artist::create( MediaLibraryPtr ml, const std::string& n
}
Query<IArtist> Artist::search( MediaLibraryPtr ml, const std::string& name,
SortingCriteria sort, bool desc )
const QueryParameters* params )
{
std::string req = "FROM " + policy::ArtistTable::Name + " WHERE id_artist IN "
"(SELECT rowid FROM " + policy::ArtistTable::Name + "Fts WHERE name MATCH '*' || ? || '*')"
"AND is_present != 0";
req += sortRequest( sort, desc );
req += sortRequest( params );
return make_query<Artist, IArtist>( ml, "*", std::move( req ), name );
}
Query<IArtist> Artist::listAll( MediaLibraryPtr ml, bool includeAll,
SortingCriteria sort, bool desc)
const QueryParameters* params )
{
std::string req = "FROM " + policy::ArtistTable::Name + " WHERE ";
if ( includeAll == true )
......@@ -421,19 +423,14 @@ Query<IArtist> Artist::listAll( MediaLibraryPtr ml, bool includeAll,
req += "nb_albums > 0";
req += " AND is_present != 0";
req += sortRequest( sort, desc );
req += sortRequest( params );
return make_query<Artist, IArtist>( ml, "*", std::move( req ) );
}
std::string Artist::sortRequest( SortingCriteria sort, bool desc )
std::string Artist::sortRequest( const QueryParameters* params )
{
std::string req = " ORDER BY ";
switch ( sort )
{
default:
req += "name";
}
if ( desc == true )
std::string req = " ORDER BY name";
if ( params != nullptr && params->desc == true )
req += " DESC";
return req;
}
......
......@@ -55,8 +55,8 @@ public:
virtual const std::string& name() const override;
virtual const std::string& shortBio() const override;
bool setShortBio( const std::string& shortBio );
virtual Query<IAlbum> albums( SortingCriteria sort, bool desc ) const override;
virtual Query<IMedia> media(SortingCriteria sort, bool desc) const override;
virtual Query<IAlbum> albums( const QueryParameters* params ) const override;
virtual Query<IMedia> media( const QueryParameters* params ) const override;
bool addMedia( Media& media );
virtual const std::string& artworkMrl() const override;
std::shared_ptr<Thumbnail> thumbnail();
......@@ -74,12 +74,12 @@ public:
static bool createDefaultArtists( sqlite::Connection* dbConnection );
static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
static Query<IArtist> search( MediaLibraryPtr ml, const std::string& name,
SortingCriteria sort, bool desc );
const QueryParameters* params );
static Query<IArtist> listAll( MediaLibraryPtr ml, bool includeAll,
SortingCriteria sort, bool desc );
const QueryParameters* params );
private:
static std::string sortRequest( SortingCriteria sort, bool desc );
static std::string sortRequest( const QueryParameters* params );
private:
MediaLibraryPtr m_ml;
......
......@@ -77,25 +77,25 @@ void Genre::updateCachedNbTracks( int increment )
m_nbTracks += increment;
}
Query<IArtist> Genre::artists( SortingCriteria, bool desc ) const
Query<IArtist> Genre::artists( const QueryParameters* params ) const
{
std::string req = "FROM " + policy::ArtistTable::Name + " a "
"INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.artist_id = a.id_artist "
"WHERE att.genre_id = ? GROUP BY att.artist_id"
" ORDER BY a.name";
if ( desc == true )
if ( params != nullptr && params->desc == true )
req += " DESC";
return make_query<Artist, IArtist>( m_ml, "a.*", std::move( req ), m_id );
}
Query<IMedia> Genre::tracks( SortingCriteria sort, bool desc ) const
Query<IMedia> Genre::tracks( const QueryParameters* params ) const
{
return AlbumTrack::fromGenre( m_ml, m_id, sort, desc );
return AlbumTrack::fromGenre( m_ml, m_id, params );
}
Query<IAlbum> Genre::albums( SortingCriteria sort, bool desc ) const
Query<IAlbum> Genre::albums( const QueryParameters* params ) const
{
return Album::fromGenre( m_ml, m_id, sort, desc );
return Album::fromGenre( m_ml, m_id, params );
}
void Genre::createTable( sqlite::Connection* dbConn )
......@@ -171,19 +171,20 @@ std::shared_ptr<Genre> Genre::fromName( MediaLibraryPtr ml, const std::string& n
return fetch( ml, req, name );
}
Query<IGenre> Genre::search( MediaLibraryPtr ml, const std::string& name, SortingCriteria sort, bool desc )
Query<IGenre> Genre::search( MediaLibraryPtr ml, const std::string& name,
const QueryParameters* params )
{
std::string req = "FROM " + policy::GenreTable::Name + " WHERE id_genre IN "
"(SELECT rowid FROM " + policy::GenreTable::Name + "Fts WHERE name MATCH '*' || ? || '*') ORDER BY name";
if ( desc == true )
if ( params != nullptr && params->desc == true )
req += " DESC";
return make_query<Genre, IGenre>( ml, "*", req, name );
}
Query<IGenre> Genre::listAll( MediaLibraryPtr ml, SortingCriteria, bool desc )
Query<IGenre> Genre::listAll( MediaLibraryPtr ml, const QueryParameters* params )
{
std::string req = "FROM " + policy::GenreTable::Name + " ORDER BY name";
if ( desc == true )
if ( params != nullptr && params->desc == true )
req += " DESC";
return make_query<Genre, IGenre>( ml, "*", std::move( req ) );
}
......
......@@ -50,16 +50,16 @@ public:
virtual const std::string& name() const override;
virtual uint32_t nbTracks() const override;
void updateCachedNbTracks( int increment );
virtual Query<IArtist> artists( SortingCriteria sort, bool desc ) const override;
virtual Query<IMedia> tracks(SortingCriteria sort, bool desc) const override;
virtual Query<IAlbum> albums( SortingCriteria sort, bool desc ) const override;
virtual Query<IArtist> artists( const QueryParameters* params ) const override;
virtual Query<IMedia> tracks( const QueryParameters* params ) const override;
virtual Query<IAlbum> albums( const QueryParameters* params ) const override;
static void createTable( sqlite::Connection* dbConn );
static void createTriggers( sqlite::Connection* dbConn );
static std::shared_ptr<Genre> create( MediaLibraryPtr ml, const std::string& name );
static std::shared_ptr<Genre> fromName( MediaLibraryPtr ml, const std::string& name );
static Query<IGenre> search( MediaLibraryPtr ml, const std::string& name, SortingCriteria sort, bool desc );
static Query<IGenre> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
static Query<IGenre> search( MediaLibraryPtr ml, const std::string& name, const QueryParameters* params );
static Query<IGenre> listAll( MediaLibraryPtr ml, const QueryParameters* params );
private:
MediaLibraryPtr m_ml;
......
......@@ -467,10 +467,12 @@ void Media::removeFile( File& file )
}));
}
std::string Media::sortRequest( SortingCriteria sort, bool desc )
std::string Media::sortRequest( const QueryParameters* params )
{
std::string req = " ORDER BY ";
auto sort = params != nullptr ? params->sort : SortingCriteria::Default;
auto desc = params != nullptr ? params->desc : false;
switch ( sort )
{
case SortingCriteria::Duration:
......@@ -505,7 +507,7 @@ std::string Media::sortRequest( SortingCriteria sort, bool desc )
}
Query<IMedia> Media::listAll( MediaLibraryPtr ml, IMedia::Type type,
SortingCriteria sort, bool desc )
const QueryParameters* params )
{
std::string req = "FROM " + policy::MediaTable::Name + " m INNER JOIN "
+ policy::FileTable::Name + " f ON m.id_media = f.media_id"
......@@ -513,7 +515,7 @@ Query<IMedia> Media::listAll( MediaLibraryPtr ml, IMedia::Type type,
" AND f.type = ?"
" AND f.is_present != 0";
req += sortRequest( sort, desc );
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", std::move( req ),
type, IFile::Type::Main );
}
......@@ -720,7 +722,7 @@ bool Media::removeLabel( LabelPtr label )
}
Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
Media::SubType subType, SortingCriteria sort, bool desc )
Media::SubType subType, const QueryParameters* params )
{
std::string req = "FROM " + policy::MediaTable::Name + " m "
" INNER JOIN " + policy::FileTable::Name + " f ON m.id_media = f.media_id"
......@@ -730,7 +732,7 @@ Query<IMedia> Media::search( MediaLibraryPtr ml, const std::string& title,
" AND f.is_present = 1"
" AND f.type = ?"
" AND m.subtype = ?";
req += sortRequest( sort, desc );
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, title, File::Type::Main, subType );
}
......
......@@ -143,17 +143,16 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual FilePtr addExternalMrl( const std::string& mrl, IFile::Type type ) override;
void removeFile( File& file );
static Query<IMedia> listAll(MediaLibraryPtr ml, Type type, SortingCriteria sort, bool desc);
static Query<IMedia> listAll(MediaLibraryPtr ml, Type type, const QueryParameters* params );
static Query<IMedia> search( MediaLibraryPtr ml, const std::string& title,
Media::SubType subType, SortingCriteria sort,
bool desc );
Media::SubType subType, const QueryParameters* params );
static Query<IMedia> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
private:
static std::string sortRequest( SortingCriteria sort, bool desc );
static std::string sortRequest( const QueryParameters* params );
private:
MediaLibraryPtr m_ml;
......
......@@ -445,14 +445,14 @@ MediaPtr MediaLibrary::addMedia( const std::string& mrl )
}
}
Query<IMedia> MediaLibrary::audioFiles( SortingCriteria sort, bool desc ) const
Query<IMedia> MediaLibrary::audioFiles( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Audio, sort, desc );
return Media::listAll( this, IMedia::Type::Audio, params );
}
Query<IMedia> MediaLibrary::videoFiles( SortingCriteria sort, bool desc ) const
Query<IMedia> MediaLibrary::videoFiles( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Video, sort, desc );
return Media::listAll( this, IMedia::Type::Video, params );
}
bool MediaLibrary::isExtensionSupported( const char* ext )
......@@ -544,14 +544,14 @@ std::shared_ptr<Album> MediaLibrary::createAlbum( const std::string& title, int6
return Album::create( this, title, thumbnailId );
}
Query<IAlbum> MediaLibrary::albums( SortingCriteria sort, bool desc ) const
Query<IAlbum> MediaLibrary::albums( const QueryParameters* params ) const
{
return Album::listAll( this, sort, desc );
return Album::listAll( this, params );
}
Query<IGenre> MediaLibrary::genres( SortingCriteria sort, bool desc ) const
Query<IGenre> MediaLibrary::genres( const QueryParameters* params ) const
{
return Genre::listAll( this, sort, desc );
return Genre::listAll( this, params );
}
GenrePtr MediaLibrary::genre( int64_t id ) const
......@@ -611,10 +611,9 @@ std::shared_ptr<Artist> MediaLibrary::createArtist( const std::string& name )
}
}
Query<IArtist> MediaLibrary::artists( bool includeAll, SortingCriteria sort,
bool desc ) const
Query<IArtist> MediaLibrary::artists( bool includeAll, const QueryParameters* params ) const
{
return Artist::listAll( this, includeAll, sort, desc );
return Artist::listAll( this, includeAll, params );
}
PlaylistPtr MediaLibrary::createPlaylist( const std::string& name )
......@@ -630,9 +629,9 @@ PlaylistPtr MediaLibrary::createPlaylist( const std::string& name )
}
}
Query<IPlaylist> MediaLibrary::playlists( SortingCriteria sort, bool desc )
Query<IPlaylist> MediaLibrary::playlists( const QueryParameters* params )
{
return Playlist::listAll( this, sort, desc );
return Playlist::listAll( this, params );
}
PlaylistPtr MediaLibrary::playlist( int64_t id ) const
......@@ -696,64 +695,63 @@ bool MediaLibrary::clearHistory()
}
MediaSearchAggregate MediaLibrary::searchMedia( const std::string& title,
SortingCriteria sort, bool desc ) const
const QueryParameters* params ) const
{
if ( validateSearchPattern( title ) == false )
return {};
MediaSearchAggregate res;
res.episodes = Media::search( this, title, IMedia::SubType::ShowEpisode,
sort, desc );
params );
res.movies = Media::search( this, title, IMedia::SubType::Movie,
sort, desc );
params );
res.others = Media::search( this, title, IMedia::SubType::Unknown,
sort, desc );
params );
res.tracks = Media::search( this, title, IMedia::SubType::AlbumTrack,
sort, desc );
params );
return res;
}
Query<IPlaylist> MediaLibrary::searchPlaylists( const std::string& name,
SortingCriteria sort,
bool desc ) const
const QueryParameters* params ) const
{
if ( validateSearchPattern( name ) == false )
return {};
return Playlist::search( this, name, sort, desc );
return Playlist::search( this, name, params );
}
Query<IAlbum> MediaLibrary::searchAlbums( const std::string& pattern,
SortingCriteria sort, bool desc ) const
const QueryParameters* params ) const
{
if ( validateSearchPattern( pattern ) == false )
return {};
return Album::search( this, pattern, sort, desc );
return Album::search( this, pattern, params );
}
Query<IGenre> MediaLibrary::searchGenre( const std::string& genre, SortingCriteria sort, bool desc ) const
Query<IGenre> MediaLibrary::searchGenre( const std::string& genre,
const QueryParameters* params ) const
{
if ( validateSearchPattern( genre ) == false )
return {};
return Genre::search( this, genre, sort, desc );
return Genre::search( this, genre, params );
}
Query<IArtist> MediaLibrary::searchArtists( const std::string& name,
SortingCriteria sort,
bool desc ) const
const QueryParameters* params ) const
{
if ( validateSearchPattern( name ) == false )
return {};