Commit 16c7b14f authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Library loading/saving is functionnal

parent 4d8b8d6e
......@@ -63,9 +63,9 @@ void Library::metaDataComputed( Media* media )
emit newClipLoaded( clip );
}
void Library::newMediaLoadingAsked( const QString& filePath )
void Library::newMediaLoadingAsked( const QString& filePath, const QString& uuid )
{
//Is this necessary ??
//FIXME: Is this necessary ??
QMutexLocker locker( &m_mutex );
Media* media;
foreach ( media, m_medias )
......@@ -73,8 +73,67 @@ void Library::newMediaLoadingAsked( const QString& filePath )
if ( media->getFileInfo()->absoluteFilePath() == filePath )
return ;
}
media = new Media( filePath );
media = new Media( filePath, uuid );
m_medias[media->getUuid()] = media;
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ), Qt::DirectConnection );
emit newMediaLoaded( media );
}
void Library::loadProject( const QDomElement& medias )
{
if ( medias.isNull() == true || medias.tagName() != "medias" )
{
qWarning() << "Invalid medias node";
return ;
}
QDomElement elem = medias.firstChild().toElement();
while ( elem.isNull() == false )
{
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
qWarning() << "Unknown field" << tagName;
Library::getInstance()->newMediaLoadingAsked( path, uuid );
mediaProperty = mediaProperty.nextSibling().toElement();
}
elem = elem.nextSibling().toElement();
}
}
void Library::saveProject( QDomDocument& doc )
{
QHash<QUuid, Media*>::iterator it = m_medias.begin();
QHash<QUuid, Media*>::iterator end = m_medias.end();
QDomElement medias = doc.createElement( "medias" );
for ( ; it != end; ++it )
{
QDomElement media = doc.createElement( "media" );
medias.appendChild( media );
QDomElement mrl = doc.createElement( "path" );
QDomCharacterData text = doc.createTextNode( it.value()->getFileInfo()->absoluteFilePath() );
QDomElement uuid = doc.createElement( "uuid" );
QDomCharacterData text2 = doc.createTextNode( it.value()->getUuid().toString() );
mrl.appendChild( text );
uuid.appendChild( text2 );
media.appendChild( mrl );
media.appendChild( uuid );
}
doc.appendChild( medias );
}
......@@ -35,6 +35,7 @@
#include <QFileInfo>
#include <QMutex>
#include <QMutexLocker>
#include <QDomElement>
#include "Media.h"
#include "Clip.h"
......@@ -63,9 +64,12 @@ private:
}
public slots:
void newMediaLoadingAsked( const QString& filePath );
void newMediaLoadingAsked( const QString& filePath, const QString& uuid = QString() );
void removingMediaAsked( const QUuid& uuid );
void loadProject( const QDomElement& project );
void saveProject( QDomDocument& doc );
private slots:
void metaDataComputed( Media* );
......
......@@ -35,7 +35,7 @@ const QString Media::ImageExtensions = "*.gif *.png *.jpg";
const QString Media::AudioExtensions = "*.mp3 *.oga *.flac *.aac *.wav";
const QString Media::streamPrefix = "stream://";
Media::Media( const QString& filePath )
Media::Media( const QString& filePath, const QString& uuid )
: m_vlcMedia( NULL ),
m_snapshot( NULL ),
m_fileInfo( NULL ),
......@@ -43,7 +43,10 @@ Media::Media( const QString& filePath )
m_width( 0 ),
m_height( 0 )
{
m_uuid = QUuid::createUuid();
if ( uuid.length() == 0 )
m_uuid = QUuid::createUuid();
else
m_uuid = QUuid( uuid );
if ( filePath.startsWith( Media::streamPrefix ) == false )
{
......
......@@ -74,7 +74,7 @@ public:
File,
Stream
};
Media( const QString& filePath );
Media( const QString& filePath, const QString& = QString() );
virtual ~Media();
/**
......
......@@ -395,8 +395,13 @@ Clip* MainWorkflow::getClip( const QUuid& uuid, unsigned int trackId )
void MainWorkflow::loadProject( const QDomElement& project )
{
if ( project.isNull() == true || project.tagName() != "timeline" )
{
qWarning() << "Invalid timeline node (" << project.tagName() << ')';
return ;
}
QDomElement elem = project.firstChild().toElement();
Q_ASSERT( project.tagName() == "timeline" );
while ( elem.isNull() == false )
{
......
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