[vlc-commits] qml: allow using different model in NetworkBrowseDisplay

Prince Gupta git at videolan.org
Mon Sep 28 14:01:29 CEST 2020


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Fri Sep 11 20:52:20 2020 +0530| [f2b6b9effe77bea1cec1983bdcd948b2efb43b17] | committer: Pierre Lamot

qml: allow using different model in NetworkBrowseDisplay

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f2b6b9effe77bea1cec1983bdcd948b2efb43b17
---

 modules/gui/qt/network/qml/NetworkBrowseDisplay.qml | 21 ++++++++++-----------
 modules/gui/qt/network/qml/NetworkDisplay.qml       | 14 ++++++++++----
 2 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
index 90e4138e57..6438a9d9a3 100644
--- a/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkBrowseDisplay.qml
@@ -32,16 +32,15 @@ import "qrc:///style/"
 Widgets.NavigableFocusScope {
     id: root
 
-    property alias tree: providerModel.tree
+    property var providerModel
+    property var tree
+    onTreeChanged: providerModel.tree = tree
     readonly property var currentIndex: view.currentItem.currentIndex
     //the index to "go to" when the view is loaded
     property var initialIndex: 0
 
-    NetworkMediaModel {
-        id: providerModel
-        ctx: mainctx
-        tree: undefined
-        onCountChanged: resetFocus()
+    function changeTree(new_tree) {
+        history.push(["mc", "network", { tree: new_tree }]);
     }
 
     Util.SelectableDelegateModel{
@@ -73,7 +72,7 @@ Widgets.NavigableFocusScope {
             var data = providerModel.getDataAt(index)
             if (data.type === NetworkMediaModel.TYPE_DIRECTORY
                     || data.type === NetworkMediaModel.TYPE_NODE)  {
-                history.push(["mc", "network", { tree: data.tree }]);
+                changeTree(data.tree)
             } else {
                 providerModel.addAndPlay( selectionModel.selectedIndexes )
             }
@@ -115,7 +114,7 @@ Widgets.NavigableFocusScope {
                         focus: true
                         iconTxt: providerModel.indexed ? VLCIcons.remove : VLCIcons.add
                         text:  providerModel.indexed ?  i18n.qtr("Remove from medialibrary") : i18n.qtr("Add to medialibrary")
-                        visible: !providerModel.is_on_provider_list && providerModel.canBeIndexed
+                        visible: !providerModel.is_on_provider_list && !!providerModel.canBeIndexed
                         onClicked: providerModel.indexed = !providerModel.indexed
 
                         Layout.preferredWidth: implicitWidth
@@ -147,7 +146,7 @@ Widgets.NavigableFocusScope {
 
                 onItemDoubleClicked: {
                     if (model.type === NetworkMediaModel.TYPE_NODE || model.type === NetworkMediaModel.TYPE_DIRECTORY)
-                        history.push( ["mc", "network", { tree: model.tree } ])
+                        changeTree(model.tree)
                     else
                         selectionModel.model.addAndPlay( index )
                 }
@@ -308,7 +307,7 @@ Widgets.NavigableFocusScope {
                         focus: true
                         iconTxt: providerModel.indexed ? VLCIcons.remove : VLCIcons.add
                         text:  providerModel.indexed ?  i18n.qtr("Remove from medialibrary") : i18n.qtr("Add to medialibrary")
-                        visible: !providerModel.is_on_provider_list && providerModel.canBeIndexed
+                        visible: !providerModel.is_on_provider_list && !!providerModel.canBeIndexed
                         onClicked: providerModel.indexed = !providerModel.indexed
 
                         Layout.preferredWidth: implicitWidth
@@ -333,7 +332,7 @@ Widgets.NavigableFocusScope {
             onActionForSelection: _actionAtIndex(selection[0].row)
             onItemDoubleClicked: {
                 if (model.type === NetworkMediaModel.TYPE_NODE || model.type === NetworkMediaModel.TYPE_DIRECTORY)
-                    history.push( ["mc", "network", { tree: model.tree } ])
+                    changeTree(model.tree)
                 else
                     providerModel.addAndPlay( index )
             }
diff --git a/modules/gui/qt/network/qml/NetworkDisplay.qml b/modules/gui/qt/network/qml/NetworkDisplay.qml
index 5e4877dc86..574d0d2150 100644
--- a/modules/gui/qt/network/qml/NetworkDisplay.qml
+++ b/modules/gui/qt/network/qml/NetworkDisplay.qml
@@ -42,14 +42,20 @@ Widgets.NavigableFocusScope {
 
     function loadView() {
         var page = "";
+        var props = undefined;
         if (root.tree === undefined)
             page ="qrc:///network/NetworkHomeDisplay.qml"
-        else
+        else {
             page = "qrc:///network/NetworkBrowseDisplay.qml"
-        view.replace(page)
-        if (root.tree) {
-            view.currentItem.tree = root.tree
+            props = { providerModel: mediaModel, tree: root.tree }
         }
+        view.replace(page, props)
+    }
+
+    NetworkMediaModel {
+        id: mediaModel
+
+        ctx: mainctx
     }
 
     Widgets.StackViewExt {



More information about the vlc-commits mailing list