Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
7ebe532c by Ahmed Sobhy at 2026-02-13T15:45:20+00:00
qt: enhance item retrieval in NetworkDeviceModel to handle cache misses
- - - - -
70498565 by Ahmed Sobhy at 2026-02-13T15:45:20+00:00
qt: enhance item retrieval in NetworkMediaModel to handle cache misses
- - - - -
043460f1 by Ahmed Sobhy at 2026-02-13T15:45:20+00:00
qt: update getItemsForIndexes in NetworkDeviceModel to support asynchronous
callbacks
- - - - -
6b35275c by Ahmed Sobhy at 2026-02-13T15:45:20+00:00
qt: update getItemsForIndexes in NetworkMediaModel to support asynchronous
callbacks
- - - - -
79fc3824 by Ahmed Sobhy at 2026-02-13T15:45:20+00:00
qt: update getItemsForIndexes invocation to support new async callback
- - - - -
6 changed files:
- modules/gui/qt/menus/qml_menu_wrapper.cpp
- modules/gui/qt/network/networkdevicemodel.cpp
- modules/gui/qt/network/networkdevicemodel.hpp
- modules/gui/qt/network/networkmediamodel.cpp
- modules/gui/qt/network/networkmediamodel.hpp
- modules/gui/qt/network/qml/BrowseTreeDisplay.qml
Changes:
=====================================
modules/gui/qt/menus/qml_menu_wrapper.cpp
=====================================
@@ -781,7 +781,7 @@ void QmlAudioContextMenu::popup(const QPoint & position)
qt_intf_t* p_intf = m_ctx->getIntf();
if (!p_intf)
return;
-
+
m_menu.reset(PopupMenu(p_intf, false));
if (m_menu)
m_menu->popup(position);
@@ -939,16 +939,16 @@ void NetworkMediaContextMenu::popup(const
QModelIndexList& selected, QPoint pos)
connect(action, &QAction::triggered, [this, selected]( ) {
if (selected.isEmpty()) return;
- QVariantList items = m_model->getItemsForIndexes(selected);
+ m_model->getItemsForIndexes(selected, [](const QVariantList& items) {
+ if (items.isEmpty()) return;
- if (items.isEmpty()) return;
+ QVariant firstItem = items.first();
- QVariant firstItem = items.first();
-
- if (firstItem.canConvert<SharedInputItem>()) {
- SharedInputItem sii = firstItem.value<SharedInputItem>();
- DialogsProvider::getInstance()->mediaInfoDialog(sii);
- }
+ if (firstItem.canConvert<SharedInputItem>()) {
+ SharedInputItem sii = firstItem.value<SharedInputItem>();
+ DialogsProvider::getInstance()->mediaInfoDialog(sii);
+ }
+ });
});
bool canBeIndexed = false;
@@ -1008,16 +1008,16 @@ void NetworkDeviceContextMenu::popup(const
QModelIndexList& selected, QPoint pos
connect(action, &QAction::triggered, [this, selected]( ) {
if (selected.isEmpty()) return;
- QVariantList items = m_model->getItemsForIndexes(selected);
+ m_model->getItemsForIndexes(selected, [](const QVariantList& items) {
+ if (items.isEmpty()) return;
- if (items.isEmpty()) return;
+ QVariant firstItem = items.first();
- QVariant firstItem = items.first();
-
- if (firstItem.canConvert<SharedInputItem>()) {
- SharedInputItem sii = firstItem.value<SharedInputItem>();
- DialogsProvider::getInstance()->mediaInfoDialog(sii);
- }
+ if (firstItem.canConvert<SharedInputItem>()) {
+ SharedInputItem sii = firstItem.value<SharedInputItem>();
+ DialogsProvider::getInstance()->mediaInfoDialog(sii);
+ }
+ });
});
menu->popup(pos);
=====================================
modules/gui/qt/network/networkdevicemodel.cpp
=====================================
@@ -18,6 +18,8 @@
#include <unordered_set>
#include <QTimer>
+#include <QJSValue>
+#include <QQmlEngine>
#include "maininterface/mainctx.hpp"
@@ -599,19 +601,63 @@ bool NetworkDeviceModel::addAndPlay(const
QModelIndexList& itemIdList)
}
/* Q_INVOKABLE */
-QVariantList NetworkDeviceModel::getItemsForIndexes(const QModelIndexList &
indexes) const
+void NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & indexes,
QJSValue callback)
{
- Q_D(const NetworkDeviceModel);
- QVariantList items;
+ if (!callback.isCallable())
+ return;
+
+ getItemsForIndexes(indexes, [this, callback](const QVariantList& items)
mutable {
+ auto engine = qjsEngine(this);
+ if (engine)
+ callback.call({engine->toScriptValue(items)});
+ });
+}
+
+void NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & indexes,
std::function<void(const QVariantList&)> callback)
+{
+ Q_D(NetworkDeviceModel);
+
+ if (!callback)
+ return;
+
+ if (indexes.isEmpty())
+ {
+ callback(QVariantList());
+ return;
+ }
+ int maxIndex = 0;
for (const QModelIndex & modelIndex : indexes)
{
- const NetworkDeviceItem* item = d->getItemForRow(modelIndex.row());
- if (!item)
- continue;
+ if (modelIndex.row() > maxIndex)
+ maxIndex = modelIndex.row();
+ }
+
+ // check if we have loaded all items we need
+ unsigned int loaded = getLoadedCount();
+ unsigned int maximum = getMaximumCount();
+ unsigned int needed = static_cast<unsigned int>(maxIndex) + 1;
+
+ if (loaded >= needed || loaded >= maximum)
+ {
+ QVariantList items;
+ for (const QModelIndex & modelIndex : indexes)
+ {
+ const NetworkDeviceItem* item = d->getItemForRow(modelIndex.row());
+ if (!item)
+ continue;
+
+
items.append(QVariant::fromValue(SharedInputItem(item->getInputItem().get(),
true)));
+ }
-
items.append(QVariant::fromValue(SharedInputItem(item->getInputItem().get(),
true)));
+ callback(items);
+ return;
}
- return items;
+ // item() internally calls refer() to trigger cache loading for all items
till the max index
+ d->item(maxIndex);
+
+ connect(this, &NetworkDeviceModel::dataChanged, this, [this, indexes,
callback]() {
+ getItemsForIndexes(indexes, callback);
+ }, Qt::SingleShotConnection);
}
=====================================
modules/gui/qt/network/networkdevicemodel.hpp
=====================================
@@ -25,9 +25,11 @@
#include "networkbasemodel.hpp"
#include <memory>
+#include <functional>
Q_MOC_INCLUDE("maininterface/mainctx.hpp")
+class QJSValue;
class MainCtx;
class NetworkDeviceModelPrivate;
@@ -83,7 +85,8 @@ public:
Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
- Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList &
indexes) const;
+ Q_INVOKABLE void getItemsForIndexes(const QModelIndexList & indexes,
QJSValue callback);
+ void getItemsForIndexes(const QModelIndexList & indexes,
std::function<void(const QVariantList&)> callback);
signals:
void ctxChanged();
=====================================
modules/gui/qt/network/networkmediamodel.cpp
=====================================
@@ -34,6 +34,8 @@
#include <QSemaphore>
#include <QDateTime>
#include <QTimeZone>
+#include <QJSValue>
+#include <QQmlEngine>
namespace {
@@ -861,25 +863,66 @@ bool NetworkMediaModel::addAndPlay(const QModelIndexList&
itemIdList)
}
/* Q_INVOKABLE */
-QVariantList NetworkMediaModel::getItemsForIndexes(const QModelIndexList &
indexes) const
+void NetworkMediaModel::getItemsForIndexes(const QModelIndexList & indexes,
QJSValue callback)
{
- Q_D(const NetworkMediaModel);
- QVariantList items;
+ if (!callback.isCallable())
+ return;
+
+ getItemsForIndexes(indexes, [this, callback](const QVariantList& items)
mutable {
+ auto engine = qjsEngine(this);
+ if (engine)
+ callback.call({engine->toScriptValue(items)});
+ });
+}
+
+void NetworkMediaModel::getItemsForIndexes(const QModelIndexList & indexes,
std::function<void(const QVariantList&)> callback)
+{
+ Q_D(NetworkMediaModel);
+
+ if (!callback)
+ return;
+
+ if (indexes.isEmpty())
+ {
+ callback(QVariantList());
+ return;
+ }
+ int maxIndex = 0;
for (const QModelIndex & modelIndex : indexes)
{
- int index = modelIndex.row();
+ if (modelIndex.row() > maxIndex)
+ maxIndex = modelIndex.row();
+ }
- const NetworkMediaItem* item = d->getItemForRow(index);
- if (!item)
- return {};
+ // check if we have loaded all items we need in the cache
+ unsigned int loaded = getLoadedCount();
+ unsigned int maximum = getMaximumCount();
+ unsigned int needed = static_cast<unsigned int>(maxIndex) + 1;
+
+ if (loaded >= needed || loaded >= maximum)
+ {
+ QVariantList items;
+ for (const QModelIndex & modelIndex : indexes)
+ {
+ const NetworkMediaItem* item = d->getItemForRow(modelIndex.row());
+ if (!item)
+ continue;
- const NetworkTreeItem & tree = item->tree;
+ const NetworkTreeItem & tree = item->tree;
+ items.append(QVariant::fromValue(SharedInputItem(tree.media.get(),
true)));
+ }
- items.append(QVariant::fromValue(SharedInputItem(tree.media.get(),
true)));
+ callback(items);
+ return;
}
- return items;
+ // item() internally calls refer() to trigger cache loading for all items
till the max index
+ d->item(maxIndex);
+
+ connect(this, &NetworkMediaModel::dataChanged, this, [this, indexes,
callback]() {
+ getItemsForIndexes(indexes, callback);
+ }, Qt::SingleShotConnection);
}
MainCtx* NetworkMediaModel::getCtx() const {
=====================================
modules/gui/qt/network/networkmediamodel.hpp
=====================================
@@ -29,9 +29,11 @@
#include "networkbasemodel.hpp"
#include <memory>
+#include <functional>
Q_MOC_INCLUDE( "maininterface/mainctx.hpp" )
+class QJSValue;
class MainCtx;
class NetworkTreeItem
@@ -164,7 +166,8 @@ public:
Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
- Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList &
indexes) const;
+ Q_INVOKABLE void getItemsForIndexes(const QModelIndexList & indexes,
QJSValue callback);
+ void getItemsForIndexes(const QModelIndexList & indexes,
std::function<void(const QVariantList&)> callback);
signals:
void nameChanged();
=====================================
modules/gui/qt/network/qml/BrowseTreeDisplay.qml
=====================================
@@ -132,9 +132,7 @@ MainViewLoader {
}
onRequestInputItems: (indexes, data, resolve, reject) => {
- resolve(
- model.getItemsForIndexes(indexes)
- )
+ model.getItemsForIndexes(indexes, resolve)
}
}
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/cab07182b66e7512adf1655dc3a126b92024ad75...79fc3824fff5fe9f0961314719c06baca2879d73
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/cab07182b66e7512adf1655dc3a126b92024ad75...79fc3824fff5fe9f0961314719c06baca2879d73
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance_______________________________________________
vlc-commits mailing list
[email protected]
https://mailman.videolan.org/listinfo/vlc-commits