Commit b678dc8e authored by Christophe Courtaut's avatar Christophe Courtaut

Splitted signals and handling media errors

parent bcf989a5
......@@ -23,6 +23,7 @@
#include <QDebug>
#include <QDir>
#include <QMessageBox>
#include "ImportModel.h"
......@@ -69,14 +70,42 @@ void ImportModel::cutClip( const QUuid& mediaId, const QUuid& clipId,
void ImportModel::metaDataComputed( Media* media )
{
static int mediaLoaded = 0;
disconnect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) );
if ( media->hasMetadata() )
{
m_medias->insert( media->getUuid(), media );
emit newMediaLoaded( media );
emit updateMediaRequested( media );
}
else
{
m_invalidMedias.append( media->getFileName() );
delete media;
}
mediaLoaded++;
qDebug() << mediaLoaded << m_loadingMedias;
if ( mediaLoaded == m_loadingMedias )
{
if ( m_invalidMedias.count() > 0 )
{
QMessageBox::warning( NULL, QString( "Error!" ), QString( tr( "Error while loading media(s):\n%0" ) ).arg( m_invalidMedias.join( QString("\n") ) ) );
m_invalidMedias.clear();
}
mediaLoaded = 0;
}
}
void ImportModel::snapshotComputed( Media *media )
{
disconnect( media, SIGNAL( snapshotComputed( Media* ) ), this, SLOT( snapshotComputed( Media* ) ) );
emit updateMediaRequested( media );
}
void ImportModel::loadMedia( Media* media )
{
m_medias->insert( media->getUuid(), media );
emit newMediaLoaded( media );
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) );
connect( media, SIGNAL( snapshotComputed(Media*) ), this, SLOT( snapshotComputed(Media*) ) );
m_metaDataWorker = new MetaDataWorker( media );
m_metaDataWorker->compute();
}
......@@ -90,12 +119,14 @@ bool ImportModel::mediaAlreadyLoaded( const QFileInfo& fileInfo )
return false;
}
void ImportModel::loadFile( const QFileInfo& fileInfo )
void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMedias )
{
Media* media;
if ( !fileInfo.isDir() )
{
if ( loadingMedias == 0)
m_loadingMedias = 1;
if ( !mediaAlreadyLoaded( fileInfo ) )
{
media = new Media( fileInfo.filePath() );
......@@ -108,8 +139,9 @@ void ImportModel::loadFile( const QFileInfo& fileInfo )
QFileInfoList list = dir.entryInfoList( m_filters );
QFileInfo file;
m_loadingMedias = list.count();
foreach( file, list )
loadFile( file );
loadFile( file, m_loadingMedias );
}
}
......
......@@ -45,7 +45,7 @@ public:
Clip* getClip( const QUuid& mediaId, const QUuid& clipId ) const;
void cutMedia( const QUuid& mediaId, int frame );
void cutClip( const QUuid& mediaId, const QUuid& clipId, int frame );
void loadFile( const QFileInfo& fileInfo );
void loadFile( const QFileInfo& fileInfo, int loadingMedias = 0 );
void removeMedia( const QUuid& mediaId );
void removeClip( const QUuid& mediaId, const QUuid& clipId );
QHash<QUuid, Media*>* getMedias() const { return m_medias; }
......@@ -59,12 +59,15 @@ private:
QHash<QUuid, Media*>* m_medias;
MetaDataWorker* m_metaDataWorker;
QStringList m_filters;
QStringList m_invalidMedias;
int m_loadingMedias;
void loadMedia( Media* media );
bool mediaAlreadyLoaded( const QFileInfo& fileInfo );
private slots:
void metaDataComputed( Media* media );
void snapshotComputed( Media* media );
};
#endif // IMPORTMODEL_H
......@@ -219,12 +219,17 @@ void Media::addAudioFrame( void* datas, unsigned char* buffer, si
// qDebug() << m_audioData.frameList.size();
}
void Media::emitMetaDataComputed()
void Media::emitMetaDataComputed( bool hasMetadata )
{
m_metadataParsed = true;
m_metadataParsed = hasMetadata;
emit metaDataComputed( this );
}
void Media::emitSnapshotComputed()
{
emit snapshotComputed( this );
}
Media::InputType Media::getInputType() const
{
return m_inputType;
......
......@@ -145,7 +145,8 @@ public:
void setMetaTags( const QStringList& tags );
bool matchMetaTag( const QString& tag ) const;
void emitMetaDataComputed();
void emitMetaDataComputed( bool hasMetadata );
void emitSnapshotComputed();
bool hasMetadata() const;
......@@ -182,6 +183,7 @@ protected:
signals:
void metaDataComputed( Media* );
void snapshotComputed( Media* );
};
#endif // CLIP_H__
......@@ -111,6 +111,7 @@ void MetaDataWorker::getMetaData()
}
m_currentMedia->setNbFrames( m_currentMedia->getLengthMS() / 1000 * m_currentMedia->getFps() );
m_currentMedia->emitMetaDataComputed( m_validity );
//Setting time for snapshot :
if ( m_currentMedia->getFileType() == Media::Video )
{
......@@ -118,13 +119,15 @@ void MetaDataWorker::getMetaData()
m_mediaPlayer->setTime( m_mediaPlayer->getLength() / 3 );
}
else
renderSnapshot();
connect( this, SIGNAL( snapshotRequested() ), this, SLOT( renderSnapshot() ) );
}
void MetaDataWorker::renderSnapshot()
{
if ( m_currentMedia->getFileType() == Media::Video )
disconnect( m_mediaPlayer, SIGNAL( positionChanged() ), this, SLOT( renderSnapshot() ) );
else
disconnect( this, SIGNAL( snapshotRequested() ), this, SLOT( renderSnapshot() ) );
if ( !m_validity )
return ;
QTemporaryFile tmp;
......@@ -153,7 +156,7 @@ void MetaDataWorker::setSnapshot()
disconnect( m_mediaPlayer, SIGNAL( snapshotTaken() ), this, SLOT( setSnapshot() ) );
m_currentMedia->emitMetaDataComputed();
m_currentMedia->emitSnapshotComputed();
//CHECKME:
//This is synchrone, but it may become asynchrone in the future...
......
......@@ -68,6 +68,9 @@ class MetaDataWorker : public QObject
bool m_mediaIsPlaying;
bool m_lengthHasChanged;
signals:
void snapshotRequested();
private slots:
void renderSnapshot();
void setSnapshot();
......
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