[vlc-devel] [PATCH 05/15] qt/playlist_controller: Add the 'insert' function

Benjamin Arnaud benjamin.arnaud at videolabs.io
Thu Mar 11 09:16:49 UTC 2021


---
 .../gui/qt/playlist/playlist_controller.cpp   | 19 +++++++++++++++++++
 .../gui/qt/playlist/playlist_controller.hpp   |  2 ++
 2 files changed, 21 insertions(+)

diff --git a/modules/gui/qt/playlist/playlist_controller.cpp b/modules/gui/qt/playlist/playlist_controller.cpp
index 671d98df2e..1d4f3da36c 100644
--- a/modules/gui/qt/playlist/playlist_controller.cpp
+++ b/modules/gui/qt/playlist/playlist_controller.cpp
@@ -24,6 +24,7 @@
 #include "playlist_controller_p.hpp"
 #include "vlc_player.h"
 #include "vlc_url.h"
+#include "util/qmlinputitem.hpp"
 #include <algorithm>
 #include <QVariant>
 #include <QDesktopServices>
@@ -441,6 +442,24 @@ PlaylistControllerModel::remove(const QVector<PlaylistItem> &items, ssize_t inde
         throw std::bad_alloc();
 }
 
+void
+PlaylistControllerModel::insert(int index, const QVariantList & items)
+{
+    QVector<vlc::playlist::Media> medias;
+
+    for (const QVariant & variant : items)
+    {
+        if (variant.canConvert<QmlInputItem>() == false)
+            continue;
+
+        const QmlInputItem & item = variant.value<QmlInputItem>();
+
+        medias.push_back(vlc::playlist::Media(item.item.get()));
+    }
+
+    insert(index, medias, false);
+}
+
 void
 PlaylistControllerModel::shuffle()
 {
diff --git a/modules/gui/qt/playlist/playlist_controller.hpp b/modules/gui/qt/playlist/playlist_controller.hpp
index 27e37c1082..5f069bd600 100644
--- a/modules/gui/qt/playlist/playlist_controller.hpp
+++ b/modules/gui/qt/playlist/playlist_controller.hpp
@@ -112,6 +112,8 @@ public:
     void move(const QVector<PlaylistItem> &, size_t target, ssize_t indexHint);
     void remove(const QVector<PlaylistItem> &, ssize_t indexHint);
 
+    Q_INVOKABLE void insert(int index, const QVariantList & items /* QList<QmlInputItem> */);
+
     Q_INVOKABLE void shuffle();
     void sort(const QVector<vlc_playlist_sort_criterion> &);
 
-- 
2.25.1



More information about the vlc-devel mailing list