Commit 8a464972 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Propagate media deletion to the model

parent afa06228
......@@ -118,8 +118,16 @@ void MediaLibrary::onMediaUpdated( std::vector<medialibrary::MediaPtr> mediaList
}
}
void MediaLibrary::onMediaDeleted( std::vector<int64_t> )
void MediaLibrary::onMediaDeleted( std::vector<int64_t> mediaList )
{
for ( auto id : mediaList )
{
// We can't know the media type, however ID are unique regardless of the type
// so we are sure that we will remove the correct media.
if ( m_videoModel->removeMedia( id ) == true )
continue;
m_audioModel->removeMedia( id );
}
}
void MediaLibrary::onArtistsAdded( std::vector<medialibrary::ArtistPtr> )
......
......@@ -71,22 +71,21 @@ void MediaLibraryModel::updateMedia( medialibrary::MediaPtr media )
emit dataChanged( m, m );
}
void MediaLibraryModel::removeMedia( medialibrary::MediaPtr media )
bool MediaLibraryModel::removeMedia( int64_t mediaId )
{
if ( media->type() != m_mediaType )
return;
std::lock_guard<std::mutex> lock( m_mediaMutex );
auto it = std::find_if( begin( m_media ), end( m_media ), [media](medialibrary::MediaPtr m) {
return m->id() == media->id();
auto it = std::find_if( begin( m_media ), end( m_media ), [mediaId](medialibrary::MediaPtr m) {
return m->id() == mediaId;
});
if ( it == end( m_media ) )
return;
return false;
auto idx = it - begin( m_media );
beginRemoveRows(QModelIndex(), idx, idx );
m_media.erase( it );
m_rowCount.fetch_sub( 1, std::memory_order_relaxed );
removeRow( idx );
endRemoveRows();
return true;
}
int MediaLibraryModel::rowCount( const QModelIndex& ) const
......
......@@ -48,7 +48,7 @@ public:
void addMedia( medialibrary::MediaPtr media );
void updateMedia( medialibrary::MediaPtr media );
void removeMedia( medialibrary::MediaPtr media );
bool removeMedia( int64_t media );
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
QHash<int, QByteArray> roleNames() const;
......
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