[vlc-devel] [PATCH 03/16] qt: add functions to insert into playlist in network models

Prince Gupta guptaprince8832 at gmail.com
Fri Dec 4 12:19:00 CET 2020


---
 modules/gui/qt/network/networkdevicemodel.cpp | 21 ++++++++++++++++
 modules/gui/qt/network/networkdevicemodel.hpp |  1 +
 modules/gui/qt/network/networkmediamodel.cpp  | 25 +++++++++++++++++--
 modules/gui/qt/network/networkmediamodel.hpp  |  1 +
 4 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/modules/gui/qt/network/networkdevicemodel.cpp b/modules/gui/qt/network/networkdevicemodel.cpp
index 281b236660..0c2c352962 100644
--- a/modules/gui/qt/network/networkdevicemodel.cpp
+++ b/modules/gui/qt/network/networkdevicemodel.cpp
@@ -115,6 +115,27 @@ int NetworkDeviceModel::getCount() const
     return static_cast<int>( m_items.size() );
 }
 
+bool NetworkDeviceModel::insertIntoPlaylist(const QModelIndexList &itemIdList, ssize_t playlistIndex)
+{
+    if (!(m_ctx && m_sdSource != CAT_MYCOMPUTER))
+        return false;
+    QVector<vlc::playlist::Media> medias;
+    medias.reserve( itemIdList.size() );
+    for ( const QModelIndex &id : itemIdList )
+    {
+        if ( !id.isValid() )
+            continue;
+        const int index = id.row();
+        if ( index < 0 || (size_t)index >= m_items.size() )
+            continue;
+
+        medias.append( vlc::playlist::Media {m_items[index].inputItem.get()} );
+    }
+    if (medias.isEmpty())
+        return false;
+    m_ctx->getIntf()->p_sys->p_mainPlaylistController->insert(playlistIndex, medias, false);
+    return true;
+}
 
 bool NetworkDeviceModel::addToPlaylist(int index)
 {
diff --git a/modules/gui/qt/network/networkdevicemodel.hpp b/modules/gui/qt/network/networkdevicemodel.hpp
index 18ab61aa92..af43d46fee 100644
--- a/modules/gui/qt/network/networkdevicemodel.hpp
+++ b/modules/gui/qt/network/networkdevicemodel.hpp
@@ -98,6 +98,7 @@ public:
 
     int getCount() const;
 
+    Q_INVOKABLE bool insertIntoPlaylist( const QModelIndexList& itemIdList, ssize_t playlistIndex );
     Q_INVOKABLE bool addToPlaylist( int index );
     Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
     Q_INVOKABLE bool addToPlaylist(const QModelIndexList& itemIdList);
diff --git a/modules/gui/qt/network/networkmediamodel.cpp b/modules/gui/qt/network/networkmediamodel.cpp
index 92b34ef35d..e030db351f 100644
--- a/modules/gui/qt/network/networkmediamodel.cpp
+++ b/modules/gui/qt/network/networkmediamodel.cpp
@@ -101,7 +101,6 @@ QMap<QString, QVariant> NetworkMediaModel::getDataAt(int idx)
     return dataDict;
 }
 
-
 int NetworkMediaModel::rowCount(const QModelIndex& parent) const
 {
     if ( parent.isValid() )
@@ -182,7 +181,29 @@ void NetworkMediaModel::setTree(QVariant parentTree)
     emit treeChanged();
 }
 
-bool NetworkMediaModel::addToPlaylist(int index)
+bool NetworkMediaModel::insertIntoPlaylist(const QModelIndexList &itemIdList, const ssize_t playlistIndex)
+{
+    if (!(m_ctx && m_hasTree))
+        return false;
+    QVector<vlc::playlist::Media> medias;
+    medias.reserve( itemIdList.size() );
+    for ( const QModelIndex &id : itemIdList )
+    {
+        if ( !id.isValid() )
+            continue;
+        const int index = id.row();
+        if ( index < 0 || (size_t)index >= m_items.size() )
+            continue;
+
+        medias.append( vlc::playlist::Media {m_items[index].tree.media.get()} );
+    }
+    if (medias.isEmpty())
+        return false;
+    m_ctx->getIntf()->p_sys->p_mainPlaylistController->insert(playlistIndex, medias, false);
+    return true;
+}
+
+bool NetworkMediaModel::addToPlaylist(const int index)
 {
     if (!(m_ctx && m_hasTree))
         return false;
diff --git a/modules/gui/qt/network/networkmediamodel.hpp b/modules/gui/qt/network/networkmediamodel.hpp
index 1d36047188..ff041d6656 100644
--- a/modules/gui/qt/network/networkmediamodel.hpp
+++ b/modules/gui/qt/network/networkmediamodel.hpp
@@ -172,6 +172,7 @@ public:
 
     Q_INVOKABLE QMap<QString, QVariant> getDataAt(int idx);
 
+    Q_INVOKABLE bool insertIntoPlaylist( const QModelIndexList& itemIdList, ssize_t playlistIndex );
     Q_INVOKABLE bool addToPlaylist( int index );
     Q_INVOKABLE bool addToPlaylist(const QVariantList& itemIdList);
     Q_INVOKABLE bool addToPlaylist(const QModelIndexList& itemIdList);
-- 
2.25.1



More information about the vlc-devel mailing list