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

Rename IFile/File to IMedia/Media

parent 7c56df4c
......@@ -39,7 +39,7 @@ class IAlbumTrack
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;
virtual std::vector<MediaPtr> files() = 0;
};
#endif // IALBUMTRACK_H
......@@ -33,7 +33,7 @@ public:
virtual unsigned int id() const = 0;
virtual const std::string& path() = 0;
// This will only returns the files in this immediate folder
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<MediaPtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0;
virtual unsigned int lastModificationDate() = 0;
virtual bool isRemovable() = 0;
......
......@@ -35,7 +35,7 @@ class ILabel
virtual unsigned int id() const = 0;
virtual const std::string& name() = 0;
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<MediaPtr> files() = 0;
};
#endif // ILABEL_H
......@@ -32,7 +32,7 @@ class IAlbumTrack;
class IShowEpisode;
class ITrackInformation;
class IFile
class IMedia
{
public:
enum class Type : uint8_t
......@@ -41,7 +41,7 @@ class IFile
AudioType, // Any kind of audio file, not being an album track
UnknownType
};
virtual ~IFile() {}
virtual ~IMedia() {}
virtual unsigned int id() const = 0;
virtual Type type() = 0;
......
......@@ -41,12 +41,12 @@ public:
* available yet.
* @param file
*/
virtual void onFileAdded( FilePtr file ) = 0;
virtual void onFileAdded( MediaPtr file ) = 0;
/**
* @brief onFileUpdated Will be called when a file metadata gets updated.
* @param file The updated file.
*/
virtual void onFileUpdated( FilePtr file ) = 0;
virtual void onFileUpdated( MediaPtr file ) = 0;
virtual void onDiscoveryStarted( const std::string& entryPoint ) = 0;
virtual void onDiscoveryCompleted( const std::string& entryPoint ) = 0;
......@@ -79,9 +79,9 @@ class IMediaLibrary
/// a stand alone file.
/// \return The newly created file, or nullptr in case of error
///
virtual FilePtr file( const std::string& path ) = 0;
virtual MediaPtr file( const std::string& path ) = 0;
virtual bool deleteFile( const std::string& mrl ) = 0;
virtual bool deleteFile( FilePtr file ) = 0;
virtual bool deleteFile( MediaPtr file ) = 0;
/// Adds a folder and all the files it contains
virtual FolderPtr folder( const std::string& path ) = 0;
......@@ -90,9 +90,9 @@ class IMediaLibrary
virtual LabelPtr createLabel( const std::string& label ) = 0;
virtual bool deleteLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<FilePtr> audioFiles() = 0;
virtual std::vector<FilePtr> videoFiles() = 0;
virtual std::vector<MediaPtr> files() = 0;
virtual std::vector<MediaPtr> audioFiles() = 0;
virtual std::vector<MediaPtr> videoFiles() = 0;
virtual AlbumPtr album( const std::string& title ) = 0;
virtual std::vector<AlbumPtr> albums() = 0;
virtual ShowPtr show( const std::string& name ) = 0;
......
......@@ -24,7 +24,7 @@
#define IMETADATASERVICE_H
#include "IMediaLibrary.h"
#include "File.h"
#include "Media.h"
class MediaLibrary;
......@@ -32,7 +32,7 @@ class IMetadataServiceCb
{
public:
virtual ~IMetadataServiceCb(){}
virtual void done( std::shared_ptr<File> file, ServiceStatus status, void* data ) = 0;
virtual void done( std::shared_ptr<Media> file, ServiceStatus status, void* data ) = 0;
};
class IMetadataService
......@@ -41,7 +41,7 @@ class IMetadataService
virtual ~IMetadataService() = default;
virtual bool initialize( IMetadataServiceCb* callback, MediaLibrary* ml ) = 0;
virtual unsigned int priority() const = 0;
virtual bool run( std::shared_ptr<File> file, void* data ) = 0;
virtual bool run( std::shared_ptr<Media> file, void* data ) = 0;
};
#endif // IMETADATASERVICE_H
......@@ -35,7 +35,7 @@ class IMovie
virtual const std::string& shortSummary() const = 0;
virtual const std::string& artworkUrl() const = 0;
virtual const std::string& imdbId() const = 0;
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<MediaPtr> files() = 0;
};
#endif // IMOVIE_H
......@@ -41,7 +41,7 @@ class IShowEpisode
virtual const std::string& shortSummary() const = 0;
virtual const std::string& tvdbId() const = 0;
virtual std::shared_ptr<IShow> show() = 0;
virtual std::vector<FilePtr> files() = 0;
virtual std::vector<MediaPtr> files() = 0;
};
#endif // ISHOWEPISODE_H
......@@ -29,7 +29,7 @@ class IAlbum;
class IAlbumTrack;
class IAudioTrack;
class IDiscoverer;
class IFile;
class IMedia;
class IFolder;
class ILabel;
class IMetadataService;
......@@ -41,7 +41,7 @@ class ILogger;
class IArtist;
class SqliteConnection;
typedef std::shared_ptr<IFile> FilePtr;
typedef std::shared_ptr<IMedia> MediaPtr;
typedef std::shared_ptr<IFolder> FolderPtr;
typedef std::shared_ptr<ILabel> LabelPtr;
typedef std::shared_ptr<IAlbum> AlbumPtr;
......
......@@ -23,7 +23,7 @@
#include "AlbumTrack.h"
#include "Album.h"
#include "Artist.h"
#include "File.h"
#include "Media.h"
#include "database/SqliteTools.h"
#include "logging/Logger.h"
......@@ -134,7 +134,7 @@ bool AlbumTrack::destroy()
{
// Ignore failures to discard from cache, we might want to discard records from
// cache in a near future to avoid running out of memory on mobile devices
File::discard( std::static_pointer_cast<File>( f ) );
Media::discard( std::static_pointer_cast<Media>( f ) );
}
return _Cache::destroy( m_dbConnection, this );
}
......@@ -155,9 +155,9 @@ std::vector<ArtistPtr> AlbumTrack::artists() const
return Artist::fetchAll( m_dbConnection, req, m_id );
}
std::vector<FilePtr> AlbumTrack::files()
std::vector<MediaPtr> AlbumTrack::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE album_track_id = ? ";
return File::fetchAll( m_dbConnection, req, m_id );
return Media::fetchAll( m_dbConnection, req, m_id );
}
......@@ -60,7 +60,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
virtual bool destroy();
virtual bool addArtist( ArtistPtr artist ) override;
virtual std::vector<ArtistPtr> artists() const override;
virtual std::vector<FilePtr> files();
virtual std::vector<MediaPtr> files();
static bool createTable( DBConnection dbConnection );
static std::shared_ptr<AlbumTrack> create( DBConnection dbConnection, unsigned int albumId,
......
......@@ -22,7 +22,7 @@ list(APPEND HEADERS_LIST
${CMAKE_SOURCE_DIR}/include/IShowEpisode.h
${CMAKE_SOURCE_DIR}/include/IAlbum.h
${CMAKE_SOURCE_DIR}/include/IAlbumTrack.h
${CMAKE_SOURCE_DIR}/include/IFile.h
${CMAKE_SOURCE_DIR}/include/IMedia.h
${CMAKE_SOURCE_DIR}/include/IFolder.h
${CMAKE_SOURCE_DIR}/include/IMediaLibrary.h
${CMAKE_SOURCE_DIR}/include/ILabel.h
......@@ -53,7 +53,7 @@ include_directories("${CMAKE_SOURCE_DIR}/src")
list(APPEND SRC_LIST ${HEADERS_LIST}
MediaLibrary.cpp
File.cpp
Media.cpp
Folder.cpp
Album.cpp
Show.cpp
......
......@@ -21,7 +21,7 @@
*****************************************************************************/
#include "Folder.h"
#include "File.h"
#include "Media.h"
#include "database/SqliteTools.h"
#include "filesystem/IDirectory.h"
......@@ -100,11 +100,11 @@ const std::string& Folder::path()
return m_path;
}
std::vector<FilePtr> Folder::files()
std::vector<MediaPtr> Folder::files()
{
static const std::string req = "SELECT * FROM " + policy::FileTable::Name +
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name +
" WHERE folder_id = ?";
return File::fetchAll( m_dbConection, req, m_id );
return Media::fetchAll( m_dbConection, req, m_id );
}
std::vector<FolderPtr> Folder::folders()
......
......@@ -65,7 +65,7 @@ public:
virtual unsigned int id() const override;
virtual const std::string& path() override;
virtual std::vector<FilePtr> files() override;
virtual std::vector<MediaPtr> files() override;
virtual std::vector<FolderPtr> folders() override;
virtual FolderPtr parent() override;
virtual unsigned int lastModificationDate() override;
......
......@@ -25,7 +25,7 @@
#include <cstring>
#include "Label.h"
#include "File.h"
#include "Media.h"
#include "database/SqliteTools.h"
const std::string policy::LabelTable::Name = "Label";
......@@ -55,12 +55,12 @@ const std::string& Label::name()
return m_name;
}
std::vector<FilePtr> Label::files()
std::vector<MediaPtr> Label::files()
{
static const std::string req = "SELECT f.* FROM " + policy::FileTable::Name + " f "
static const std::string req = "SELECT f.* FROM " + policy::MediaTable::Name + " f "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?";
return File::fetchAll( m_dbConnection, req, m_id );
return Media::fetchAll( m_dbConnection, req, m_id );
}
LabelPtr Label::create(DBConnection dbConnection, const std::string& name )
......
......@@ -26,7 +26,7 @@
#include <sqlite3.h>
#include <string>
class File;
class Media;
class Label;
#include "ILabel.h"
......@@ -61,7 +61,7 @@ class Label : public ILabel, public Cache<Label, ILabel, policy::LabelTable, pol
public:
virtual unsigned int id() const;
virtual const std::string& name();
virtual std::vector<FilePtr> files();
virtual std::vector<MediaPtr> files();
static LabelPtr create( DBConnection dbConnection, const std::string& name );
static bool createTable( DBConnection dbConnection );
......
......@@ -28,7 +28,7 @@
#include "Album.h"
#include "AlbumTrack.h"
#include "AudioTrack.h"
#include "File.h"
#include "Media.h"
#include "Folder.h"
#include "Label.h"
#include "logging/Logger.h"
......@@ -38,11 +38,11 @@
#include "VideoTrack.h"
#include "filesystem/IFile.h"
const std::string policy::FileTable::Name = "File";
const std::string policy::FileTable::CacheColumn = "mrl";
unsigned int File::* const policy::FileTable::PrimaryKey = &File::m_id;
const std::string policy::MediaTable::Name = "Media";
const std::string policy::MediaTable::CacheColumn = "mrl";
unsigned int Media::* const policy::MediaTable::PrimaryKey = &Media::m_id;
File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
Media::Media( DBConnection dbConnection, sqlite3_stmt* stmt )
: m_dbConnection( dbConnection )
{
m_id = sqlite3_column_int( stmt, 0 );
......@@ -60,7 +60,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_name = sqlite::Traits<std::string>::Load( stmt, 12 );
}
File::File( const fs::IFile* file, unsigned int folderId, const std::string& name, Type type )
Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& name, Type type )
: m_id( 0 )
, m_type( type )
, m_duration( -1 )
......@@ -76,10 +76,10 @@ File::File( const fs::IFile* file, unsigned int folderId, const std::string& nam
{
}
std::shared_ptr<File> File::create( DBConnection dbConnection, Type type, const fs::IFile* file, unsigned int folderId )
std::shared_ptr<Media> Media::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 +
auto self = std::make_shared<Media>( file, folderId, file->name(), type );
static const std::string req = "INSERT INTO " + policy::MediaTable::Name +
"(type, mrl, folder_id, last_modification_date, name) VALUES(?, ?, ?, ?, ?)";
using type_t = std::underlying_type<Type>::type;
......@@ -90,7 +90,7 @@ std::shared_ptr<File> File::create( DBConnection dbConnection, Type type, const
return self;
}
AlbumTrackPtr File::albumTrack()
AlbumTrackPtr Media::albumTrack()
{
if ( m_albumTrack == nullptr && m_albumTrackId != 0 )
{
......@@ -99,10 +99,10 @@ AlbumTrackPtr File::albumTrack()
return m_albumTrack;
}
bool File::setAlbumTrack( AlbumTrackPtr albumTrack )
bool Media::setAlbumTrack( AlbumTrackPtr albumTrack )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET album_track_id = ? "
"WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET album_track_id = ? "
"WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, albumTrack->id(), m_id ) == false )
return false;
m_albumTrackId = albumTrack->id();
......@@ -110,22 +110,22 @@ bool File::setAlbumTrack( AlbumTrackPtr albumTrack )
return true;
}
int64_t File::duration() const
int64_t Media::duration() const
{
return m_duration;
}
bool File::setDuration( int64_t duration )
bool Media::setDuration( int64_t duration )
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET duration = ? "
"WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET duration = ? "
"WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, duration, m_id ) == false )
return false;
m_duration = duration;
return true;
}
std::shared_ptr<IShowEpisode> File::showEpisode()
std::shared_ptr<IShowEpisode> Media::showEpisode()
{
if ( m_showEpisode == nullptr && m_showEpisodeId != 0 )
{
......@@ -134,10 +134,10 @@ std::shared_ptr<IShowEpisode> File::showEpisode()
return m_showEpisode;
}
bool File::setShowEpisode(ShowEpisodePtr showEpisode)
bool Media::setShowEpisode(ShowEpisodePtr showEpisode)
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET show_episode_id = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET show_episode_id = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, showEpisode->id(), m_id ) == false )
return false;
m_showEpisodeId = showEpisode->id();
......@@ -145,25 +145,25 @@ bool File::setShowEpisode(ShowEpisodePtr showEpisode)
return true;
}
std::vector<std::shared_ptr<ILabel> > File::labels()
std::vector<std::shared_ptr<ILabel> > Media::labels()
{
static const std::string req = "SELECT l.* FROM " + policy::LabelTable::Name + " l "
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = l.id_label "
"WHERE lfr.id_file = ?";
"WHERE lfr.id_media = ?";
return Label::fetchAll( m_dbConnection, req, m_id );
}
int File::playCount() const
int Media::playCount() const
{
return m_playCount;
}
const std::string& File::mrl() const
const std::string& Media::mrl() const
{
return m_mrl;
}
MoviePtr File::movie()
MoviePtr Media::movie()
{
if ( m_movie == nullptr && m_movieId != 0 )
{
......@@ -172,10 +172,10 @@ MoviePtr File::movie()
return m_movie;
}
bool File::setMovie( MoviePtr movie )
bool Media::setMovie( MoviePtr movie )
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET movie_id = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET movie_id = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, movie->id(), m_id ) == false )
return false;
m_movie = movie;
......@@ -183,7 +183,7 @@ bool File::setMovie( MoviePtr movie )
return true;
}
bool File::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps)
bool Media::addVideoTrack(const std::string& codec, unsigned int width, unsigned int height, float fps)
{
static const std::string req = "INSERT INTO VideoTrackFileRelation VALUES(?, ?)";
......@@ -197,15 +197,15 @@ bool File::addVideoTrack(const std::string& codec, unsigned int width, unsigned
return sqlite::Tools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
std::vector<VideoTrackPtr> File::videoTracks()
std::vector<VideoTrackPtr> Media::videoTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::VideoTrackTable::Name +
" t LEFT JOIN VideoTrackFileRelation vtfr ON vtfr.id_track = t.id_track"
" WHERE vtfr.id_file = ?";
" WHERE vtfr.id_media = ?";
return VideoTrack::fetchAll( m_dbConnection, req, m_id );
}
bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
bool Media::addAudioTrack( const std::string& codec, unsigned int bitrate,
unsigned int sampleRate, unsigned int nbChannels )
{
static const std::string req = "INSERT INTO AudioTrackFileRelation VALUES(?, ?)";
......@@ -220,70 +220,70 @@ bool File::addAudioTrack( const std::string& codec, unsigned int bitrate,
return sqlite::Tools::executeRequest( m_dbConnection, req, track->id(), m_id );
}
std::vector<AudioTrackPtr> File::audioTracks()
std::vector<AudioTrackPtr> Media::audioTracks()
{
static const std::string req = "SELECT t.* FROM " + policy::AudioTrackTable::Name +
" t LEFT JOIN AudioTrackFileRelation atfr ON atfr.id_track = t.id_track"
" WHERE atfr.id_file = ?";
" WHERE atfr.id_media = ?";
return AudioTrack::fetchAll( m_dbConnection, req, m_id );
}
const std::string &File::snapshot()
const std::string &Media::snapshot()
{
return m_snapshot;
}
bool File::setSnapshot(const std::string &snapshot)
bool Media::setSnapshot(const std::string &snapshot)
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET snapshot = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET snapshot = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, snapshot, m_id ) == false )
return false;
m_snapshot = snapshot;
return true;
}
bool File::isStandAlone()
bool Media::isStandAlone()
{
return m_folderId == 0;
}
unsigned int File::lastModificationDate()
unsigned int Media::lastModificationDate()
{
return m_lastModificationDate;
}
bool File::isParsed() const
bool Media::isParsed() const
{
return m_isParsed;
}
bool File::markParsed()
bool Media::markParsed()
{
if ( m_isParsed == true )
return true;
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET parsed = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET parsed = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, true, m_id ) == false )
return false;
m_isParsed = true;
return true;
}
unsigned int File::id() const
unsigned int Media::id() const
{
return m_id;
}
IFile::Type File::type()
IMedia::Type Media::type()
{
return m_type;
}
bool File::setType( Type type )
bool Media::setType( Type type )
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET type = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET type = ? WHERE id_media = ?";
// We need to convert to an integer representation for the sqlite traits to work properly
using type_t = std::underlying_type<Type>::type;
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, static_cast<type_t>( type ), m_id ) == false )
......@@ -292,25 +292,25 @@ bool File::setType( Type type )
return true;
}
const std::string &File::name()
const std::string &Media::name()
{
return m_name;
}
bool File::setName( const std::string &name )
bool Media::setName( const std::string &name )
{
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET name = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET name = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, name, m_id ) == false )
return false;
m_name = name;
return true;
}
bool File::createTable( DBConnection connection )
bool Media::createTable( DBConnection connection )
{
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::FileTable::Name + "("
"id_file INTEGER PRIMARY KEY AUTOINCREMENT,"
std::string req = "CREATE TABLE IF NOT EXISTS " + policy::MediaTable::Name + "("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER,"
"duration INTEGER,"
"album_track_id UNSIGNED INTEGER,"
......@@ -336,28 +336,28 @@ bool File::createTable( DBConnection connection )
return false;
req = "CREATE TABLE IF NOT EXISTS VideoTrackFileRelation("
"id_track INTEGER,"
"id_file INTEGER,"
"PRIMARY KEY ( id_track, id_file ), "
"id_media INTEGER,"
"PRIMARY KEY ( id_track, id_media ), "
"FOREIGN KEY ( id_track ) REFERENCES " + policy::VideoTrackTable::Name +
"(id_track) ON DELETE CASCADE,"
"FOREIGN KEY ( id_file ) REFERENCES " + policy::FileTable::Name
+ "(id_file) ON DELETE CASCADE"
"FOREIGN KEY ( id_media ) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE"
")";
if ( sqlite::Tools::executeRequest( connection, req ) == false )
return false;
req = "CREATE TABLE IF NOT EXISTS AudioTrackFileRelation("
"id_track INTEGER,"
"id_file INTEGER,"
"PRIMARY KEY ( id_track, id_file ), "
"id_media INTEGER,"
"PRIMARY KEY ( id_track, id_media ), "
"FOREIGN KEY ( id_track ) REFERENCES " + policy::AudioTrackTable::Name +
"(id_track) ON DELETE CASCADE,"
"FOREIGN KEY ( id_file ) REFERENCES " + policy::FileTable::Name
+ "(id_file) ON DELETE CASCADE"
"FOREIGN KEY ( id_media ) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( connection, req );
}
bool File::addLabel( LabelPtr label )
bool Media::addLabel( LabelPtr label )
{
if ( m_id == 0 || label->id() == 0 )
{
......@@ -368,23 +368,23 @@ bool File::addLabel( LabelPtr label )
return sqlite::Tools::executeRequest( m_dbConnection, req, label->id(), m_id );
}
bool File::removeLabel( LabelPtr label )
bool Media::removeLabel( LabelPtr label )
{
if ( m_id == 0 || label->id() == 0 )
{
LOG_ERROR( "Can't unlink a label/file not inserted in database" );
return false;
}
const char* req = "DELETE FROM LabelFileRelation WHERE id_label = ? AND id_file = ?";
const char* req = "DELETE FROM LabelFileRelation WHERE id_label = ? AND id_media = ?";
return sqlite::Tools::executeDelete( m_dbConnection, req, label->id(), m_id );
}
const std::string& policy::FileCache::key(const std::shared_ptr<File> self )
const std::string& policy::MediaCache::key(const std::shared_ptr<Media> self )
{
return self->mrl();
}
std::string policy::FileCache::key(sqlite3_stmt* stmt)
std::string policy::MediaCache::key(sqlite3_stmt* stmt)
{
return sqlite::Traits<std::string>::Load( stmt, 6 );
}
......@@ -26,45 +26,45 @@
#include <sqlite3.h>
#include "IFile.h"
#include "IMedia.h"
#include "database/Cache.h"
class Album;
class ShowEpisode;
class AlbumTrack;
class File;
class Media;
namespace policy
{
struct FileTable
struct MediaTable
{
static const std::string Name;
static const std::string CacheColumn;
static unsigned int File::*const PrimaryKey;
static unsigned int Media::*const PrimaryKey;
};
struct FileCache
struct MediaCache
{
typedef std::string KeyType;
static const std::string& key(const std::shared_ptr<File> self);
static const std::string& key(const std::shared_ptr<Media> self);
static std::string key( sqlite3_stmt* stmt );
};
}
class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::FileCache>
class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, policy::MediaCache>
{
private:
typedef Cache<File, IFile, policy::FileTable, policy::FileCache> _Cache;
typedef Cache<Media, IMedia, policy::MediaTable, policy::MediaCache> _Cache;
public:
// Those should be private, however the standard states that the expression
// ::new (pv) T(std::forward(args)...)
// shall be well-formed, and private constructor would prevent that.
// There might be a way with a user-defined allocator, but we'll see that later...
File(DBConnection dbConnection , sqlite3_stmt* stmt);
File(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
Media(DBConnection dbConnection , sqlite3_stmt* stmt);
Media(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
static std::shared_ptr<File> create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static std::shared_ptr<Media> create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static bool createTable( DBConnection connection );
virtual unsigned int id() const;
......@@ -126,8 +126,8 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
ShowEpisodePtr m_showEpisode;
MoviePtr m_movie;
friend class Cache<File, IFile, policy::FileTable, policy::FileCache>;
friend struct policy::FileTable;
friend class Cache<Media, IMedia, policy::MediaTable, policy::MediaCache>;