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
/// 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 "ready" (meaning all required metadata have been parsed)
virtual bool setReady() = 0;
virtual bool isReady() const = 0;
virtual unsigned int lastModificationDate() = 0;
};
......
......@@ -34,8 +34,7 @@ File::File( DBConnection dbConnection, sqlite3_stmt* stmt )
m_folderId = sqlite::Traits<unsigned int>::Load( stmt, 8 );
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 9 );
m_snapshot = sqlite::Traits<std::string>::Load( stmt, 10 );
m_isReady = m_type != Type::UnknownType;
m_isParsed = sqlite::Traits<bool>::Load( stmt, 11 );
}
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_folderId( folderId )
, m_lastModificationDate( file->lastModificationDate() )
, m_isReady( false )
, m_isParsed( false )
{
}
......@@ -230,13 +229,19 @@ unsigned int File::lastModificationDate()
bool File::isReady() const
{
return m_isReady;
return m_isParsed;
}
void File::setReady()
bool File::setReady()
{
assert( m_isReady == false );
m_isReady = true;
if ( m_isParsed == 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
......@@ -275,6 +280,7 @@ bool File::createTable( DBConnection connection )
"folder_id UNSIGNED INTEGER,"
"last_modification_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"parsed BOOLEAN,"
"FOREIGN KEY (album_track_id) REFERENCES " + policy::AlbumTrackTable::Name
+ "(id_track) ON DELETE CASCADE,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
......
......@@ -73,7 +73,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
virtual unsigned int lastModificationDate() override;
virtual bool isReady() const;
void setReady();
bool setReady();
private:
DBConnection m_dbConnection;
......@@ -90,6 +90,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
unsigned int m_folderId;
unsigned int m_lastModificationDate;
std::string m_snapshot;
bool m_isParsed;
// Auto fetched related properties
Album* m_album;
......@@ -97,8 +98,6 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
ShowEpisodePtr m_showEpisode;
MoviePtr m_movie;
bool m_isReady;
friend class Cache<File, IFile, policy::FileTable, policy::FileCache>;
friend struct policy::FileTable;
};
......
#include "Parser.h"
#include <algorithm>
#include "Parser.h"
#include "IFile.h"
Parser::Parser()
: m_stopParser( false )
......@@ -87,6 +89,7 @@ void Parser::done( FilePtr file, ServiceStatus status, void* data )
++t->it;
if (t->it == t->end)
{
file->setReady();
t->cb->onMetadataUpdated( file );
delete t;
return;
......
......@@ -101,8 +101,6 @@ ServiceStatus VLCMetadataService::handleMediaMeta( FilePtr file, VLC::Media& med
if (parseVideoFile( file, media ) == false )
return StatusFatal;
}
auto f = std::static_pointer_cast<File>( file );
f->setReady();
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