[vlc-commits] qt/network*: Add the 'getItemsForIndexes' function
Benjamin Arnaud
git at videolan.org
Mon Mar 15 10:34:54 UTC 2021
vlc | branch: master | Benjamin Arnaud <benjamin.arnaud at videolabs.io> | Thu Mar 11 10:16:52 2021 +0100| [fa9868a48ed60c68e5c665db4e1fc32bdb2dcd05] | committer: Pierre Lamot
qt/network*: Add the 'getItemsForIndexes' function
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fa9868a48ed60c68e5c665db4e1fc32bdb2dcd05
---
modules/gui/qt/network/networkdevicemodel.cpp | 24 +++++++++++++++++++++++-
modules/gui/qt/network/networkdevicemodel.hpp | 2 ++
modules/gui/qt/network/networkmediamodel.cpp | 24 ++++++++++++++++++++++++
modules/gui/qt/network/networkmediamodel.hpp | 2 ++
4 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/modules/gui/qt/network/networkdevicemodel.cpp b/modules/gui/qt/network/networkdevicemodel.cpp
index 0c2c352962..358a3f685c 100644
--- a/modules/gui/qt/network/networkdevicemodel.cpp
+++ b/modules/gui/qt/network/networkdevicemodel.cpp
@@ -18,9 +18,9 @@
#include "networkdevicemodel.hpp"
#include "networkmediamodel.hpp"
-
#include "playlist/media.hpp"
#include "playlist/playlist_controller.hpp"
+#include "util/qmlinputitem.hpp"
NetworkDeviceModel::NetworkDeviceModel( QObject* parent )
: QAbstractListModel( parent )
@@ -230,6 +230,28 @@ QMap<QString, QVariant> NetworkDeviceModel::getDataAt(int idx)
return dataDict;
}
+/* Q_INVOKABLE */
+QVariantList NetworkDeviceModel::getItemsForIndexes(const QModelIndexList & indexes) const
+{
+ assert(m_ml);
+
+ QVariantList items;
+
+ for (const QModelIndex & modelIndex : indexes)
+ {
+ int index = modelIndex.row();
+
+ if (index < 0 || (size_t) index >= m_items.size())
+ continue;
+
+ QmlInputItem input(m_items[index].inputItem.get(), true);
+
+ items.append(QVariant::fromValue(input));
+ }
+
+ return items;
+}
+
bool NetworkDeviceModel::initializeMediaSources()
{
auto libvlc = vlc_object_instance(m_ctx->getIntf());
diff --git a/modules/gui/qt/network/networkdevicemodel.hpp b/modules/gui/qt/network/networkdevicemodel.hpp
index af43d46fee..f3f5ed2d46 100644
--- a/modules/gui/qt/network/networkdevicemodel.hpp
+++ b/modules/gui/qt/network/networkdevicemodel.hpp
@@ -108,6 +108,8 @@ public:
Q_INVOKABLE QMap<QString, QVariant> getDataAt(int index);
+ Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList & indexes) const;
+
signals:
void ctxChanged();
void sdSourceChanged();
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index e030db351f..603b6cf7bd 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -22,6 +22,7 @@
#include "playlist/media.hpp"
#include "playlist/playlist_controller.hpp"
+#include "util/qmlinputitem.hpp"
NetworkMediaModel::NetworkMediaModel( QObject* parent )
: QAbstractListModel( parent )
@@ -296,6 +297,29 @@ bool NetworkMediaModel::addAndPlay(const QModelIndexList& itemIdList)
return ret;
}
+/* Q_INVOKABLE */
+QVariantList NetworkMediaModel::getItemsForIndexes(const QModelIndexList & indexes) const
+{
+ assert(m_ml);
+
+ QVariantList items;
+
+ for (const QModelIndex & modelIndex : indexes)
+ {
+ int index = modelIndex.row();
+
+ if (index < 0 || (size_t) index >= m_items.size())
+ continue;
+
+ const NetworkTreeItem & tree = m_items[index].tree;
+
+ QmlInputItem input(tree.media.get(), true);
+
+ items.append(QVariant::fromValue(input));
+ }
+
+ return items;
+}
bool NetworkMediaModel::initializeMediaSources()
{
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index ff041d6656..36423e12a7 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -180,6 +180,8 @@ public:
Q_INVOKABLE bool addAndPlay(const QVariantList& itemIdList);
Q_INVOKABLE bool addAndPlay(const QModelIndexList& itemIdList);
+ Q_INVOKABLE QVariantList getItemsForIndexes(const QModelIndexList & indexes) const;
+
signals:
void nameChanged();
void urlChanged();
More information about the vlc-commits
mailing list