diff --git a/modules/gui/qt/medialibrary/mlbasemodel.cpp b/modules/gui/qt/medialibrary/mlbasemodel.cpp index 5af3cd3916c0f70f94bed9509821309b11d72df1..7a922d009927b915b9f15bef48b869ef56a5b7f8 100644 --- a/modules/gui/qt/medialibrary/mlbasemodel.cpp +++ b/modules/gui/qt/medialibrary/mlbasemodel.cpp @@ -408,19 +408,37 @@ void MLBaseModel::invalidateCache() m_cache.reset(); } +//------------------------------------------------------------------------------------------------- + MLItem *MLBaseModel::item(int signedidx) const { validateCache(); ssize_t count = m_cache->count(); - if (count == COUNT_UNINITIALIZED || signedidx < 0 - || signedidx >= count) + + if (count == COUNT_UNINITIALIZED || signedidx < 0 || signedidx >= count) return nullptr; unsigned int idx = static_cast<unsigned int>(signedidx); + m_cache->refer(idx); const std::unique_ptr<MLItem> *item = m_cache->get(idx); + + if (!item) + /* Not in cache */ + return nullptr; + + /* Return raw pointer */ + return item->get(); +} + +MLItem *MLBaseModel::itemCache(int signedidx) const +{ + unsigned int idx = static_cast<unsigned int>(signedidx); + + const std::unique_ptr<MLItem> *item = m_cache->get(idx); + if (!item) /* Not in cache */ return nullptr; @@ -429,6 +447,8 @@ MLItem *MLBaseModel::item(int signedidx) const return item->get(); } +//------------------------------------------------------------------------------------------------- + MLBaseModel::BaseLoader::BaseLoader(vlc_medialibrary_t *ml, MLItemId parent, QString searchPattern, vlc_ml_sorting_criteria_t sort, bool sort_desc) : m_ml(ml) diff --git a/modules/gui/qt/medialibrary/mlbasemodel.hpp b/modules/gui/qt/medialibrary/mlbasemodel.hpp index 2c54681a4574ce34c7fe83a16d5782da2f140cfb..72a9adeeebf33ebea8e2621c414ac4cbc5cfe42d 100644 --- a/modules/gui/qt/medialibrary/mlbasemodel.hpp +++ b/modules/gui/qt/medialibrary/mlbasemodel.hpp @@ -107,7 +107,12 @@ protected: void validateCache() const; void invalidateCache(); - MLItem* item(int signedidx) const; + + MLItem *item(int signedidx) const; + + // NOTE: This is faster because it only returns items available in cache. + MLItem *itemCache(int signedidx) const; + virtual void onVlcMlEvent( const MLEvent &event ); virtual ListCacheLoader<std::unique_ptr<MLItem>> *createLoader() const = 0;