Skip to content

Commit

Permalink
qt: improve ml playlist insertion perceived reactivity
Browse files Browse the repository at this point in the history
As we have the element content when inserting them in the library, so we can
insert them "a priori" in our cache and update the interface before the
medialibrary notifies us with the actual content ("a posteriori"). If assumption
was wrong, diffutil will correct it
  • Loading branch information
chubinou authored and robUx4 committed Oct 2, 2024
1 parent 4161e99 commit 1fdf9c9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions modules/gui/qt/medialibrary/mlplaylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@

setTransactionPending(true);

m_mediaLib->runOnMLThread(this,
struct Ctx {
std::vector<std::unique_ptr<MLItem>> medias;
};
m_mediaLib->runOnMLThread<Ctx>(this,
//ML thread
[medias, id, at](vlc_medialibrary_t* ml) {
[medias, id, at](vlc_medialibrary_t* ml, Ctx& ctx) {
std::vector<int64_t> mediaIdList;
for (const auto& media : medias)
{
Expand All @@ -77,8 +80,8 @@
if (ml_media == nullptr)
continue;
}

mediaIdList.push_back(ml_media->i_id);
ctx.medias.emplace_back(std::make_unique<MLPlaylistMedia>(ml_media));
vlc_ml_media_release(ml_media);
}
if (mediaIdList.size() == 0)
Expand All @@ -87,7 +90,8 @@
vlc_ml_playlist_insert(ml, id, mediaIdList.data(), mediaIdList.size(), at);
},
//UI thread
[this]() {
[this, at](quint64, Ctx& ctx) {
insertItemListInCache(std::move(ctx.medias), at);
m_need_reset = true;
endTransaction();
});
Expand Down

0 comments on commit 1fdf9c9

Please sign in to comment.