[vlc-commits] qt: add function to insert into playlist in medialib

Prince Gupta git at videolan.org
Thu Dec 10 09:34:43 UTC 2020


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Tue Nov 10 23:13:40 2020 +0530| [2ad44496e295b61539dafa22f5830809799ef203] | committer: Pierre Lamot

qt: add function to insert into playlist in medialib

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

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

 modules/gui/qt/medialibrary/medialib.cpp | 36 ++++++++++++++++++++++++++++++++
 modules/gui/qt/medialibrary/medialib.hpp |  1 +
 2 files changed, 37 insertions(+)

diff --git a/modules/gui/qt/medialibrary/medialib.cpp b/modules/gui/qt/medialibrary/medialib.cpp
index b482b32d59..fa5feeac8e 100644
--- a/modules/gui/qt/medialibrary/medialib.cpp
+++ b/modules/gui/qt/medialibrary/medialib.cpp
@@ -187,6 +187,42 @@ void MediaLib::addAndPlay(const QVariantList& itemIdList, const QStringList* opt
     }
 }
 
+void MediaLib::insertIntoPlaylist(const size_t index, const QVariantList &itemIds, const QStringList *options)
+{
+    QVector<vlc::playlist::Media> medias;
+    for ( const auto &id : itemIds )
+    {
+        if (!id.canConvert<MLItemId>())
+            continue;
+
+        const MLItemId itemId = id.value<MLItemId>();
+        if (itemId.id == 0)
+            continue;
+        if (itemId.type == VLC_ML_PARENT_UNKNOWN)
+        {
+            vlc::playlist::InputItemPtr item(vlc_ml_get_input_item( m_ml, itemId.id ), false);
+            if (item)
+                medias.push_back(vlc::playlist::Media(item.get(), options));
+        }
+        else
+        {
+            vlc_ml_query_params_t query;
+            memset(&query, 0, sizeof(vlc_ml_query_params_t));
+            ml_unique_ptr<vlc_ml_media_list_t> media_list(vlc_ml_list_media_of( m_ml, &query, itemId.type, itemId.id));
+            if (media_list == nullptr)
+                return;
+
+            auto mediaRange = ml_range_iterate<vlc_ml_media_t>( media_list );
+            std::transform(mediaRange.begin(), mediaRange.end(), std::back_inserter(medias), [&](vlc_ml_media_t& m) {
+                vlc::playlist::InputItemPtr item(vlc_ml_get_input_item( m_ml, m.i_id ), false);
+                return vlc::playlist::Media(item.get(), options);
+            });
+        }
+    }
+    if (!medias.isEmpty())
+        m_intf->p_sys->p_mainPlaylistController->insert( index, medias );
+}
+
 void MediaLib::reload()
 {
     vlc_ml_reload_folder( vlcMl(), nullptr );
diff --git a/modules/gui/qt/medialibrary/medialib.hpp b/modules/gui/qt/medialibrary/medialib.hpp
index e48aae5783..a029a8e581 100644
--- a/modules/gui/qt/medialibrary/medialib.hpp
+++ b/modules/gui/qt/medialibrary/medialib.hpp
@@ -56,6 +56,7 @@ public:
     Q_INVOKABLE void addAndPlay(const QString& mrl, const QStringList* options = nullptr);
     Q_INVOKABLE void addAndPlay(const QUrl& mrl, const QStringList* options = nullptr);
     Q_INVOKABLE void addAndPlay(const QVariantList&itemIdList, const QStringList* options = nullptr);
+    Q_INVOKABLE void insertIntoPlaylist(size_t index, const QVariantList &itemIds /*QList<MLParentId>*/, const QStringList *options = nullptr);
 
     Q_INVOKABLE void reload();
 



More information about the vlc-commits mailing list