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

Move all the codebase within a medialibrary namespace

So we avoid getting bitten by ODR
parent 604b5de2
......@@ -26,6 +26,9 @@
#ifndef __ANDROID__
namespace medialibrary
{
template <typename T>
inline std::string toString(T t)
{
......@@ -33,10 +36,15 @@ inline std::string toString(T t)
return std::to_string(t);
}
}
#else
#include <sstream>
namespace medialibrary
{
template <typename T>
inline std::string toString(T t)
{
......@@ -46,4 +54,6 @@ inline std::string toString(T t)
return ss.str();
}
}
#endif
......@@ -22,7 +22,12 @@
#pragma once
namespace medialibrary
{
class SqliteConnection;
class MediaLibrary;
typedef SqliteConnection* DBConnection;
using MediaLibraryPtr = const MediaLibrary*;
}
......@@ -29,6 +29,9 @@
#include "filesystem/IFile.h"
#include "medialibrary/IMediaLibrary.h"
namespace medialibrary
{
class IDiscoverer
{
public:
......@@ -41,4 +44,6 @@ public:
virtual void reload( const std::string& entryPoint ) = 0;
};
}
#endif // IDISCOVERER_H
......@@ -25,6 +25,9 @@
#include <memory>
#include <string>
namespace medialibrary
{
namespace fs
{
class IDirectory;
......@@ -55,3 +58,5 @@ namespace factory
virtual void refresh() = 0;
};
}
}
......@@ -24,6 +24,9 @@
#include <string>
namespace medialibrary
{
namespace fs
{
class IDevice
......@@ -36,3 +39,5 @@ public:
virtual const std::string& mountpoint() const = 0;
};
}
}
......@@ -26,6 +26,9 @@
#include <string>
#include <vector>
namespace medialibrary
{
namespace fs
{
class IFile;
......@@ -44,3 +47,5 @@ namespace fs
virtual std::shared_ptr<IDevice> device() const = 0;
};
}
}
......@@ -24,6 +24,9 @@
#include <string>
namespace medialibrary
{
namespace fs
{
class IFile
......@@ -40,3 +43,5 @@ namespace fs
virtual unsigned int lastModificationDate() const = 0;
};
}
}
......@@ -45,13 +45,13 @@ public:
/**
* @brief tracks fetches album tracks from the database
*/
virtual std::vector<std::shared_ptr<IMedia>> tracks( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<std::shared_ptr<IMedia>> tracks( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) 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 std::vector<std::shared_ptr<IMedia>> tracks( GenrePtr genre, medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<std::shared_ptr<IMedia>> tracks( GenrePtr genre, SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
/**
* @brief albumArtist Returns the album main artist (generally tagged as album-artist)
*/
......
......@@ -37,8 +37,8 @@ public:
virtual int64_t id() const = 0;
virtual const std::string& name() const = 0;
virtual const std::string& shortBio() const = 0;
virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> media( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> media( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& musicBrainzId() const = 0;
};
......
......@@ -35,9 +35,9 @@ public:
virtual ~IGenre() = default;
virtual int64_t id() const = 0;
virtual const std::string& name() const = 0;
virtual std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> tracks( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<ArtistPtr> artists( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> tracks( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
};
}
......@@ -31,40 +31,41 @@
namespace medialibrary
{
static constexpr auto UnknownArtistID = 1u;
static constexpr auto VariousArtistID = 2u;
struct MediaSearchAggregate
{
std::vector<MediaPtr> episodes;
std::vector<MediaPtr> movies;
std::vector<MediaPtr> others;
std::vector<MediaPtr> tracks;
};
struct SearchAggregate
{
std::vector<AlbumPtr> albums;
std::vector<ArtistPtr> artists;
std::vector<GenrePtr> genres;
MediaSearchAggregate media;
std::vector<PlaylistPtr> playlists;
};
enum class SortingCriteria
{
/*
* Default depends on the entity type:
* - By track number (and disc number) for album tracks
* - Alphabetical order for others
*/
Default,
Alpha,
Duration,
InsertionDate,
LastModificationDate,
ReleaseDate,
};
static constexpr auto UnknownArtistID = 1u;
static constexpr auto VariousArtistID = 2u;
struct MediaSearchAggregate
{
std::vector<MediaPtr> episodes;
std::vector<MediaPtr> movies;
std::vector<MediaPtr> others;
std::vector<MediaPtr> tracks;
};
struct SearchAggregate
{
std::vector<AlbumPtr> albums;
std::vector<ArtistPtr> artists;
std::vector<GenrePtr> genres;
MediaSearchAggregate media;
std::vector<PlaylistPtr> playlists;
};
enum class SortingCriteria
{
/*
* Default depends on the entity type:
* - By track number (and disc number) for album tracks
* - Alphabetical order for others
*/
Default,
Alpha,
Duration,
InsertionDate,
LastModificationDate,
ReleaseDate,
};
class IMediaLibraryCb
{
......@@ -131,10 +132,10 @@ class IMediaLibrary
virtual LabelPtr createLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual std::vector<MediaPtr> audioFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> videoFiles( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> audioFiles( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<MediaPtr> videoFiles( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual AlbumPtr album( int64_t id ) const = 0;
virtual std::vector<AlbumPtr> albums( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<AlbumPtr> albums( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) 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;
......@@ -145,19 +146,19 @@ class IMediaLibrary
* @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 std::vector<ArtistPtr> artists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<ArtistPtr> artists( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) 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 std::vector<GenrePtr> genres( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) const = 0;
virtual std::vector<GenrePtr> genres( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) const = 0;
virtual GenrePtr genre( int64_t id ) const = 0;
/***
* Playlists
*/
virtual PlaylistPtr createPlaylist( const std::string& name ) = 0;
virtual std::vector<PlaylistPtr> playlists( medialibrary::SortingCriteria sort = medialibrary::SortingCriteria::Default, bool desc = false ) = 0;
virtual std::vector<PlaylistPtr> playlists( SortingCriteria sort = SortingCriteria::Default, bool desc = false ) = 0;
virtual PlaylistPtr playlist( int64_t id ) const = 0;
virtual bool deletePlaylist( int64_t playlistId ) = 0;
......@@ -171,12 +172,12 @@ class IMediaLibrary
/**
* Search
*/
virtual medialibrary::MediaSearchAggregate searchMedia( const std::string& pattern ) const = 0;
virtual MediaSearchAggregate searchMedia( const std::string& pattern ) const = 0;
virtual std::vector<PlaylistPtr> searchPlaylists( const std::string& name ) const = 0;
virtual std::vector<AlbumPtr> searchAlbums( const std::string& pattern ) const = 0;
virtual std::vector<GenrePtr> searchGenre( const std::string& genre ) const = 0;
virtual std::vector<ArtistPtr> searchArtists( const std::string& name ) const = 0;
virtual medialibrary::SearchAggregate search( const std::string& pattern ) const = 0;
virtual SearchAggregate search( const std::string& pattern ) const = 0;
/**
* @brief discover Launch a discovery on the provided entry point.
......
......@@ -30,6 +30,9 @@
#include "database/SqliteTools.h"
namespace medialibrary
{
const std::string policy::AlbumTable::Name = "Album";
const std::string policy::AlbumTable::PrimaryKeyColumn = "id_album";
int64_t Album::* const policy::AlbumTable::PrimaryKey = &Album::m_id;
......@@ -140,18 +143,18 @@ bool Album::setArtworkMrl( const std::string& artworkMrl )
return true;
}
std::string Album::orderTracksBy( medialibrary::SortingCriteria sort, bool desc )
std::string Album::orderTracksBy( SortingCriteria sort, bool desc )
{
std::string req = " ORDER BY ";
switch ( sort )
{
case medialibrary::SortingCriteria::Alpha:
case SortingCriteria::Alpha:
req += "med.title";
break;
case medialibrary::SortingCriteria::Duration:
case SortingCriteria::Duration:
req += "med.duration";
break;
case medialibrary::SortingCriteria::ReleaseDate:
case SortingCriteria::ReleaseDate:
req += "med.release_date";
break;
default:
......@@ -167,18 +170,18 @@ std::string Album::orderTracksBy( medialibrary::SortingCriteria sort, bool desc
return req;
}
std::string Album::orderBy( medialibrary::SortingCriteria sort, bool desc )
std::string Album::orderBy( SortingCriteria sort, bool desc )
{
std::string req = " ORDER BY ";
switch ( sort )
{
case medialibrary::SortingCriteria::ReleaseDate:
case SortingCriteria::ReleaseDate:
if ( desc == true )
req += "release_year DESC, title";
else
req += "release_year, title";
break;
case medialibrary::SortingCriteria::Duration:
case SortingCriteria::Duration:
req += "duration";
if ( desc == true )
req += " DESC";
......@@ -192,7 +195,7 @@ std::string Album::orderBy( medialibrary::SortingCriteria sort, bool desc )
return req;
}
std::vector<medialibrary::MediaPtr> Album::tracks( medialibrary::SortingCriteria sort, bool desc ) const
std::vector<MediaPtr> Album::tracks( SortingCriteria sort, bool desc ) 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.
......@@ -200,10 +203,10 @@ std::vector<medialibrary::MediaPtr> Album::tracks( medialibrary::SortingCriteria
" INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.media_id = med.id_media "
" WHERE att.album_id = ? AND med.is_present = 1";
req += orderTracksBy( sort, desc );
return Media::fetchAll<medialibrary::IMedia>( m_ml, req, m_id );
return Media::fetchAll<IMedia>( m_ml, req, m_id );
}
std::vector<medialibrary::MediaPtr> Album::tracks( medialibrary::GenrePtr genre, medialibrary::SortingCriteria sort, bool desc ) const
std::vector<MediaPtr> Album::tracks( GenrePtr genre, SortingCriteria sort, bool desc ) const
{
if ( genre == nullptr )
return {};
......@@ -212,14 +215,14 @@ std::vector<medialibrary::MediaPtr> Album::tracks( medialibrary::GenrePtr genre,
" WHERE att.album_id = ? AND med.is_present = 1"
" AND genre_id = ?";
req += orderTracksBy( sort, desc );
return Media::fetchAll<medialibrary::IMedia>( m_ml, req, m_id, genre->id() );
return Media::fetchAll<IMedia>( m_ml, req, m_id, genre->id() );
}
std::vector<medialibrary::MediaPtr> Album::cachedTracks() const
std::vector<MediaPtr> Album::cachedTracks() const
{
auto lock = m_tracks.lock();
if ( m_tracks.isCached() == false )
m_tracks = tracks( medialibrary::SortingCriteria::Default, false );
m_tracks = tracks( SortingCriteria::Default, false );
return m_tracks.get();
}
......@@ -258,7 +261,7 @@ unsigned int Album::duration() const
return m_duration;
}
medialibrary::ArtistPtr Album::albumArtist() const
ArtistPtr Album::albumArtist() const
{
if ( m_artistId == 0 )
return nullptr;
......@@ -293,14 +296,14 @@ bool Album::setAlbumArtist( std::shared_ptr<Artist> artist )
return true;
}
std::vector<medialibrary::ArtistPtr> Album::artists( bool desc ) const
std::vector<ArtistPtr> Album::artists( bool desc ) const
{
std::string req = "SELECT art.* FROM " + policy::ArtistTable::Name + " art "
"INNER JOIN AlbumArtistRelation aar ON aar.artist_id = art.id_artist "
"WHERE aar.album_id = ? ORDER BY art.name";
if ( desc == true )
req += " DESC";
return Artist::fetchAll<medialibrary::IArtist>( m_ml, req, m_id );
return Artist::fetchAll<IArtist>( m_ml, req, m_id );
}
bool Album::addArtist( std::shared_ptr<Artist> artist )
......@@ -422,7 +425,7 @@ std::shared_ptr<Album> Album::createUnknownAlbum( MediaLibraryPtr ml, const Arti
return album;
}
std::vector<medialibrary::AlbumPtr> Album::search( MediaLibraryPtr ml, const std::string& pattern )
std::vector<AlbumPtr> Album::search( MediaLibraryPtr ml, const std::string& pattern )
{
static const std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " WHERE id_album IN "
"(SELECT rowid FROM " + policy::AlbumTable::Name + "Fts WHERE " +
......@@ -431,13 +434,13 @@ std::vector<medialibrary::AlbumPtr> Album::search( MediaLibraryPtr ml, const std
return fetchAll<IAlbum>( ml, req, pattern + "*" );
}
std::vector<medialibrary::AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, medialibrary::SortingCriteria sort, bool desc )
std::vector<AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc )
{
std::string req = "SELECT * FROM " + policy::AlbumTable::Name + " alb "
"WHERE artist_id = ? AND is_present=1 ORDER BY ";
switch ( sort )
{
case medialibrary::SortingCriteria::Alpha:
case SortingCriteria::Alpha:
req += "title";
if ( desc == true )
req += " DESC";
......@@ -456,7 +459,7 @@ std::vector<medialibrary::AlbumPtr> Album::fromArtist( MediaLibraryPtr ml, int64
return fetchAll<IAlbum>( ml, req, artistId );
}
std::vector<medialibrary::AlbumPtr> Album::fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc)
std::vector<AlbumPtr> Album::fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc)
{
std::string req = "SELECT a.* FROM " + policy::AlbumTable::Name + " a "
"INNER JOIN " + policy::AlbumTrackTable::Name + " att ON att.album_id = a.id_album "
......@@ -465,10 +468,12 @@ std::vector<medialibrary::AlbumPtr> Album::fromGenre( MediaLibraryPtr ml, int64_
return fetchAll<IAlbum>( ml, req, genreId );
}
std::vector<medialibrary::AlbumPtr> Album::listAll( MediaLibraryPtr ml, medialibrary::SortingCriteria sort, bool desc )
std::vector<AlbumPtr> Album::listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc )
{
std::string req = "SELECT * FROM " + policy::AlbumTable::Name +
" WHERE is_present=1";
req += orderBy( sort, desc );
return fetchAll<IAlbum>( ml, req );
}
}
......@@ -33,6 +33,9 @@
#include "medialibrary/IAlbum.h"
#include "utils/Cache.h"
namespace medialibrary
{
class Album;
class AlbumTrack;
class Artist;
......@@ -48,7 +51,7 @@ struct AlbumTable
};
}
class Album : public medialibrary::IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
{
public:
Album( MediaLibraryPtr ml, sqlite::Row& row );
......@@ -72,14 +75,14 @@ class Album : public medialibrary::IAlbum, public DatabaseHelpers<Album, policy:
bool setShortSummary( const std::string& summary );
virtual const std::string& artworkMrl() const override;
bool setArtworkMrl( const std::string& artworkMrl );
virtual std::vector<medialibrary::MediaPtr> tracks( medialibrary::SortingCriteria sort, bool desc ) const override;
virtual std::vector<medialibrary::MediaPtr> tracks( medialibrary::GenrePtr genre, medialibrary::SortingCriteria sort, bool desc ) const override;
virtual std::vector<MediaPtr> tracks( SortingCriteria sort, bool desc ) const override;
virtual std::vector<MediaPtr> tracks( GenrePtr genre, SortingCriteria sort, bool desc ) const override;
///
/// \brief cachedTracks Returns a cached list of tracks
/// This has no warranty of ordering, validity, or anything else.
/// \return An unordered-list of this album's tracks
///
std::vector<medialibrary::MediaPtr> cachedTracks() const;
std::vector<MediaPtr> cachedTracks() const;
///
/// \brief addTrack Add a track to the album.
/// This will modify the media, but *not* save it.
......@@ -89,9 +92,9 @@ class Album : public medialibrary::IAlbum, public DatabaseHelpers<Album, policy:
unsigned int nbTracks() const override;
unsigned int duration() const override;
virtual medialibrary::ArtistPtr albumArtist() const override;
virtual ArtistPtr albumArtist() const override;
bool setAlbumArtist( std::shared_ptr<Artist> artist );
virtual std::vector<medialibrary::ArtistPtr> artists(bool desc) const override;
virtual std::vector<ArtistPtr> artists(bool desc) const override;
bool addArtist( std::shared_ptr<Artist> artist );
bool removeArtist( Artist* artist );
......@@ -104,14 +107,14 @@ class Album : public medialibrary::IAlbum, public DatabaseHelpers<Album, policy:
/// \param pattern A pattern representing the title, or the name of the main artist
/// \return
///
static std::vector<medialibrary::AlbumPtr> search( MediaLibraryPtr ml, const std::string& pattern );
static std::vector<medialibrary::AlbumPtr> fromArtist( MediaLibraryPtr ml, int64_t artistId, medialibrary::SortingCriteria sort, bool desc );
static std::vector<medialibrary::AlbumPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc );
static std::vector<medialibrary::AlbumPtr> listAll( MediaLibraryPtr ml, medialibrary::SortingCriteria sort, bool desc );
static std::vector<AlbumPtr> search( MediaLibraryPtr ml, const std::string& pattern );
static std::vector<AlbumPtr> fromArtist( MediaLibraryPtr ml, int64_t artistId, SortingCriteria sort, bool desc );
static std::vector<AlbumPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
static std::vector<AlbumPtr> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
private:
static std::string orderTracksBy( medialibrary::SortingCriteria sort, bool desc );
static std::string orderBy( medialibrary::SortingCriteria sort, bool desc );
static std::string orderTracksBy( SortingCriteria sort, bool desc );
static std::string orderBy( SortingCriteria sort, bool desc );
protected:
MediaLibraryPtr m_ml;
int64_t m_id;
......@@ -124,10 +127,12 @@ class Album : public medialibrary::IAlbum, public DatabaseHelpers<Album, policy:
unsigned int m_duration;
bool m_isPresent;
mutable Cache<std::vector<medialibrary::MediaPtr>> m_tracks;
mutable Cache<std::vector<MediaPtr>> m_tracks;
mutable Cache<std::shared_ptr<Artist>> m_albumArtist;
friend struct policy::AlbumTable;
};
}
#endif // ALBUM_H
......@@ -28,6 +28,9 @@
#include "database/SqliteTools.h"
#include "logging/Logger.h"
namespace medialibrary
{
const std::string policy::AlbumTrackTable::Name = "AlbumTrack";
const std::string policy::AlbumTrackTable::PrimaryKeyColumn = "id_track";
int64_t AlbumTrack::* const policy::AlbumTrackTable::PrimaryKey = &AlbumTrack::m_id;
......@@ -63,7 +66,7 @@ int64_t AlbumTrack::id() const
return m_id;
}
medialibrary::ArtistPtr AlbumTrack::artist() const
ArtistPtr AlbumTrack::artist() const
{
if ( m_artistId == 0 )
return nullptr;
......@@ -130,30 +133,30 @@ std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, int64_t albu
return self;
}
medialibrary::AlbumTrackPtr AlbumTrack::fromMedia( MediaLibraryPtr ml, int64_t mediaId )
AlbumTrackPtr AlbumTrack::fromMedia( MediaLibraryPtr ml, int64_t mediaId )
{
static const std::string req = "SELECT * FROM " + policy::AlbumTrackTable::Name +
" WHERE media_id = ?";
return fetch( ml, req, mediaId );
}
std::vector<medialibrary::MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, medialibrary::SortingCriteria sort, bool desc )
std::vector<MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc )
{
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m"
" INNER JOIN " + policy::AlbumTrackTable::Name + " t ON m.id_media = t.media_id"
" WHERE t.genre_id = ? ORDER BY ";
switch ( sort )
{
case medialibrary::SortingCriteria::Duration:
case SortingCriteria::Duration:
req += "m.duration";
break;
case medialibrary::SortingCriteria::InsertionDate:
case SortingCriteria::InsertionDate:
req += "m.insertion_date";
break;
case medialibrary::SortingCriteria::ReleaseDate:
case SortingCriteria::ReleaseDate:
req += "m.release_date";
break;
case medialibrary::SortingCriteria::Alpha:
case SortingCriteria::Alpha:
req += "m.title";
break;
default:
......@@ -166,10 +169,10 @@ std::vector<medialibrary::MediaPtr> AlbumTrack::fromGenre( MediaLibraryPtr ml, i
if ( desc == true )
req += " DESC";
return Media::fetchAll<medialibrary::IMedia>( ml, req, genreId );
return Media::fetchAll<IMedia>( ml, req, genreId );
}
medialibrary::GenrePtr AlbumTrack::genre()
GenrePtr AlbumTrack::genre()
{
auto l = m_genre.lock();
if ( m_genre.isCached() == false )
......@@ -203,7 +206,7 @@ unsigned int AlbumTrack::discNumber() const
return m_discNumber;
}
std::shared_ptr<medialibrary::IAlbum> AlbumTrack::album()
std::shared_ptr<IAlbum> AlbumTrack::album()
{
auto album = m_album.lock();
if ( album == nullptr && m_albumId != 0 )
......@@ -214,7 +217,7 @@ std::shared_ptr<medialibrary::IAlbum> AlbumTrack::album()
return album;
}
std::shared_ptr<medialibrary::IMedia> AlbumTrack::media()
std::shared_ptr<IMedia> AlbumTrack::media()
{
auto lock = m_media.lock();
if ( m_media.isCached() == false )
......@@ -223,3 +226,5 @@ std::shared_ptr<medialibrary::IMedia> AlbumTrack::media()
}
return m_media.get().lock();
}
}
......@@ -32,6 +32,9 @@
#include "database/DatabaseHelpers.h"
#include "utils/Cache.h"
namespace medialibrary
{
class Album;
class AlbumTrack;
class Artist;
......@@ -48,28 +51,28 @@ struct AlbumTrackTable
};
}
class AlbumTrack : public medialibrary::IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy::AlbumTrackTable>
class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy::AlbumTrackTable>
{
public:
AlbumTrack( MediaLibraryPtr ml, sqlite::Row& row );
AlbumTrack( MediaLibraryPtr ml, int64_t mediaId, unsigned int trackNumber, int64_t albumId, unsigned int discNumber);
virtual int64_t id() const override;
virtual medialibrary::ArtistPtr artist() const override;
virtual ArtistPtr artist() const override;
bool setArtist( std::shared_ptr<Artist> artist );
virtual medialibrary::GenrePtr genre() override;
virtual GenrePtr genre() override;
bool setGenre( std::shared_ptr<Genre> genre );
virtual unsigned int trackNumber() override;
virtual unsigned int discNumber() const override;
virtual std::shared_ptr<medialibrary::IAlbum> album() override;
virtual std::shared_ptr<medialibrary::IMedia> media() override;
virtual std::shared_ptr<IAlbum> album() override;
virtual std::shared_ptr<IMedia> media() override;
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AlbumTrack> create( MediaLibraryPtr ml, int64_t albumId,
std::shared_ptr<Media> media, unsigned int trackNb , unsigned int discNumber );