Commit 9c09dc17 authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Buxfix of the progress bar

parent acc20b2b
...@@ -30,14 +30,14 @@ ...@@ -30,14 +30,14 @@
ImportModel::ImportModel() ImportModel::ImportModel()
{ {
m_medias = new QHash<QUuid, Media*>(); m_medias = new QHash<QUuid, Media*>();
m_progressDialog = new QProgressDialog("Importing files...", "Cancel", 0, m_loadingMedias, NULL);
m_progressDialog->setWindowModality( Qt::WindowModal );
m_progressDialog->setMinimumDuration( 1000 );
m_nbLoadedMedias = 0;
} }
ImportModel::~ImportModel() ImportModel::~ImportModel()
{ {
QUuid id;
foreach ( id, m_medias->keys() )
delete m_medias->value( id );
} }
Media* ImportModel::getMedia( const QUuid& mediaId ) const Media* ImportModel::getMedia( const QUuid& mediaId ) const
...@@ -79,10 +79,8 @@ void ImportModel::metaDataComputed( Media* media ) ...@@ -79,10 +79,8 @@ void ImportModel::metaDataComputed( Media* media )
} }
else else
m_invalidMedias.append( media ); m_invalidMedias.append( media );
m_nbLoadedMedias++;
m_progressDialog->setValue( ++m_nbLoadedMedias );
m_progressDialog->setValue( m_nbLoadedMedias );
if( m_progressDialog->wasCanceled() ) if( m_progressDialog->wasCanceled() )
{ {
...@@ -96,6 +94,7 @@ void ImportModel::metaDataComputed( Media* media ) ...@@ -96,6 +94,7 @@ void ImportModel::metaDataComputed( Media* media )
if ( m_nbLoadedMedias == m_loadingMedias ) if ( m_nbLoadedMedias == m_loadingMedias )
{ {
qDebug() << "Finished";
if ( m_invalidMedias.count() > 0 ) if ( m_invalidMedias.count() > 0 )
{ {
QStringList list; QStringList list;
...@@ -118,10 +117,18 @@ void ImportModel::snapshotComputed( Media *media ) ...@@ -118,10 +117,18 @@ void ImportModel::snapshotComputed( Media *media )
emit updateMediaRequested( media ); emit updateMediaRequested( media );
} }
void ImportModel::audioSpectrumComputed( Media *media )
{
disconnect( media, SIGNAL( audioSpectrumComputed( Media* ) ), this, SLOT( audioSpectrumComputed( Media* ) ) );
if ( m_invalidMedias.contains( media ) )
delete media;
}
void ImportModel::loadMedia( Media* media ) void ImportModel::loadMedia( Media* media )
{ {
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) ); connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) );
connect( media, SIGNAL( snapshotComputed(Media*) ), this, SLOT( snapshotComputed(Media*) ) ); connect( media, SIGNAL( snapshotComputed(Media*) ), this, SLOT( snapshotComputed(Media*) ) );
connect( media, SIGNAL( audioSpectrumComputed( Media* ) ), this, SLOT( audioSpectrumComputed(Media*) ) );
MetaDataManager::getInstance()->computeMediaMetadata( media ); MetaDataManager::getInstance()->computeMediaMetadata( media );
} }
...@@ -140,22 +147,16 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed ...@@ -140,22 +147,16 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed
if ( !fileInfo.isDir() ) if ( !fileInfo.isDir() )
{ {
if ( loadingMedias == 0) if ( loadingMedias == 1 )
{ m_progressDialog->setMaximum( 1 );
m_loadingMedias = 1;
m_progressDialog = new QProgressDialog("Importing files...", "Cancel", 0, m_loadingMedias, NULL);
m_progressDialog->setWindowModality( Qt::WindowModal );
m_progressDialog->setMinimumDuration( 1000 );
m_progressDialog->setValue( 0 );
m_nbLoadedMedias = 0;
}
if ( !mediaAlreadyLoaded( fileInfo ) ) if ( !mediaAlreadyLoaded( fileInfo ) )
{ {
media = new Media( fileInfo.filePath() ); media = new Media( fileInfo.filePath() );
loadMedia( media ); loadMedia( media );
} }
else else
m_nbLoadedMedias++; m_progressDialog->setValue( ++m_nbLoadedMedias );
} }
else else
{ {
...@@ -165,10 +166,8 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed ...@@ -165,10 +166,8 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed
m_loadingMedias = list.count(); m_loadingMedias = list.count();
m_nbLoadedMedias = 0; m_nbLoadedMedias = 0;
m_progressDialog = new QProgressDialog("Importing files...", "Cancel", 0, m_loadingMedias, NULL);
m_progressDialog->setWindowModality(Qt::WindowModal);
m_progressDialog->setMinimumDuration( 1000 );
m_progressDialog->setValue( 0 ); m_progressDialog->setValue( 0 );
m_progressDialog->setMaximum( m_loadingMedias );
foreach( file, list ) foreach( file, list )
loadFile( file, m_loadingMedias ); loadFile( file, m_loadingMedias );
} }
...@@ -177,6 +176,7 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed ...@@ -177,6 +176,7 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed
void ImportModel::removeMedia( const QUuid& mediaId) void ImportModel::removeMedia( const QUuid& mediaId)
{ {
m_medias->remove( mediaId ); m_medias->remove( mediaId );
deleteAllAddedMedias();
} }
void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clipId ) void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clipId )
...@@ -186,3 +186,16 @@ void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clip ...@@ -186,3 +186,16 @@ void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clip
m_medias->value( mediaId )->removeClip( clipId ); m_medias->value( mediaId )->removeClip( clipId );
} }
void ImportModel::deleteAllAddedMedias()
{
m_invalidMedias.clear();
QUuid id;
foreach( id, m_medias->keys() )
{
if ( m_medias->value( id )->getMetadata() == Media::ParsedWithAudioSpectrum )
delete m_medias->value( id );
else
m_invalidMedias.append( m_medias->value( id ) );
}
}
...@@ -46,11 +46,12 @@ public: ...@@ -46,11 +46,12 @@ public:
Clip* getClip( const QUuid& mediaId, const QUuid& clipId ) const; Clip* getClip( const QUuid& mediaId, const QUuid& clipId ) const;
void cutMedia( const QUuid& mediaId, int frame ); void cutMedia( const QUuid& mediaId, int frame );
void cutClip( const QUuid& mediaId, const QUuid& clipId, int frame ); void cutClip( const QUuid& mediaId, const QUuid& clipId, int frame );
void loadFile( const QFileInfo& fileInfo, int loadingMedias = 0 ); void loadFile( const QFileInfo& fileInfo, int loadingMedias = 1 );
void removeMedia( const QUuid& mediaId ); void removeMedia( const QUuid& mediaId );
void removeClip( const QUuid& mediaId, const QUuid& clipId ); void removeClip( const QUuid& mediaId, const QUuid& clipId );
QHash<QUuid, Media*>* getMedias() const { return m_medias; } QHash<QUuid, Media*>* getMedias() const { return m_medias; }
void setFilter( const QStringList& filter ) { m_filters = filter; } void setFilter( const QStringList& filter ) { m_filters = filter; }
void deleteAllAddedMedias();
signals: signals:
void newMediaLoaded( Media* media ); void newMediaLoaded( Media* media );
...@@ -70,6 +71,7 @@ private: ...@@ -70,6 +71,7 @@ private:
private slots: private slots:
void metaDataComputed( Media* media ); void metaDataComputed( Media* media );
void snapshotComputed( Media* media ); void snapshotComputed( Media* media );
void audioSpectrumComputed( Media* media );
}; };
#endif // IMPORTMODEL_H #endif // IMPORTMODEL_H
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