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

Rework "ready" state.

It's now true when all metadata services have been run. The type is
still exposed and can be used to figure out if the basic metadata are
available
parent 5ac40117
...@@ -50,6 +50,8 @@ class IFile ...@@ -50,6 +50,8 @@ class IFile
/// Returns wether the file has been added as a stand alone file (true), or as /// Returns wether the file has been added as a stand alone file (true), or as
/// part of a folder (false) /// part of a folder (false)
virtual bool isStandAlone() = 0; virtual bool isStandAlone() = 0;
/// Explicitely mark a file as "ready" (meaning all required metadata have been parsed)
virtual bool setReady() = 0;
virtual bool isReady() const = 0; virtual bool isReady() const = 0;
virtual unsigned int lastModificationDate() = 0; virtual unsigned int lastModificationDate() = 0;
}; };
......
...@@ -34,8 +34,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt ) ...@@ -34,8 +34,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_folderId = sqlite::Traits<unsigned int>::Load( stmt, 8 ); m_folderId = sqlite::Traits<unsigned int>::Load( stmt, 8 );
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 9 ); m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 9 );
m_snapshot = sqlite::Traits<std::string>::Load( stmt, 10 ); m_snapshot = sqlite::Traits<std::string>::Load( stmt, 10 );
m_isParsed = sqlite::Traits<bool>::Load( stmt, 11 );
m_isReady = m_type != Type::UnknownType;
} }
File::File( const fs::IFile* file, unsigned int folderId ) File::File( const fs::IFile* file, unsigned int folderId )
...@@ -49,7 +48,7 @@ File::File( const fs::IFile* file, unsigned int folderId ) ...@@ -49,7 +48,7 @@ File::File( const fs::IFile* file, unsigned int folderId )
, m_movieId( 0 ) , m_movieId( 0 )
, m_folderId( folderId ) , m_folderId( folderId )
, m_lastModificationDate( file->lastModificationDate() ) , m_lastModificationDate( file->lastModificationDate() )
, m_isReady( false ) , m_isParsed( false )
{ {
} }
...@@ -230,13 +229,19 @@ unsigned int File::lastModificationDate() ...@@ -230,13 +229,19 @@ unsigned int File::lastModificationDate()
bool File::isReady() const bool File::isReady() const
{ {
return m_isReady; return m_isParsed;
} }
void File::setReady() bool File::setReady()
{ {
assert( m_isReady == false ); if ( m_isParsed == true )
m_isReady = true; return true;
static const std::string req = "UPDATE " + policy::FileTable::Name
+ " SET parsed = ? WHERE id_file = ?";
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 File::id() const
...@@ -275,6 +280,7 @@ bool File::createTable( DBConnection connection ) ...@@ -275,6 +280,7 @@ bool File::createTable( DBConnection connection )
"folder_id UNSIGNED INTEGER," "folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER," "last_modification_date UNSIGNED INTEGER,"
"snapshot TEXT," "snapshot TEXT,"
"parsed BOOLEAN,"
"FOREIGN KEY (album_track_id) REFERENCES " + policy::AlbumTrackTable::Name "FOREIGN KEY (album_track_id) REFERENCES " + policy::AlbumTrackTable::Name
+ "(id_track) ON DELETE CASCADE," + "(id_track) ON DELETE CASCADE,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name "FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
......
...@@ -73,7 +73,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy:: ...@@ -73,7 +73,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual unsigned int lastModificationDate() override; virtual unsigned int lastModificationDate() override;
virtual bool isReady() const; virtual bool isReady() const;
void setReady(); bool setReady();
private: private:
DBConnection m_dbConnection; DBConnection m_dbConnection;
...@@ -90,6 +90,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy:: ...@@ -90,6 +90,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
unsigned int m_folderId; unsigned int m_folderId;
unsigned int m_lastModificationDate; unsigned int m_lastModificationDate;
std::string m_snapshot; std::string m_snapshot;
bool m_isParsed;
// Auto fetched related properties // Auto fetched related properties
Album* m_album; Album* m_album;
...@@ -97,8 +98,6 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy:: ...@@ -97,8 +98,6 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
ShowEpisodePtr m_showEpisode; ShowEpisodePtr m_showEpisode;
MoviePtr m_movie; MoviePtr m_movie;
bool m_isReady;
friend class Cache<File, IFile, policy::FileTable, policy::FileCache>; friend class Cache<File, IFile, policy::FileTable, policy::FileCache>;
friend struct policy::FileTable; friend struct policy::FileTable;
}; };
......
#include "Parser.h"
#include <algorithm> #include <algorithm>
#include "Parser.h" #include "IFile.h"
Parser::Parser() Parser::Parser()
: m_stopParser( false ) : m_stopParser( false )
...@@ -87,6 +89,7 @@ void Parser::done( FilePtr file, ServiceStatus status, void* data ) ...@@ -87,6 +89,7 @@ void Parser::done( FilePtr file, ServiceStatus status, void* data )
++t->it; ++t->it;
if (t->it == t->end) if (t->it == t->end)
{ {
file->setReady();
t->cb->onMetadataUpdated( file ); t->cb->onMetadataUpdated( file );
delete t; delete t;
return; return;
......
...@@ -101,8 +101,6 @@ ServiceStatus VLCMetadataService::handleMediaMeta( FilePtr file, VLC::Media& med ...@@ -101,8 +101,6 @@ ServiceStatus VLCMetadataService::handleMediaMeta( FilePtr file, VLC::Media& med
if (parseVideoFile( file, media ) == false ) if (parseVideoFile( file, media ) == false )
return StatusFatal; return StatusFatal;
} }
auto f = std::static_pointer_cast<File>( file );
f->setReady();
return StatusSuccess; return StatusSuccess;
} }
......
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