Commit e14eb6dc authored by luyikei's avatar luyikei

MediaLibraryModel: Avoid calling functions from the medialibrary thread

parent e67c4afa
......@@ -212,7 +212,9 @@ Library::onMediaAdded( std::vector<medialibrary::MediaPtr> mediaList )
{
for ( auto m : mediaList )
{
m_model->addMedia( m );
QMetaObject::invokeMethod( m_model, "addMedia",
Qt::QueuedConnection,
Q_ARG( medialibrary::MediaPtr, m ) );
}
}
......@@ -221,7 +223,9 @@ Library::onMediaUpdated( std::vector<medialibrary::MediaPtr> mediaList )
{
for ( auto m : mediaList )
{
m_model->updateMedia( m );
QMetaObject::invokeMethod( m_model, "updateMedia",
Qt::QueuedConnection,
Q_ARG( medialibrary::MediaPtr, m ) );
}
}
......@@ -229,7 +233,9 @@ void
Library::onMediaDeleted( std::vector<int64_t> mediaList )
{
for ( auto id : mediaList )
m_model->removeMedia( id );
QMetaObject::invokeMethod( m_model, "removeMedia",
Qt::QueuedConnection,
Q_ARG( int64_t, id ) );
}
void
......@@ -287,7 +293,8 @@ void
Library::onDiscoveryCompleted( const std::string& entryPoint )
{
if ( entryPoint.empty() == true )
m_model->refresh();
QMetaObject::invokeMethod( m_model, "refresh",
Qt::QueuedConnection );
emit discoveryCompleted( QString::fromStdString( entryPoint ) );
}
......@@ -324,10 +331,14 @@ Library::onReloadCompleted( const std::string& entryPoint )
if ( entryPoint.empty() == true )
{
for ( auto media : m_ml->videoFiles() )
m_model->addMedia( media );
QMetaObject::invokeMethod( m_model, "addMedia",
Qt::QueuedConnection,
Q_ARG( medialibrary::MediaPtr, media ) );
for ( auto media : m_ml->audioFiles() )
m_model->addMedia( media );
QMetaObject::invokeMethod( m_model, "addMedia",
Qt::QueuedConnection,
Q_ARG( medialibrary::MediaPtr, media ) );
}
}
......
......@@ -30,6 +30,7 @@ MediaLibraryModel::MediaLibraryModel( medialibrary::IMediaLibrary& ml, QObject *
, m_ml( ml )
, m_rowCount( 0 )
{
qRegisterMetaType<medialibrary::MediaPtr>();
}
void MediaLibraryModel::addMedia( medialibrary::MediaPtr media )
......
......@@ -46,16 +46,18 @@ public:
explicit MediaLibraryModel( medialibrary::IMediaLibrary& ml, QObject *parent = 0 );
void addMedia( medialibrary::MediaPtr media );
medialibrary::MediaPtr findMedia( qint64 mediaId );
void updateMedia( medialibrary::MediaPtr media );
bool removeMedia( int64_t media );
void refresh();
virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
virtual QHash<int, QByteArray> roleNames() const override;
public slots:
void addMedia( medialibrary::MediaPtr media );
void updateMedia( medialibrary::MediaPtr media );
bool removeMedia( int64_t media );
void refresh();
private:
medialibrary::IMediaLibrary& m_ml;
......
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