[vlc-commits] qt: add property to access full path in NetworkMediaModel
Prince Gupta
git at videolan.org
Fri Nov 27 14:52:19 CET 2020
vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Fri Nov 20 23:17:34 2020 +0530| [2566f73257c45ff960c43a8eba74f08c26587311] | committer: Pierre Lamot
qt: add property to access full path in NetworkMediaModel
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2566f73257c45ff960c43a8eba74f08c26587311
---
modules/gui/qt/network/networkmediamodel.cpp | 15 ++++++++++++++-
modules/gui/qt/network/networkmediamodel.hpp | 28 ++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index c41bf9ae38..92b34ef35d 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -314,18 +314,31 @@ bool NetworkMediaModel::initializeMediaSources()
{
input_item_node_t* mediaNode = nullptr;
+ input_item_node_t* parent = nullptr;
vlc_media_tree_Lock(tree);
vlc_media_tree_PreparseCancel( libvlc, this );
std::vector<InputItemPtr> itemList;
- if (vlc_media_tree_Find( tree, m_treeItem.media.get(), &mediaNode, nullptr))
+ m_path = {QVariant::fromValue(PathNode(m_treeItem, m_name))};
+ if (vlc_media_tree_Find( tree, m_treeItem.media.get(), &mediaNode, &parent))
{
itemList.reserve(mediaNode->i_children);
for (int i = 0; i < mediaNode->i_children; i++)
itemList.emplace_back(mediaNode->pp_children[i]->p_item);
+
+ while (parent && parent->p_item) {
+ m_path.push_front(QVariant::fromValue(PathNode(NetworkTreeItem(m_treeItem.source, parent->p_item), parent->p_item->psz_name)));
+ input_item_node_t *node = nullptr;
+ input_item_node_t *grandParent = nullptr;
+ if (!vlc_media_tree_Find( tree, parent->p_item, &node, &grandParent)) {
+ break;
+ }
+ parent = grandParent;
+ }
}
vlc_media_tree_Unlock(tree);
if (!itemList.empty())
refreshMediaList( m_treeItem.source, std::move( itemList ), true );
+ emit pathChanged();
}
m_preparseSem.acquire();
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index 776361d0c9..c12011ec5b 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -69,6 +69,30 @@ public:
InputItemPtr media;
};
+class PathNode
+{
+ Q_GADGET
+ Q_PROPERTY( QVariant tree READ getTree CONSTANT )
+ Q_PROPERTY( QString display READ getDisplay CONSTANT )
+
+public:
+ PathNode() = default;
+ PathNode( const NetworkTreeItem &tree, const QString &display )
+ : m_tree( QVariant::fromValue(tree) )
+ , m_display( display )
+ {
+ }
+
+ QVariant getTree() const { return m_tree; }
+ QString getDisplay() const { return m_display; }
+
+private:
+ const QVariant m_tree;
+ const QString m_display;
+};
+
+Q_DECLARE_METATYPE(PathNode)
+
class NetworkMediaModel : public QAbstractListModel, public NetworkSourceListener::SourceListenerCb
{
Q_OBJECT
@@ -101,6 +125,7 @@ public:
Q_PROPERTY(QmlMainContext* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged)
Q_PROPERTY(QVariant tree READ getTree WRITE setTree NOTIFY treeChanged)
+ Q_PROPERTY(QVariantList path READ getPath NOTIFY pathChanged)
Q_PROPERTY(QString name READ getName NOTIFY nameChanged)
Q_PROPERTY(QUrl url READ getUrl NOTIFY urlChanged)
@@ -127,6 +152,7 @@ public:
inline QmlMainContext* getCtx() const { return m_ctx; }
inline QVariant getTree() const { return QVariant::fromValue( m_treeItem); }
+ inline QVariantList getPath() const { return m_path; }
inline QString getName() const { return m_name; }
inline QUrl getUrl() const { return m_url; }
@@ -158,6 +184,7 @@ signals:
void treeChanged();
void isOnProviderListChanged();
void sdSourceChanged();
+ void pathChanged();
private:
struct Item
@@ -201,6 +228,7 @@ private:
bool m_hasTree = false;
NetworkTreeItem m_treeItem;
std::unique_ptr<NetworkSourceListener> m_listener;
+ QVariantList m_path;
};
#endif // MLNETWORKMEDIAMODEL_HPP
More information about the vlc-commits
mailing list