Commit 7c56df4c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Remove setters & modification methods from public interfaces

parent 4d8a8fcd
......@@ -34,16 +34,10 @@ class IAlbum
virtual unsigned int id() const = 0;
virtual const std::string& title() const = 0;
virtual time_t releaseDate() const = 0;
virtual bool setReleaseDate( time_t date ) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual std::vector<std::shared_ptr<IAlbumTrack>> tracks() const = 0;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackId ) = 0;
virtual std::vector<ArtistPtr> artists() const = 0;
virtual bool addArtist( ArtistPtr artist ) = 0;
virtual bool destroy() = 0;
};
#endif // IALBUM_H
......@@ -34,17 +34,12 @@ class IAlbumTrack
virtual unsigned int id() const = 0;
virtual const std::string& genre() = 0;
virtual bool setGenre( const std::string& genre ) = 0;
virtual const std::string& title() = 0;
virtual unsigned int trackNumber() = 0;
virtual std::shared_ptr<IAlbum> album() = 0;
virtual bool addArtist( ArtistPtr artist ) = 0;
virtual std::vector<ArtistPtr> artists() const = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
virtual bool destroy() = 0;
};
#endif // IALBUMTRACK_H
......@@ -34,7 +34,6 @@ public:
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 0;
virtual const std::string& shortBio() const = 0;
virtual bool setShortBio( const std::string& shortBio ) = 0;
virtual std::vector<AlbumPtr> albums() const = 0;
virtual std::vector<AlbumTrackPtr> tracks() const = 0;
};
......@@ -45,45 +45,24 @@ class IFile
virtual unsigned int id() const = 0;
virtual Type type() = 0;
virtual bool setType( Type type ) = 0;
virtual const std::string& name() = 0;
virtual bool setName( const std::string& name ) = 0;
virtual AlbumTrackPtr albumTrack() = 0;
virtual bool setAlbumTrack(AlbumTrackPtr albumTrack ) = 0;
/**
* @brief duration Returns the file duration in ms
*/
virtual int64_t duration() const = 0;
virtual bool setDuration( int64_t duration ) = 0;
virtual std::shared_ptr<IShowEpisode> showEpisode() = 0;
virtual bool setShowEpisode( ShowEpisodePtr showEpisode ) = 0;
virtual int playCount() const = 0;
virtual const std::string& mrl() const = 0;
virtual bool addLabel( LabelPtr label ) = 0;
virtual bool removeLabel( LabelPtr label ) = 0;
virtual MoviePtr movie() = 0;
virtual bool setMovie( MoviePtr movie ) = 0;
virtual std::vector<std::shared_ptr<ILabel> > labels() = 0;
virtual bool addVideoTrack( const std::string& codec, unsigned int width,
unsigned int height, float fps ) = 0;
virtual std::vector<VideoTrackPtr> videoTracks() = 0;
virtual bool addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels ) = 0;
virtual std::vector<AudioTrackPtr> audioTracks() = 0;
// Returns the location of this file snapshot.
// This is likely to be used for album arts as well.
virtual const std::string& snapshot() = 0;
virtual bool setSnapshot( const std::string& snapshot ) = 0;
/// Returns wether the file has been added as a stand alone file (true), or as
/// part of a folder (false)
virtual bool isStandAlone() = 0;
/// Explicitely mark a file as fully parsed, meaning no metadata service needs to run anymore.
//FIXME: This lacks granularity as we don't have a straight forward way to know which service
//needs to run or not.
virtual bool markParsed() = 0;
virtual bool isParsed() const = 0;
virtual unsigned int lastModificationDate() = 0;
};
#endif // IFILE_H
......@@ -36,7 +36,6 @@ public:
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0;
virtual unsigned int lastModificationDate() = 0;
virtual bool setLastModificationDate( unsigned int lastModificationDate ) = 0;
virtual bool isRemovable() = 0;
virtual FolderPtr parent() = 0;
};
......@@ -79,7 +79,6 @@ class IMediaLibrary
/// a stand alone file.
/// \return The newly created file, or nullptr in case of error
///
virtual FilePtr addFile( const std::string& path, FolderPtr parentFolder ) = 0;
virtual FilePtr file( const std::string& path ) = 0;
virtual bool deleteFile( const std::string& mrl ) = 0;
virtual bool deleteFile( FilePtr file ) = 0;
......@@ -95,19 +94,15 @@ class IMediaLibrary
virtual std::vector<FilePtr> audioFiles() = 0;
virtual std::vector<FilePtr> videoFiles() = 0;
virtual AlbumPtr album( const std::string& title ) = 0;
virtual AlbumPtr createAlbum( const std::string& title ) = 0;
virtual std::vector<AlbumPtr> albums() = 0;
virtual ShowPtr show( const std::string& name ) = 0;
virtual ShowPtr createShow( const std::string& name ) = 0;
virtual MoviePtr movie( const std::string& title ) = 0;
virtual MoviePtr createMovie( const std::string& title ) = 0;
virtual ArtistPtr artist( const std::string& name ) = 0;
/**
* @brief unknownArtist returns a representation of a virtual "unknown" artist.
* If all tracks have an associated artist, this returns nullptr.
*/
virtual ArtistPtr unknownArtist() = 0;
virtual ArtistPtr createArtist( const std::string& name ) = 0;
virtual std::vector<ArtistPtr> artists() const = 0;
/**
......
......@@ -24,21 +24,24 @@
#define IMETADATASERVICE_H
#include "IMediaLibrary.h"
#include "File.h"
class MediaLibrary;
class IMetadataServiceCb
{
public:
virtual ~IMetadataServiceCb(){}
virtual void done( FilePtr file, ServiceStatus status, void* data ) = 0;
virtual void done( std::shared_ptr<File> file, ServiceStatus status, void* data ) = 0;
};
class IMetadataService
{
public:
virtual ~IMetadataService() = default;
virtual bool initialize( IMetadataServiceCb* callback, IMediaLibrary* ml ) = 0;
virtual bool initialize( IMetadataServiceCb* callback, MediaLibrary* ml ) = 0;
virtual unsigned int priority() const = 0;
virtual bool run( FilePtr file, void* data ) = 0;
virtual bool run( std::shared_ptr<File> file, void* data ) = 0;
};
#endif // IMETADATASERVICE_H
......@@ -32,14 +32,9 @@ class IMovie
virtual unsigned int id() const = 0;
virtual const std::string& title() const = 0;
virtual time_t releaseDate() const = 0;
virtual bool setReleaseDate( time_t date ) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual const std::string& imdbId() const = 0;
virtual bool setImdbId( const std::string& id ) = 0;
virtual bool destroy() = 0;
virtual std::vector<FilePtr> files() = 0;
};
......
......@@ -32,16 +32,10 @@ class IShow
virtual unsigned int id() const = 0;
virtual const std::string& name() const = 0;
virtual time_t releaseDate() const = 0;
virtual bool setReleaseDate( time_t date ) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual const std::string& tvdbId() = 0;
virtual bool setTvdbId( const std::string& id ) = 0;
virtual ShowEpisodePtr addEpisode( const std::string& title, unsigned int episodeNumber ) = 0;
virtual std::vector<ShowEpisodePtr> episodes() = 0;
virtual bool destroy() = 0;
};
#endif // ISHOW_H
......@@ -34,22 +34,14 @@ class IShowEpisode
virtual unsigned int id() const = 0;
virtual const std::string& artworkUrl() const = 0;
virtual bool setArtworkUrl( const std::string& artworkUrl ) = 0;
virtual unsigned int episodeNumber() const = 0;
virtual time_t lastSyncDate() const = 0;
virtual const std::string& name() const = 0;
virtual unsigned int seasonNumber() const = 0;
virtual bool setSeasonNumber(unsigned int seasonNumber) = 0;
virtual const std::string& shortSummary() const = 0;
virtual bool setShortSummary( const std::string& summary ) = 0;
virtual const std::string& tvdbId() const = 0;
virtual bool setTvdbId( const std::string& tvdbId ) = 0;
virtual std::shared_ptr<IShow> show() = 0;
virtual std::vector<FilePtr> files() = 0;
/**
* @brief destroy Deletes the album track and the file(s) associated
*/
virtual bool destroy() = 0;
};
#endif // ISHOWEPISODE_H
......@@ -116,7 +116,7 @@ std::vector<std::shared_ptr<IAlbumTrack>> Album::tracks() const
return AlbumTrack::fetchAll( m_dbConnection, req, m_id );
}
AlbumTrackPtr Album::addTrack( const std::string& title, unsigned int trackNb )
std::shared_ptr<AlbumTrack> Album::addTrack( const std::string& title, unsigned int trackNb )
{
return AlbumTrack::create( m_dbConnection, m_id, title, trackNb );
}
......@@ -129,7 +129,7 @@ std::vector<ArtistPtr> Album::artists() const
return Artist::fetchAll( m_dbConnection, req, m_id );
}
bool Album::addArtist( ArtistPtr artist )
bool Album::addArtist( std::shared_ptr<Artist> artist )
{
static const std::string req = "INSERT INTO AlbumArtistRelation VALUES(?, ?)";
if ( m_id == 0 || artist->id() == 0 )
......@@ -144,8 +144,9 @@ bool Album::destroy()
{
auto ts = tracks();
//FIXME: Have a single request to fetch all files at once, instead of having one per track
for ( auto& t : ts )
for ( auto& it : ts )
{
auto t = std::static_pointer_cast<AlbumTrack>( it );
t->destroy();
}
return _Cache::destroy( m_dbConnection, this );
......@@ -176,7 +177,7 @@ bool Album::createTable(DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, reqRel );
}
AlbumPtr Album::create(DBConnection dbConnection, const std::string& title )
std::shared_ptr<Album> Album::create(DBConnection dbConnection, const std::string& title )
{
auto album = std::make_shared<Album>( title );
static const std::string req = "INSERT INTO " + policy::AlbumTable::Name +
......
......@@ -32,6 +32,8 @@
#include "IAlbum.h"
class Album;
class AlbumTrack;
class Artist;
namespace policy
{
......@@ -61,15 +63,15 @@ class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
virtual bool setArtworkUrl( const std::string& artworkUrl );
virtual time_t lastSyncDate() const;
virtual std::vector<std::shared_ptr<IAlbumTrack> > tracks() const;
virtual AlbumTrackPtr addTrack( const std::string& title, unsigned int trackNb );
std::shared_ptr<AlbumTrack> addTrack( const std::string& title, unsigned int trackNb );
virtual std::vector<ArtistPtr> artists() const override;
virtual bool addArtist( ArtistPtr artist ) override;
virtual bool addArtist( std::shared_ptr<Artist> artist );
virtual bool destroy();
static bool createTable( DBConnection dbConnection );
static AlbumPtr create(DBConnection dbConnection, const std::string& title );
static std::shared_ptr<Album> create(DBConnection dbConnection, const std::string& title );
protected:
DBConnection m_dbConnection;
......
......@@ -79,7 +79,7 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
sqlite::Tools::executeRequest( dbConnection, reqRel );
}
AlbumTrackPtr AlbumTrack::create(DBConnection dbConnection, unsigned int albumId, const std::string& name, unsigned int trackNb)
std::shared_ptr<AlbumTrack> AlbumTrack::create(DBConnection dbConnection, unsigned int albumId, const std::string& name, unsigned int trackNb)
{
auto self = std::make_shared<AlbumTrack>( name, trackNb, albumId );
static const std::string req = "INSERT INTO " + policy::AlbumTrackTable::Name
......
......@@ -63,7 +63,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual std::vector<FilePtr> files();
static bool createTable( DBConnection dbConnection );
static AlbumTrackPtr create( DBConnection dbConnection, unsigned int albumId,
static std::shared_ptr<AlbumTrack> create( DBConnection dbConnection, unsigned int albumId,
const std::string& name, unsigned int trackNb );
private:
......
......@@ -118,7 +118,7 @@ bool Artist::createTable( DBConnection dbConnection )
return sqlite::Tools::executeRequest( dbConnection, req );
}
ArtistPtr Artist::create( DBConnection dbConnection, const std::string &name )
std::shared_ptr<Artist> Artist::create( DBConnection dbConnection, const std::string &name )
{
auto artist = std::make_shared<Artist>( name );
static const std::string req = "INSERT INTO " + policy::ArtistTable::Name +
......
......@@ -55,12 +55,12 @@ public:
virtual unsigned int id() const override;
virtual const std::string &name() const override;
virtual const std::string& shortBio() const override;
virtual bool setShortBio( const std::string& shortBio ) override;
virtual bool setShortBio( const std::string& shortBio );
virtual std::vector<AlbumPtr> albums() const override;
virtual std::vector<AlbumTrackPtr> tracks() const override;
static bool createTable( DBConnection dbConnection );
static ArtistPtr create( DBConnection dbConnection, const std::string& name );
static std::shared_ptr<Artist> create( DBConnection dbConnection, const std::string& name );
private:
DBConnection m_dbConnection;
......
......@@ -84,7 +84,7 @@ bool AudioTrack::createTable( DBConnection dbConnection )
return sqlite::Tools::executeRequest( dbConnection, req );
}
AudioTrackPtr AudioTrack::fetch(DBConnection dbConnection, const std::string& codec,
std::shared_ptr<AudioTrack> AudioTrack::fetch(DBConnection dbConnection, const std::string& codec,
unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels )
{
static const std::string req = "SELECT * FROM " + policy::AudioTrackTable::Name
......@@ -92,7 +92,7 @@ AudioTrackPtr AudioTrack::fetch(DBConnection dbConnection, const std::string& co
return AudioTrack::fetchOne( dbConnection, req, codec, bitrate, sampleRate, nbChannels );
}
AudioTrackPtr AudioTrack::create( DBConnection dbConnection, const std::string& codec,
std::shared_ptr<AudioTrack> AudioTrack::create( DBConnection dbConnection, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels )
{
static const std::string req = "INSERT INTO " + policy::AudioTrackTable::Name
......
......@@ -52,9 +52,9 @@ class AudioTrack : public IAudioTrack, public Cache<AudioTrack, IAudioTrack, pol
virtual unsigned int nbChannels() const;
static bool createTable( DBConnection dbConnection );
static AudioTrackPtr fetch( DBConnection dbConnection, const std::string& codec,
static std::shared_ptr<AudioTrack> fetch( DBConnection dbConnection, const std::string& codec,
unsigned int bitrate, unsigned int sampleRate, unsigned int nbChannels );
static AudioTrackPtr create(DBConnection dbConnection, const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
static std::shared_ptr<AudioTrack> create(DBConnection dbConnection, const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
private:
DBConnection m_dbConnection;
......
......@@ -76,7 +76,7 @@ File::File( const fs::IFile* file, unsigned int folderId, const std::string& nam
{
}
FilePtr File::create( DBConnection dbConnection, Type type, const fs::IFile* file, unsigned int folderId )
std::shared_ptr<File> File::create( DBConnection dbConnection, Type type, const fs::IFile* file, unsigned int folderId )
{
auto self = std::make_shared<File>( file, folderId, file->name(), type );
static const std::string req = "INSERT INTO " + policy::FileTable::Name +
......
......@@ -64,18 +64,18 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
File(DBConnection dbConnection , sqlite3_stmt* stmt);
File(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
static FilePtr create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static std::shared_ptr<File> create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static bool createTable( DBConnection connection );
virtual unsigned int id() const;
virtual Type type() override;
virtual bool setType( Type type ) override;
virtual bool setType( Type type );
virtual const std::string& name() override;
virtual bool setName( const std::string& name ) override;
virtual bool setName( const std::string& name );
virtual AlbumTrackPtr albumTrack();
virtual bool setAlbumTrack( AlbumTrackPtr albumTrack );
virtual int64_t duration() const;
virtual bool setDuration( int64_t duration) override;
virtual bool setDuration( int64_t duration);
virtual std::shared_ptr<IShowEpisode> showEpisode();
virtual bool setShowEpisode( ShowEpisodePtr showEpisode );
virtual bool addLabel( LabelPtr label );
......@@ -91,13 +91,16 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual bool addAudioTrack(const std::string& codec, unsigned int bitrate , unsigned int sampleRate, unsigned int nbChannels);
virtual std::vector<AudioTrackPtr> audioTracks();
virtual const std::string& snapshot() override;
virtual bool setSnapshot( const std::string& snapshot ) override;
virtual bool setSnapshot( const std::string& snapshot );
virtual bool isStandAlone() override;
virtual unsigned int lastModificationDate() override;
virtual bool isStandAlone();
virtual unsigned int lastModificationDate();
virtual bool markParsed() override;
virtual bool isParsed() const override;
/// Explicitely mark a file as fully parsed, meaning no metadata service needs to run anymore.
//FIXME: This lacks granularity as we don't have a straight forward way to know which service
//needs to run or not.
virtual bool markParsed();
virtual bool isParsed() const;
private:
DBConnection m_dbConnection;
......
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