Commit d5f01cae authored by luyikei's avatar luyikei Committed by Hugo Beauzée-Luyssen

Complete save/load of Library

Signed-off-by: default avatarHugo Beauzée-Luyssen <hugo@beauzee.fr>
parent b78df552
......@@ -36,7 +36,7 @@
#include "Tools/VlmcDebug.h"
#include "Project/Workspace.h"
#include <QDomElement>
#include <QVariant>
#include <QHash>
#include <QUuid>
......@@ -45,9 +45,36 @@ Library::Library( Settings *projectSettings )
, m_settings( new Settings )
{
m_settings->createVar( SettingValue::List, QString( "medias" ), QVariantList(), "", "", SettingValue::Nothing );
m_settings->createVar( SettingValue::List, QString( "clips" ), QVariantList(), "", "", SettingValue::Nothing );
connect( m_settings, &Settings::postLoad, this, &Library::postLoad, Qt::DirectConnection );
connect( m_settings, &Settings::preSave, this, &Library::preSave, Qt::DirectConnection );
projectSettings->addSettings( "Library", *m_settings );
}
void
Library::preSave()
{
QVariantList l;
for ( auto val : m_medias )
l << val->toVariant();
m_settings->value( "medias" )->set( l );
l.clear();
for ( auto val : m_clips )
l << val->toVariantFull();
m_settings->value( "clips" )->set( l );
}
void
Library::postLoad()
{
for ( const auto& var : m_settings->value( "medias" )->get().toList() )
createMediaFromVariant( var );
for ( const auto& var : m_settings->value( "clips" )->get().toList() )
createClipFromVariant( var, nullptr );
}
Library::~Library()
{
delete m_settings;
......@@ -95,6 +122,7 @@ Library::addClip( Clip *clip )
bool ret = MediaContainer::addClip( clip );
if ( ret != false )
setCleanState( false );
m_medias[clip->getMedia()->fileInfo()->absoluteFilePath()] = clip->getMedia();
return ret;
}
......
......@@ -69,6 +69,8 @@ private:
Workspace* m_workspace;
Settings* m_settings;
void preSave();
void postLoad();
private slots:
void mediaLoaded( const Media* m );
......
......@@ -194,3 +194,29 @@ MediaContainer::count() const
{
return m_clips.size();
}
Media*
MediaContainer::createMediaFromVariant( const QVariant& var )
{
Media* m = addMedia( QFileInfo( var.toString() ) );
return m;
}
Clip*
MediaContainer::createClipFromVariant( const QVariant &var, Clip* parent )
{
QVariantMap h = var.toMap();
Clip* c = nullptr;
if ( h.contains( "parent" ) )
c = new Clip( parent, h["begin"].toULongLong(),
h["end"].toULongLong(), h["uuid"].toString() );
else {
c = new Clip( m_medias[ h["media"].toString() ], 0, -1, h["uuid"].toString() );
addClip( c );
}
if ( h.contains( "subClips" ) )
for ( auto& var : h["subClips"].toList() )
c->addSubclip( createClipFromVariant( var, c ) );
return c;
}
......@@ -121,6 +121,9 @@ protected:
Clip* m_parent;
Media* createMediaFromVariant( const QVariant& var );
Clip* createClipFromVariant( const QVariant& var, Clip* parent );
public slots:
/**
* \brief Removes a Clip from the container and delete it
......
......@@ -25,10 +25,12 @@
*/
#include "Clip.h"
#include "Main/Core.h"
#include "Backend/ISource.h"
#include "Library/Library.h"
#include "Media/Media.h"
#include "Project/Workspace.h"
#include <QVariant>
const int Clip::DefaultFPS = 30;
......@@ -243,6 +245,40 @@ Clip::isChild( const QUuid &uuid) const
return false;
}
QVariant
Clip::toVariant() const
{
QVariantHash h = {
{ "uuid", m_uuid.toString() },
{ "metatags", m_metaTags },
{ "notes", m_notes }
};
if ( isRootClip() )
h.insert( "media", m_media->toVariant() );
else
{
h.insert( "parent", m_parent->uuid().toString() );
h.insert( "begin", m_begin );
h.insert( "end", m_end );
}
return QVariant( h );
}
QVariant
Clip::toVariantFull() const
{
QVariantHash h = toVariant().toHash();
if ( m_childs->count() > 0 )
{
QVariantList l;
for ( const auto& c : m_childs->clips() )
l << c->toVariant();
h.insert( "subClips", l );
}
return h;
}
void
Clip::mediaMetadataUpdated()
{
......
......@@ -143,6 +143,9 @@ class Clip : public QObject
*/
bool isChild( const QUuid& uuid ) const;
QVariant toVariant() const;
QVariant toVariantFull() const;
private:
Media *m_media;
/**
......
......@@ -31,6 +31,8 @@
#include "Media.h"
#include "Clip.h"
#include "Main/Core.h"
#include "Library/Library.h"
#include "Metadata/MetaDataManager.h"
#include "Tools/VlmcDebug.h"
#include "Project/Workspace.h"
......@@ -146,6 +148,12 @@ Media::onMetaDataComputed()
}
}
QVariant
Media::toVariant() const
{
return QVariant( m_fileInfo->absoluteFilePath() );
}
void
Media::setFilePath( const QString &filePath )
{
......
......@@ -97,6 +97,8 @@ public:
void onMetaDataComputed();
QVariant toVariant() const;
// This has to be called from the GUI thread.
QPixmap& snapshot();
......
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