From 1fdf9c9f7c7643b6b87084b170c1b68390ec27bd Mon Sep 17 00:00:00 2001 From: Pierre Lamot Date: Thu, 12 Sep 2024 10:30:37 +0200 Subject: [PATCH] qt: improve ml playlist insertion perceived reactivity 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 --- modules/gui/qt/medialibrary/mlplaylistmodel.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/gui/qt/medialibrary/mlplaylistmodel.cpp b/modules/gui/qt/medialibrary/mlplaylistmodel.cpp index aaf319ee22fe..54eaaf436b13 100644 --- a/modules/gui/qt/medialibrary/mlplaylistmodel.cpp +++ b/modules/gui/qt/medialibrary/mlplaylistmodel.cpp @@ -59,9 +59,12 @@ setTransactionPending(true); - m_mediaLib->runOnMLThread(this, + struct Ctx { + std::vector> medias; + }; + m_mediaLib->runOnMLThread(this, //ML thread - [medias, id, at](vlc_medialibrary_t* ml) { + [medias, id, at](vlc_medialibrary_t* ml, Ctx& ctx) { std::vector mediaIdList; for (const auto& media : medias) { @@ -77,8 +80,8 @@ if (ml_media == nullptr) continue; } - mediaIdList.push_back(ml_media->i_id); + ctx.medias.emplace_back(std::make_unique(ml_media)); vlc_ml_media_release(ml_media); } if (mediaIdList.size() == 0) @@ -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(); });