Commit dc810a81 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Library: Project loading is functionnal for the library.

This also fix a typo/bug when checking if a clip has already been
loaded.
parent 5638e7bf
......@@ -172,6 +172,7 @@ ImportController::importMedia( const QString &filePath )
m_ui->progressBar->setMaximum( m_nbMediaToLoad );
Media* media = m_temporaryMedias->addMedia( filePath );
m_temporaryMedias->addClip( media->baseClip() );
if ( media )
connect( media, SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( metaDataComputed( const Media* ) ) );
......
......@@ -39,139 +39,114 @@
#include <QXmlStreamWriter>
void
Library::loadProject( const QDomElement& medias )
Library::loadProject( const QDomElement& doc )
{
if ( medias.isNull() == true || medias.tagName() != "medias" )
{
qWarning() << "Invalid medias node";
const QDomElement medias = doc.firstChildElement( "medias" );
if ( medias.isNull() == true )
return ;
}
QDomElement elem = medias.firstChild().toElement();
while ( elem.isNull() == false )
QDomElement media = medias.firstChild().toElement();
while ( media.isNull() == false )
{
QList<QDomElement> clipList;
QDomElement mediaProperty = elem.firstChild().toElement();
QString path;
QString uuid;
while ( mediaProperty.isNull() == false )
{
QString tagName = mediaProperty.tagName();
if ( tagName == "path" )
path = mediaProperty.text();
else if ( tagName == "uuid" )
uuid = mediaProperty.text();
else if ( tagName == "clips" )
{
QDomElement clip = mediaProperty.firstChild().toElement();
while ( clip.isNull() == false )
{
clipList.push_back( clip );
clip = clip.nextSibling().toElement();
}
}
else
qWarning() << "Unknown field" << tagName;
mediaProperty = mediaProperty.nextSibling().toElement();
}
//FIXME: This is verry redondant...
if ( mediaAlreadyLoaded( path ) == true )
{
QHash<QUuid, Clip*>::iterator it = m_clips.begin();
QHash<QUuid, Clip*>::iterator end = m_clips.end();
for ( ; it != end; ++it )
{
if ( it.value()->getMedia()->fileInfo()->absoluteFilePath() == path )
{
Clip* clip = it.value();
clip->setUuid( QUuid( uuid ) );
m_clips.erase( it );
m_clips[clip->uuid()] = clip;
break ;
}
}
}
else
if ( media.hasAttribute( "mrl" ) == true )
{
if ( addMedia( path, uuid ) == false )
{
elem = elem.nextSibling().toElement();
continue ;
}
QString mrl = media.attribute( "mrl" );
Media* m = addMedia( mrl );
m_medias[mrl] = m;
}
if ( clipList.size() != 0 )
{
foreach( QDomElement clip, clipList )
{
QString parentUuid = clip.attribute( "parentUuid", "");
if ( parentUuid != "" && parentUuid == uuid )
{
QString beg = clip.attribute( "begin", "" );
QString end = clip.attribute( "end", "" );
QString clipUuid = clip.attribute( "uuid", "" );
if ( beg != "" && end != "" && uuid != "" )
{
if ( m_clips.contains( uuid ) == false )
continue ;
Clip* parentClip = m_clips[QUuid( uuid )];
Clip* clip = new Clip( parentClip, beg.toInt(), end.toInt(), QUuid( clipUuid ) );
parentClip->addSubclip( clip );
}
}
}
}
elem = elem.nextSibling().toElement();
media = media.nextSibling().toElement();
}
emit projectLoaded();
}
const QDomElement clips = doc.firstChildElement( "clips" );
if ( clips.isNull() == true )
return ;
load( clips, this );
//void
//Library::saveProject( QDomDocument& doc, QDomElement& rootNode )
//{
// QHash<QUuid, Media*>::iterator it = m_clips.begin();
// QHash<QUuid, Media*>::iterator end = m_clips.end();
//
// QDomElement medias = doc.createElement( "medias" );
//
// for ( ; it != end; ++it )
// if ( medias.isNull() == true || medias.tagName() != "medias" )
// {
// QDomElement media = doc.createElement( "media" );
//
// medias.appendChild( media );
// QDomElement mrl = doc.createElement( "path" );
//
// QDomCharacterData text;
// text = doc.createTextNode( it.value()->fileInfo()->absoluteFilePath() );
// qWarning() << "Invalid medias node";
// return ;
// }
//
// QDomElement uuid = doc.createElement( "uuid" );
// QDomCharacterData text2 = doc.createTextNode( it.value()->baseClip()->uuid().toString() );
// QDomElement elem = medias.firstChild().toElement();
// while ( elem.isNull() == false )
// {
// QList<QDomElement> clipList;
// QDomElement mediaProperty = elem.firstChild().toElement();
// QString path;
// QString uuid;
//
// mrl.appendChild( text );
// uuid.appendChild( text2 );
// while ( mediaProperty.isNull() == false )
// {
// QString tagName = mediaProperty.tagName();
// if ( tagName == "path" )
// path = mediaProperty.text();
// else if ( tagName == "uuid" )
// uuid = mediaProperty.text();
// else if ( tagName == "clips" )
// {
// QDomElement clip = mediaProperty.firstChild().toElement();
// while ( clip.isNull() == false )
// {
// clipList.push_back( clip );
// clip = clip.nextSibling().toElement();
// }
// }
// else
// qWarning() << "Unknown field" << tagName;
// mediaProperty = mediaProperty.nextSibling().toElement();
// }
// //FIXME: This is verry redondant...
// if ( mediaAlreadyLoaded( path ) == true )
// {
// QHash<QUuid, Clip*>::iterator it = m_clips.begin();
// QHash<QUuid, Clip*>::iterator end = m_clips.end();
//
// media.appendChild( mrl );
// media.appendChild( uuid );
// //Creating the clip branch
// if ( it.value()->clipsCount() != 0 )
// for ( ; it != end; ++it )
// {
// if ( it.value()->getMedia()->fileInfo()->absoluteFilePath() == path )
// {
// Clip* clip = it.value();
// clip->setUuid( QUuid( uuid ) );
// m_clips.erase( it );
// m_clips[clip->uuid()] = clip;
// break ;
// }
// }
// }
// else
// {
// if ( addMedia( path, uuid ) == false )
// {
// elem = elem.nextSibling().toElement();
// continue ;
// }
// }
// if ( clipList.size() != 0 )
// {
// QDomElement clips = doc.createElement( "clips" );
// foreach( Clip* c, it.value()->clips().values() )
// foreach( QDomElement clip, clipList )
// {
// QDomElement clip = doc.createElement( "clip" );
// clip.setAttribute( "begin", c->begin() );
// clip.setAttribute( "end", c->end() );
// clip.setAttribute( "uuid", c->uuid() );
// clip.setAttribute( "parentUuid", c->getMedia()->baseClip()->uuid() );
// clips.appendChild( clip );
// QString parentUuid = clip.attribute( "parentUuid", "");
// if ( parentUuid != "" && parentUuid == uuid )
// {
// QString beg = clip.attribute( "begin", "" );
// QString end = clip.attribute( "end", "" );
// QString clipUuid = clip.attribute( "uuid", "" );
// if ( beg != "" && end != "" && uuid != "" )
// {
// if ( m_clips.contains( uuid ) == false )
// continue ;
// Clip* parentClip = m_clips[QUuid( uuid )];
// Clip* clip = new Clip( parentClip, beg.toInt(), end.toInt(), QUuid( clipUuid ) );
// parentClip->addSubclip( clip );
// }
// }
// }
// media.appendChild( clips );
// }
// elem = elem.nextSibling().toElement();
// }
// rootNode.appendChild( medias );
// #warning "FIXME: Project saving";
//}
emit projectLoaded();
}
void
Library::saveProject( QXmlStreamWriter& project )
......
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include <QHash>
#include <QDomElement>
#include <QUuid>
#include "Clip.h"
......@@ -28,6 +29,8 @@
#include "Media.h"
#include "MetaDataManager.h"
#include <QtDebug>
MediaContainer::MediaContainer( Clip* parent /*= NULL*/ ) : m_parent( parent )
{
}
......@@ -81,7 +84,6 @@ MediaContainer::addMedia( const QFileInfo& fileInfo, const QString& uuid )
}
}
MetaDataManager::getInstance()->computeMediaMetadata( media );
addMedia( media );
return media;
}
......@@ -102,9 +104,12 @@ MediaContainer::addClip( Clip* clip )
foreach ( Clip* c, m_clips.values() )
{
if ( clip->uuid() == c->uuid() ||
( clip->getMedia()->fileInfo() == clip->getMedia()->fileInfo() &&
( clip->getMedia()->fileInfo() == c->getMedia()->fileInfo() &&
( clip->begin() == c->begin() && clip->end() == c->end() ) ) )
{
qDebug() << "Clip already loaded.";
return false;
}
}
m_clips[clip->uuid()] = clip;
emit newClipLoaded( clip );
......@@ -185,3 +190,45 @@ MediaContainer::save( QXmlStreamWriter &project )
foreach ( Clip* c, m_clips.values() )
c->save( project );
}
void
MediaContainer::load( const QDomElement &clips, MediaContainer *parentMC )
{
QDomElement clip = clips.firstChild().toElement();
while ( clip.isNull() == false )
{
QString uuid = clip.attribute( "uuid" );
QString metatags = clip.attribute( "metatags" );
QString notes = clip.attribute( "notes" );
Clip *c;
if ( clip.hasAttribute( "media" ) == true )
{
QString media = clip.attribute( "media" );
Media* m = m_medias[media];
if ( m != NULL )
{
c = new Clip( m, 0, -1, uuid );
addClip( c );
}
}
else
{
QString parent = clip.attribute( "parent" );
QString begin = clip.attribute( "begin" );
QString end = clip.attribute( "end" );
if ( parent.isEmpty() == false )
{
Clip* p = parentMC->clip( QUuid( parent ) );
c = new Clip( p, begin.toLongLong(), end.toLongLong(), uuid );
addClip( c );
}
}
QDomElement subClips = clip.firstChildElement( "subClips" );
if ( subClips.isNull() == false )
c->getChilds()->load( subClips, this );
clip = clip.nextSibling().toElement();
}
}
......@@ -31,6 +31,7 @@ class Media;
class Clip;
class QFileInfo;
class QXmlStreamWriter;
class QDomElement;
class MediaContainer : public QObject
{
......@@ -101,6 +102,8 @@ public:
*/
void save( QXmlStreamWriter& project );
void load( const QDomElement& root, MediaContainer *parent );
/**
* \return All the loaded Clip
*/
......@@ -116,6 +119,13 @@ protected:
*/
QHash<QUuid, Clip*> m_clips;
/**
* \brief Used when loading a project.
*
* This should not have an associated getter.
*/
QHash<QString, Media*> m_medias;
Clip* m_parent;
public slots:
......
......@@ -133,16 +133,10 @@ void ProjectManager::cleanChanged( bool val )
void ProjectManager::loadTimeline()
{
QDomElement root = m_domDocument->documentElement();
MainWorkflow::getInstance()->loadProject( root.firstChildElement( "timeline" ) );
emit projectUpdated( projectName(), true );
}
void ProjectManager::parseProjectNode( const QDomElement &node )
{
QDomElement projectNameNode = node.firstChildElement( "ProjectName" );
m_projectName = projectNameNode.attribute( "value", ProjectManager::unNamedProject );
// QDomElement root = m_domDocument->documentElement();
//
// MainWorkflow::getInstance()->loadProject( root.firstChildElement( "timeline" ) );
// emit projectUpdated( projectName(), true );
}
void ProjectManager::loadProject( const QString& fileName )
......@@ -154,11 +148,11 @@ void ProjectManager::loadProject( const QString& fileName )
return ;
m_projectFile = new QFile( fileName );
m_domDocument = new QDomDocument;
m_projectFile->open( QFile::ReadOnly );
m_domDocument->setContent( m_projectFile );
m_projectFile->close();
QDomDocument doc;
doc.setContent( m_projectFile );
m_needSave = false;
if ( ProjectManager::isBackupFile( fileName ) == false )
......@@ -171,12 +165,11 @@ void ProjectManager::loadProject( const QString& fileName )
m_projectFile = NULL;
}
QDomElement root = m_domDocument->documentElement();
QDomElement root = doc.documentElement();
parseProjectNode( root.firstChildElement( "project" ) );
connect( Library::getInstance(), SIGNAL( projectLoaded() ), this, SLOT( loadTimeline() ) );
Library::getInstance()->loadProject( root.firstChildElement( "medias" ) );
SettingsManager::getInstance()->load( root.firstChildElement( "project" ) );
// connect( Library::getInstance(), SIGNAL( projectLoaded() ), this, SLOT( loadTimeline() ) );
Library::getInstance()->loadProject( root );
// SettingsManager::getInstance()->load( root.firstChildElement( "project" ) );
}
QString ProjectManager::acquireProjectFileName()
......
......@@ -70,7 +70,6 @@ private:
* It's only purpose it to write the project for very specific cases.
*/
void __saveProject( const QString& fileName );
void parseProjectNode( const QDomElement& node );
void emergencyBackup();
static bool isBackupFile( const QString& projectFile );
void appendToRecentProject( const QString& projectName );
......@@ -91,7 +90,6 @@ private:
private:
QFile* m_projectFile;
QDomDocument* m_domDocument;
bool m_needSave;
QStringList m_recentsProjects;
QString m_projectName;
......
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