[vlc-commits] qml: update Network contextual actions

Pierre Lamot git at videolan.org
Mon Oct 14 11:59:20 CEST 2019


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Thu Sep 19 15:44:58 2019 +0200| [c3c1ceb535239d29365fb4cd0839d20e70a07d7e] | committer: Jean-Baptiste Kempf

qml: update Network contextual actions

  action can now operate on the selection

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 .../gui/qt/qml/mediacenter/MCNetworkDisplay.qml    | 54 ++++++++++++++--------
 .../mediacenter/MCNetworksSectionSelectableDM.qml  | 42 +++++++++++++----
 2 files changed, 68 insertions(+), 28 deletions(-)

diff --git a/modules/gui/qt/qml/mediacenter/MCNetworkDisplay.qml b/modules/gui/qt/qml/mediacenter/MCNetworkDisplay.qml
index 6333489603..0ef1f6ba9f 100644
--- a/modules/gui/qt/qml/mediacenter/MCNetworkDisplay.qml
+++ b/modules/gui/qt/qml/mediacenter/MCNetworkDisplay.qml
@@ -32,40 +32,56 @@ Utils.NavigableFocusScope {
     property alias tree: providerModel.tree
     Utils.MenuExt {
         id: contextMenu
+        property var delegateModel: undefined
         property var model: ({})
-        property bool isIndexible: !contextMenu.model ? false : Boolean(contextMenu.model.can_index)
-        property bool isFileType: !contextMenu.model ? false : contextMenu.model.type === MLNetworkModel.TYPE_FILE
         closePolicy: Popup.CloseOnReleaseOutside | Popup.CloseOnEscape
         focus:true
 
         Instantiator {
             id: instanciator
-            function perform(id){
-                switch(id){
-                case 0: console.log("not implemented"); break;
-                case 1: contextMenu.model.indexed = !contextMenu.model.indexed; break;
-                default: console.log("unknown id:",id)
+            property var modelActions: {
+                "play": function() {
+                    if (delegateModel) {
+                        delegateModel.playSelection()
+                    }
+                    contextMenu.close()
+                },
+                "enqueue": function() {
+                    if (delegateModel)
+                        delegateModel.enqueueSelection()
+                    contextMenu.close()
+                },
+                "index": function(index) {
+                    contextMenu.model.indexed = contextMenu.model.indexed
+                    contextMenu.close()
                 }
-                contextMenu.close()
             }
-            model: [
-                {
-                    active: contextMenu.isFileType,
-                    text: qsTr("Play all"),
-                    performId: 0
-                },
-                {
-                    active: contextMenu.isIndexible,
-                    text: !contextMenu.model ? "" : contextMenu.model.indexed ? qsTr("Unindex") : qsTr("Index") ,
-                    performId: 1
+
+            model: [{
+                    active: true,
+                    text: qsTr("Play"),
+                    action: "play"
+                }, {
+                    active: true,
+                    text: qsTr("Enqueue"),
+                    action: "enqueue"
+                }, {
+                    active:  contextMenu.model && !!contextMenu.model.can_index,
+                    text: contextMenu.model && contextMenu.model.indexed ? qsTr("Unindex") : qsTr("Index"),
+                    action: "index"
                 }
             ]
+
             onObjectAdded: model[index].active && contextMenu.insertItem( index, object )
             onObjectRemoved: model[index].active && contextMenu.removeItem( object )
             delegate: Utils.MenuItemExt {
                 focus: true
                 text: modelData.text
-                onTriggered: instanciator.perform(modelData.performId)
+                onTriggered: {
+                    if (modelData.action && instanciator.modelActions[modelData.action]) {
+                        instanciator.modelActions[modelData.action]()
+                    }
+                }
             }
         }
 
diff --git a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
index 3bc5d3dc6d..bd9f0b5c63 100644
--- a/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
+++ b/modules/gui/qt/qml/mediacenter/MCNetworksSectionSelectableDM.qml
@@ -51,6 +51,7 @@ Utils.SelectableDelegateModel {
 
             onContextMenuButtonClicked: {
                 contextMenu.model = model
+                contextMenu.delegateModel = delegateModel
                 contextMenu.popup(menuParent)
             }
         }
@@ -75,6 +76,7 @@ Utils.SelectableDelegateModel {
 
             onContextMenuButtonClicked: {
                 contextMenu.model = model
+                contextMenu.delegateModel = delegateModel
                 contextMenu.popup(menuParent)
             }
 
@@ -84,22 +86,44 @@ Utils.SelectableDelegateModel {
 
     }
 
+    function switchIndex() {
+        var list = []
+        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
+            var obj = delegateModel.selectedGroup.get(i)
+            if (obj.model.can_index) {
+                console.log("index", obj.model.mrl, obj.model.indexed)
+                obj.model.indexed = !obj.model.indexed
+            }
+        }
+    }
+
+    function playSelection() {
+        var list = []
+        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
+            var mrl = delegateModel.selectedGroup.get(i).model.mrl;
+            list.push(mrl)
+        }
+        medialib.addAndPlay( list )
+    }
+
+    function enqueueSelection() {
+        var list = []
+        for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
+            var mrl = delegateModel.selectedGroup.get(i).model.mrl;
+            list.push(mrl)
+        }
+        medialib.addToPlaylist( list )
+    }
+
     function actionAtIndex(index) {
         if ( delegateModel.selectedGroup.count > 1 ) {
-            var list = []
-            for (var i = 0; i < delegateModel.selectedGroup.count; i++) {
-                var type = delegateModel.selectedGroup.get(i).model.type;
-                var mrl = delegateModel.selectedGroup.get(i).model.mrl;
-                if (type == MLNetworkModel.TYPE_FILE)
-                    list.push(mrl)
-            }
-            medialib.addAndPlay( list )
+            playSelection()
         } else {
             if (delegateModel.items.get(index).model.type === MLNetworkModel.TYPE_DIRECTORY
                     || delegateModel.items.get(index).model.type === MLNetworkModel.TYPE_NODE)  {
                 history.push(["mc", "network", { tree: delegateModel.items.get(index).model.tree }], History.Go);
             } else {
-                medialib.addAndPlay( delegateModel.items.get(index).model.mrl );
+                playSelection()
             }
         }
     }



More information about the vlc-commits mailing list