Commit 0a3274b4 authored by Geoffroy Lacarriere's avatar Geoffroy Lacarriere

Bug fix of crashes during deletion of metadata computing in the import menu

Securing delete media by using removeMedia method that delete the media when at the end of metadata computing
parent 285c30e1
......@@ -66,8 +66,10 @@ bool ImportMediaListController::contains( QUuid uuid )
void ImportMediaListController::removeMedia( const QUuid& uuid )
{
removeCell( m_mediaCellList->value( uuid ) );
ImportMediaCellView* cell = m_mediaCellList->value( uuid );
removeCell( cell );
m_mediaCellList->remove( uuid );
delete cell;
}
void ImportMediaListController::addClip( Clip* clip )
......
......@@ -113,17 +113,20 @@ void ImportController::newMediaLoaded( Media* media )
void ImportController::mediaSelection( const QUuid& uuid )
{
if ( !m_currentUuid.isNull() )
m_mediaListController->getCell( m_currentUuid )->setPalette( palette() );
QPalette p = m_mediaListController->getCell( uuid )->palette();
p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
m_mediaListController->getCell( uuid )->setPalette( p );
setUIMetaData( m_model->getMedia( uuid ) );
if ( uuid != m_currentUuid )
m_preview->stop();
emit mediaSelected( m_model->getMedia( uuid ) );
m_currentUuid = uuid;
if ( m_mediaListController->contains( uuid ) )
{
if ( !m_currentUuid.isNull() && m_mediaListController->contains( m_currentUuid ) )
m_mediaListController->getCell( m_currentUuid )->setPalette( palette() );
QPalette p = m_mediaListController->getCell( uuid )->palette();
p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
m_mediaListController->getCell( uuid )->setPalette( p );
setUIMetaData( m_model->getMedia( uuid ) );
if ( uuid != NULL && uuid != m_currentUuid )
m_preview->stop();
m_currentUuid = uuid;
emit mediaSelected( m_model->getMedia( uuid ) );
}
}
void ImportController::clipSelection( const QUuid& uuid )
......@@ -133,10 +136,14 @@ void ImportController::clipSelection( const QUuid& uuid )
void ImportController::updateMediaRequested( Media* media )
{
ImportMediaCellView* cell = m_mediaListController->getCell( media->getUuid() );
cell->setThumbnail( media->getSnapshot() );
cell->setLength( media->getLengthMS() );
if ( m_mediaListController->contains( media->getUuid() ) )
{
ImportMediaCellView* cell = m_mediaListController->getCell( media->getUuid() );
cell->setThumbnail( media->getSnapshot() );
cell->setLength( media->getLengthMS() );
}
}
void ImportController::setUIMetaData( Media* media )
{
if ( media != NULL )
......@@ -190,6 +197,7 @@ void ImportController::treeViewDoubleClicked( const QModelIndex& index )
void ImportController::reject()
{
m_preview->stop();
m_model->removeAllMedias();
done( Rejected );
}
......@@ -208,7 +216,8 @@ void ImportController::accept()
void ImportController::mediaDeletion( const QUuid& uuid )
{
m_mediaListController->removeMedia( uuid );
delete m_model->getMedias()->take( uuid );
m_model->removeMedia( uuid );
if ( uuid == m_currentUuid )
{
setUIMetaData( NULL );
......@@ -221,7 +230,7 @@ void ImportController::clipDeletion( const QUuid& uuid )
{
m_mediaListController->removeClip( uuid );
QUuid id;
foreach(id, m_model->getMedias()->keys() )
foreach( id, m_model->getMedias()->keys() )
{
Media* media = m_model->getMedias()->value( id );
if (media->clip( uuid) )
......
......@@ -51,7 +51,7 @@ class ImportController : public QDialog
void setUIMetaData( Media* media );
protected:
void changeEvent(QEvent *e);
void changeEvent( QEvent *e );
private:
Ui::ImportController* m_ui;
......
......@@ -86,7 +86,8 @@ void ImportModel::metaDataComputed( Media* media )
{
Media* media;
foreach( media, m_invalidMedias )
delete media;
removeMedia( media->getUuid() );
//delete media;
m_nbLoadedMedias = 0;
m_invalidMedias.clear();
return;
......@@ -94,7 +95,6 @@ void ImportModel::metaDataComputed( Media* media )
if ( m_nbLoadedMedias == m_loadingMedias )
{
qDebug() << "Finished";
if ( m_invalidMedias.count() > 0 )
{
QStringList list;
......@@ -102,7 +102,8 @@ void ImportModel::metaDataComputed( Media* media )
foreach( media, m_invalidMedias )
{
list.append( media->getFileName() );
delete media;
removeMedia( media->getUuid() );
//delete media;
}
QMessageBox::warning( NULL, QString( "Error!" ), QString( tr( "Error while loading media(s):\n%0" ) ).arg( list.join( QString("\n") ) ) );
m_invalidMedias.clear();
......@@ -114,14 +115,8 @@ void ImportModel::metaDataComputed( Media* media )
void ImportModel::snapshotComputed( Media *media )
{
disconnect( media, SIGNAL( snapshotComputed( Media* ) ), this, SLOT( snapshotComputed( 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;
if ( !m_invalidMedias.contains( media ) )
emit updateMediaRequested( media );
}
void ImportModel::loadMedia( Media* media )
......@@ -173,10 +168,22 @@ void ImportModel::loadFile( const QFileInfo& fileInfo, int loadingMed
}
}
void ImportModel::removeMedia( const QUuid& mediaId)
void ImportModel::removeMedia( const QUuid& mediaId )
{
m_medias->remove( mediaId );
deleteAllAddedMedias();
if ( m_medias->contains( mediaId ) && m_medias->value( mediaId )->getMetadata() == Media::ParsedWithAudioSpectrum )
delete m_medias->take( mediaId );
else
m_invalidMedias.append( m_medias->take( mediaId ) );
}
void ImportModel::audioSpectrumComputed( Media *media )
{
disconnect( media, SIGNAL( audioSpectrumComputed( Media* ) ), this, SLOT( audioSpectrumComputed( Media* ) ) );
if ( m_invalidMedias.contains( media ) )
{
m_invalidMedias.removeAll( media );
delete media;
}
}
void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clipId )
......@@ -187,15 +194,9 @@ void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clip
m_medias->value( mediaId )->removeClip( clipId );
}
void ImportModel::deleteAllAddedMedias()
void ImportModel::removeAllMedias()
{
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 ) );
}
removeMedia( id );
}
......@@ -51,7 +51,7 @@ public:
void removeClip( const QUuid& mediaId, const QUuid& clipId );
QHash<QUuid, Media*>* getMedias() const { return m_medias; }
void setFilter( const QStringList& filter ) { m_filters = filter; }
void deleteAllAddedMedias();
void removeAllMedias();
signals:
void newMediaLoaded( Media* media );
......
......@@ -71,5 +71,4 @@ void ListViewController::addCell( QWidget* cell )
void ListViewController::removeCell( QWidget* cell )
{
m_layout->removeWidget( cell );
delete cell;
}
......@@ -117,7 +117,6 @@ void MediaCellView::mouseMoveEvent( QMouseEvent* event )
mimeData->setData( "vlmc/uuid", m_uuid.toString().toAscii() );
QDrag* drag = new QDrag( this );
drag->setMimeData( mimeData );
drag->setPixmap( Library::getInstance()->getClip( m_uuid )->getParent()->getSnapshot().scaled( 100, 100, Qt::KeepAspectRatio ) );
drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
......
......@@ -35,13 +35,16 @@ void MediaListViewController::cellSelection( const QUuid& uuid )
if ( m_currentUuid == uuid )
return;
if ( !m_currentUuid.isNull() )
m_cells->value( m_currentUuid )->setPalette( m_cells->value( uuid )->palette() );
QPalette p = m_cells->value( uuid )->palette();
p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
m_cells->value( uuid )->setPalette( p );
m_currentUuid = uuid;
emit mediaSelected( Library::getInstance()->getMedia( uuid ) );
if ( m_cells->contains( uuid ) )
{
if ( !m_currentUuid.isNull() && m_cells->contains( m_currentUuid ) )
m_cells->value( m_currentUuid )->setPalette( m_cells->value( uuid )->palette() );
QPalette p = m_cells->value( uuid )->palette();
p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
m_cells->value( uuid )->setPalette( p );
m_currentUuid = uuid;
emit mediaSelected( Library::getInstance()->getMedia( uuid ) );
}
}
void MediaListViewController::mediaDeletion( const QUuid& uuid )
......
......@@ -24,7 +24,7 @@
#include "ImportController.h"
StackViewController::StackViewController( QWidget* parent, bool enableImport ) :
QWidget( parent ), m_importButton( NULL ), m_current( 0 )
QWidget( parent ), m_importButton( NULL ), m_current( 0 ), m_importController( NULL )
{
m_nav = new StackViewNavController( this );
......@@ -114,6 +114,8 @@ const ViewController* StackViewController::getCurrentViewController() const
void StackViewController::displayImportMenu()
{
ImportController* import = new ImportController( );
import->exec();
if ( m_importController != NULL )
delete m_importController;
m_importController = new ImportController();
m_importController->exec();
}
......@@ -33,6 +33,8 @@
#include "StackViewNavController.h"
#include "ViewController.h"
class ImportController;
class StackViewController : public QWidget
{
Q_OBJECT
......@@ -52,6 +54,7 @@ private:
QVBoxLayout* m_layout;
ViewController* m_current;
QStack<ViewController*>* m_controllerStack;
ImportController* m_importController;
public slots:
void previous();
......
......@@ -55,7 +55,29 @@ void Library::removingMediaAsked( const QUuid& uuid )
//and won't be abble to remove the ListViewMediaItem without it.
//delete *it;
m_medias.erase( it );
delete media;
//delete media;
deleteMedia( media );
}
void Library::deleteMedia( Media *media )
{
if ( media->getMetadata() == Media::ParsedWithAudioSpectrum )
delete media;
else
{
m_mediaToDelete.append( media );
connect( media, SIGNAL( audioSpectrumComputed( Media* ) ), this, SLOT( deleteMedia( Media* ) ) );
}
}
void Library::audioSpectrumComputed( Media *media )
{
disconnect( media, SIGNAL( audioSpectrumComputed( Media* ) ), this, SLOT( audioSpectrumComputed( Media* ) ) );
if ( m_mediaToDelete.contains( media ) )
{
m_mediaToDelete.removeAll( media );
delete media;
}
}
void Library::metaDataComputed( Media* media )
......@@ -80,11 +102,15 @@ void Library::addMedia( Media* media )
{
QUuid id;
foreach( id, m_medias.keys() )
{
qDebug() << m_medias.value( id )->getFileInfo()->filePath();
qDebug() << media->getFileInfo()->filePath();
if ( m_medias.value( id )->getFileInfo()->filePath() == media->getFileInfo()->filePath() )
{
delete media;
deleteMedia( media );
return;
}
}
m_medias[media->getUuid()] = media;
metaDataComputed( media );
}
......
......@@ -54,6 +54,7 @@ public:
* \param media The media to add.
*/
void addMedia( Media* media );
void deleteMedia( Media* media );
private:
Library();
......@@ -67,6 +68,7 @@ private:
QHash<QUuid, Media*> m_medias;
QHash<QUuid, Clip*> m_clips;
QList<Media*> m_mediaToDelete;
template <typename T>
T getElementByUuid( const QHash<QUuid, T>& container , const QUuid& uuid )
{
......@@ -89,6 +91,7 @@ public slots:
private slots:
void metaDataComputed( Media* );
void audioSpectrumComputed( Media* media );
signals:
void metadataRequired( Media* );
......
......@@ -33,7 +33,7 @@
#include "Media.h"
#include "Singleton.hpp"
#define DEFAULT_MAX_MEDIA_PLAYER 3
#define DEFAULT_MAX_MEDIA_PLAYER 1
class MetaDataManager : public QObject, public Singleton<MetaDataManager>
{
......
......@@ -63,7 +63,7 @@ void MetaDataWorker::compute()
m_media->addConstantParam( ":vout=dummy" );
m_mediaPlayer->setMedia( m_media->getVLCMedia() );
if ( m_type != Audio )
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( entrypointPlaying() ) );
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( entrypointPlaying() ), Qt::QueuedConnection );
m_mediaPlayer->play();
m_media->flushVolatileParameters();
}
......@@ -72,7 +72,7 @@ void MetaDataWorker::computeVideoMetaData()
{
//Disabling audio for this specific use of the media
m_media->addVolatileParam( ":no-audio", ":audio" );
connect( m_mediaPlayer, SIGNAL( lengthChanged() ), this, SLOT( entrypointLengthChanged() ) );
connect( m_mediaPlayer, SIGNAL( lengthChanged() ), this, SLOT( entrypointLengthChanged() ), Qt::QueuedConnection );
}
void MetaDataWorker::computeImageMetaData()
......
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