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

Media: Provide an insertion date

parent d9664e4d
......@@ -65,6 +65,7 @@ class IMedia
// 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 unsigned int insertionDate() const = 0;
};
#endif // IFILE_H
......@@ -57,6 +57,7 @@ Media::Media( DBConnection dbConnection, sqlite::Row& row )
>> m_movieId
>> m_folderId
>> m_lastModificationDate
>> m_insertionDate
>> m_snapshot
>> m_isParsed
>> m_title;
......@@ -72,6 +73,7 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& t
, m_movieId( 0 )
, m_folderId( folderId )
, m_lastModificationDate( file->lastModificationDate() )
, m_insertionDate( time( nullptr ) )
, m_isParsed( false )
, m_title( title )
, m_changed( false )
......@@ -82,10 +84,10 @@ std::shared_ptr<Media> Media::create( DBConnection dbConnection, Type type, cons
{
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, title) VALUES(?, ?, ?, ?, ?)";
"(type, mrl, folder_id, last_modification_date, insertion_date, title) VALUES(?, ?, ?, ?, ?, ?)";
if ( insert( dbConnection, self, req, type, self->m_mrl, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_title) == false )
self->m_lastModificationDate, self->m_insertionDate, self->m_title) == false )
return nullptr;
self->m_dbConnection = dbConnection;
return self;
......@@ -225,6 +227,11 @@ const std::string &Media::snapshot()
return m_snapshot;
}
unsigned int Media::insertionDate() const
{
return m_insertionDate;
}
void Media::setSnapshot( const std::string& snapshot )
{
if ( m_snapshot == snapshot )
......@@ -319,6 +326,7 @@ bool Media::createTable( DBConnection connection )
"movie_id UNSIGNED INTEGER,"
"folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"insertion_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"parsed BOOLEAN NOT NULL DEFAULT 0,"
"title TEXT,"
......
......@@ -92,6 +92,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
unsigned int nbChannels, const std::string& language, const std::string& desc );
virtual std::vector<AudioTrackPtr> audioTracks() override;
virtual const std::string& snapshot() override;
virtual unsigned int insertionDate() const override;
void setSnapshot( const std::string& snapshot );
bool save();
......@@ -118,6 +119,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
unsigned int m_movieId;
unsigned int m_folderId;
unsigned int m_lastModificationDate;
unsigned int m_insertionDate;
std::string m_snapshot;
bool m_isParsed;
std::string m_title;
......
......@@ -49,6 +49,7 @@ TEST_F( Medias, Create )
ASSERT_TRUE( f->isStandAlone() );
ASSERT_FALSE( f->isParsed() );
ASSERT_EQ( f->duration(), -1 );
ASSERT_NE( 0u, f->insertionDate() );
auto files = ml->files();
ASSERT_EQ( files.size(), 1u );
......
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