Commit 20266b06 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Solving a bug when loading a project with some already loaded videos.

Removed useless code, code factorisation
parent 3122b77b
......@@ -46,7 +46,6 @@ Clip* Library::getClip( const QUuid& uuid )
void Library::removingMediaAsked( const QUuid& uuid )
{
QMutexLocker locker( &m_mutex );
QHash<QUuid, Media*>::iterator it = m_medias.find( uuid );
if ( it == m_medias.end() )
return ;
......@@ -74,20 +73,26 @@ void Library::metaDataComputed( Media* media )
void Library::newMediaLoadingAsked( const QString& filePath, const QString& uuid )
{
//FIXME: Is this necessary ??
QMutexLocker locker( &m_mutex );
Media* media;
foreach ( media, m_medias )
{
if ( media->getFileInfo()->absoluteFilePath() == filePath )
return ;
}
if ( mediaAlreadyLoaded( filePath ) == true )
return ;
media = new Media( filePath, uuid );
m_medias[media->getUuid()] = media;
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ), Qt::DirectConnection );
emit newMediaLoaded( media );
}
bool Library::mediaAlreadyLoaded( const QString& filePath )
{
Media* media;
foreach ( media, m_medias )
{
if ( media->getFileInfo()->absoluteFilePath() == filePath )
return true;
}
return false;
}
void Library::loadProject( const QDomElement& medias )
{
if ( medias.isNull() == true || medias.tagName() != "medias" )
......@@ -115,8 +120,31 @@ void Library::loadProject( const QDomElement& medias )
qWarning() << "Unknown field" << tagName;
mediaProperty = mediaProperty.nextSibling().toElement();
}
m_nbMediasToLoad.fetchAndAddAcquire( 1 );
newMediaLoadingAsked( path, uuid );
//FIXME: This is verry redondant...
if ( mediaAlreadyLoaded( path ) == true )
{
Media* media;
QHash<QUuid, Media*>::iterator it = m_medias.begin();
QHash<QUuid, Media*>::iterator end = m_medias.end();
for ( ; it != end; ++it )
{
if ( it.value()->getFileInfo()->absoluteFilePath() == path )
{
media = it.value();
media->setUuid( QUuid( uuid ) );
m_medias.erase( it );
m_medias[media->getUuid()] = media;
break ;
}
}
}
else
{
m_nbMediasToLoad.fetchAndAddAcquire( 1 );
newMediaLoadingAsked( path, uuid );
}
elem = elem.nextSibling().toElement();
}
}
......
......@@ -51,9 +51,10 @@ public:
private:
Library();
bool mediaAlreadyLoaded( const QString& filePath );
QHash<QUuid, Media*> m_medias;
QHash<QUuid, Clip*> m_clips;
QMutex m_mutex;
template <typename T>
T getElementByUuid( const QHash<QUuid, T>& container , const QUuid& uuid )
{
......
......@@ -224,3 +224,8 @@ Media::InputType Media::getInputType() const
{
return m_inputType;
}
void Media::setUuid( const QUuid& uuid )
{
m_uuid = uuid;
}
......@@ -116,6 +116,7 @@ public:
void setFps( float fps );
const QUuid& getUuid() const;
void setUuid( const QUuid& uuid );
FileType getFileType() const;
static const QString VideoExtensions;
......
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