[vlc-commits] [Git][videolan/vlc][master] 2 commits: qt: properly manage multiple mlInputItem calls

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Apr 21 02:32:54 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
c2e202c7 by Fatih Uzunoglu at 2023-04-21T02:11:13+00:00
qt: properly manage multiple mlInputItem calls

- - - - -
8d930c56 by Fatih Uzunoglu at 2023-04-21T02:11:13+00:00
qml: early resolve DragItem input items

- - - - -


5 changed files:

- modules/gui/qt/medialibrary/medialib.cpp
- modules/gui/qt/medialibrary/medialib.hpp
- modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/widgets/qml/DragItem.qml


Changes:

=====================================
modules/gui/qt/medialibrary/medialib.cpp
=====================================
@@ -298,6 +298,26 @@ void MediaLib::mlInputItem(const QVariantList& variantList, QJSValue callback)
         return;
     }
 
+    auto it = m_inputItemQuery.find(variantList);
+
+    if (it == m_inputItemQuery.end())
+    {
+        it = m_inputItemQuery.insert(variantList, {callback});
+    }
+    else
+    {
+        // be patient
+
+        for (const auto& it2 : it.value())
+        {
+            if (callback.strictlyEquals(it2))
+                return;
+        }
+
+        it.value().push_back(callback); // FIXME: Use an ordered set
+        return;
+    }
+
     runOnMLThread<Ctx>(this,
     //ML thread
     [mlIdList](vlc_medialibrary_t* ml, Ctx& ctx){
@@ -326,7 +346,7 @@ void MediaLib::mlInputItem(const QVariantList& variantList, QJSValue callback)
         }
     },
     //UI thread
-    [this, callback](quint64, Ctx& ctx) mutable
+    [this, it](quint64, Ctx& ctx) mutable
     {
         auto jsEngine = qjsEngine(this);
         if (!jsEngine)
@@ -341,7 +361,12 @@ void MediaLib::mlInputItem(const QVariantList& variantList, QJSValue callback)
             i++;
         }
 
-        callback.call({jsArray});
+        for (auto cb : qAsConst(it.value())) // TODO: Qt 6 use const reference
+        {
+            cb.call({jsArray});
+        }
+
+        m_inputItemQuery.erase(it);
     });
 }
 


=====================================
modules/gui/qt/medialibrary/medialib.hpp
=====================================
@@ -218,6 +218,8 @@ private:
     quint64 m_taskId = 1;
     QMap<quint64, RunOnMLThreadBaseRunner*> m_runningTasks;
     QMultiMap<const QObject*, quint64> m_objectTasks;
+
+    QMap<QVariantList, QVector<QJSValue>> m_inputItemQuery;
 };
 
 class RunOnMLThreadBaseRunner : public QObject, public QRunnable


=====================================
modules/gui/qt/medialibrary/qml/PlaylistMedia.qml
=====================================
@@ -161,9 +161,13 @@ MainInterface.MainTableView {
 
         // NOTE: Dropping medialibrary content into the playlist.
         } else if (Helpers.isValidInstanceOf(item, Widgets.DragItem)) {
-            item.getSelectedInputItem(function(inputItems) {
-                model.insert(inputItems, destinationIndex)
-            })
+            if (item.inputItems) {
+                model.insert(item.inputItems, destinationIndex)
+            } else {
+                item.getSelectedInputItem(function(inputItems) {
+                    model.insert(inputItems, destinationIndex)
+                })
+            }
         }
 
         root.forceActiveFocus()


=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -102,13 +102,17 @@ Control {
 
         // NOTE: Dropping medialibrary content into the queue.
         } else if (Helpers.isValidInstanceOf(item, Widgets.DragItem)) {
-            item.getSelectedInputItem(function(inputItems) {
-                if (!Array.isArray(inputItems) || inputItems.length === 0) {
-                    console.warn("can't convert items to input items");
-                    return
-                }
-                mainPlaylistController.insert(index, inputItems, false)
-            })
+            if (item.inputItems) {
+                mainPlaylistController.insert(index, item.inputItems, false)
+            } else {
+                item.getSelectedInputItem(function(inputItems) {
+                    if (!Array.isArray(inputItems) || inputItems.length === 0) {
+                        console.warn("can't convert items to input items");
+                        return
+                    }
+                    mainPlaylistController.insert(index, inputItems, false)
+                })
+            }
 
         // NOTE: Dropping an external item (i.e. filesystem) into the queue.
         } else if (drop.hasUrls) {


=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -60,6 +60,8 @@ Item {
     // string => role
     property string titleRole: "title"
 
+    readonly property var inputItems: _inputItems
+
     function coversXPos(index) {
         return VLCStyle.margin_small + (coverSize / 3) * index;
     }
@@ -82,6 +84,8 @@ Item {
         if (!dragItem._active)
             return
 
+        Qt.callLater(dragItem.getSelectedInputItem, dragItem.setInputItems)
+
         var covers = []
         var titleList = []
 
@@ -107,6 +111,16 @@ Item {
         _title = titleList.join(",") + (indexes.length > _maxCovers ? "..." : "")
     }
 
+    function setInputItems(inputItems) {
+        if (!Array.isArray(inputItems) || inputItems.length === 0) {
+            console.warn("can't convert items to input items");
+            dragItem._inputItems = null
+            return
+        }
+
+        dragItem._inputItems = inputItems
+    }
+
     //---------------------------------------------------------------------------------------------
     // Private
 
@@ -118,6 +132,8 @@ Item {
 
     readonly property int _displayedCoversCount: Math.min(_indexesSize, _maxCovers + 1)
 
+    property var _inputItems
+
     property var _data: []
 
     property var _covers: []
@@ -131,6 +147,9 @@ Item {
         // TODO: Rework D&D positioning
         if (!Drag.active)
             x = y = -1
+
+        if (!Drag.active)
+            dragItem._inputItems = undefined
     }
 
     //---------------------------------------------------------------------------------------------



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b437cad5687aa36d6b5fe15a3f61e46e2bfb81ea...8d930c56700387bddc399872c69ec88b4c0c6387

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b437cad5687aa36d6b5fe15a3f61e46e2bfb81ea...8d930c56700387bddc399872c69ec88b4c0c6387
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list