[vlc-commits] qt: allow multple subtitle selection from TrackListModel

Prince Gupta git at videolan.org
Fri Nov 6 16:00:47 CET 2020


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Sat Oct  3 00:01:03 2020 +0530| [fb15ff5acd2717a1a1801b3da56d2a5d0a121eec] | committer: Pierre Lamot

qt: allow multple subtitle selection from TrackListModel

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

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

 modules/gui/qt/player/input_models.cpp | 30 ++++++++++++++++++++++++++++--
 modules/gui/qt/player/input_models.hpp |  9 ++++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/player/input_models.cpp b/modules/gui/qt/player/input_models.cpp
index 3164ad845c..e45955a627 100644
--- a/modules/gui/qt/player/input_models.cpp
+++ b/modules/gui/qt/player/input_models.cpp
@@ -66,8 +66,8 @@ bool TrackListModel::setData(const QModelIndex &index, const QVariant &value, in
         vlc_es_id_t *es_id = m_data[row].m_id.get();
         const enum es_format_category_e cat = vlc_es_id_GetCat(es_id);
         enum vlc_player_select_policy policy =
-            cat == VIDEO_ES ? VLC_PLAYER_SELECT_SIMULTANEOUS
-                            : VLC_PLAYER_SELECT_EXCLUSIVE;
+            ( cat ==  VIDEO_ES ) || m_multiSelect ? VLC_PLAYER_SELECT_SIMULTANEOUS
+                                                  : VLC_PLAYER_SELECT_EXCLUSIVE;
         vlc_player_SelectEsId(m_player, es_id, policy);
     }
     else
@@ -153,6 +153,32 @@ QHash<int, QByteArray> TrackListModel::roleNames() const
     return roleNames;
 }
 
+void TrackListModel::setMultiSelect(bool multiSelect)
+{
+    if (m_multiSelect == multiSelect)
+        return;
+
+    m_multiSelect = multiSelect;
+    if ( !m_multiSelect && getCount() > 1 )
+    {
+        int firstSelectedIndex = -1;
+        for ( int i = 0; i < getCount(); i++ )
+        {
+            if ( data( index( i ), Qt::CheckStateRole ).toBool() )
+            {
+                if (firstSelectedIndex != -1)
+                    setData( index(i), false, Qt::CheckStateRole );
+                else
+                    firstSelectedIndex = i;
+            }
+        }
+
+        if ( firstSelectedIndex != -1 )
+            setData( index(firstSelectedIndex), true, Qt::CheckStateRole );
+    }
+    emit multiSelectChanged(m_multiSelect);
+}
+
 TrackListModel::Data::Data(const vlc_player_track *track_info)
     : m_title( qfu(track_info->name) )
     , m_id( track_info->es_id, true )
diff --git a/modules/gui/qt/player/input_models.hpp b/modules/gui/qt/player/input_models.hpp
index d8f9db5467..f1b6730450 100644
--- a/modules/gui/qt/player/input_models.hpp
+++ b/modules/gui/qt/player/input_models.hpp
@@ -45,7 +45,7 @@ class TrackListModel : public QAbstractListModel
 {
     Q_OBJECT
     Q_PROPERTY(int count READ getCount NOTIFY countChanged)
-
+    Q_PROPERTY(bool multiSelect READ getMultiSelect WRITE setMultiSelect NOTIFY multiSelectChanged)
 
 public:
     TrackListModel(vlc_player_t* player, QObject* parent = nullptr);
@@ -68,8 +68,14 @@ public:
 
     inline int getCount() const { return m_data.size(); }
 
+    inline bool getMultiSelect() const { return m_multiSelect; }
+
+public slots:
+    void setMultiSelect(bool multiSelect);
+
 signals:
     void countChanged();
+    void multiSelectChanged(bool multiSelect);
 
 private:
     vlc_player_t* m_player;
@@ -88,6 +94,7 @@ private:
         bool m_selected = false;
     };
     QList<Data> m_data;
+    bool m_multiSelect = false; // this only work for subtitles
 };
 
 /**



More information about the vlc-commits mailing list