[vlc-devel] [PATCH 1/2] WIP/RFC: qt: handle multiple track selection

Thomas Guillem thomas at gllm.fr
Thu Jun 20 17:54:19 CEST 2019


Maybe we should iterate the track models data instead of the player directly.

cf. TODO comment.
---
 modules/gui/qt/util/input_models.cpp | 57 +++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/modules/gui/qt/util/input_models.cpp b/modules/gui/qt/util/input_models.cpp
index b740bfafb6..aefb76f982 100644
--- a/modules/gui/qt/util/input_models.cpp
+++ b/modules/gui/qt/util/input_models.cpp
@@ -62,7 +62,62 @@ bool TrackListModel::setData(const QModelIndex &index, const QVariant &value, in
     vlc_player_locker lock{ m_player };
 
     if (select)
-        vlc_player_SelectEsId(m_player, m_data[row].m_id.get());
+    {
+        static const unsigned max_tracks_by_cat[] = {
+            [UNKNOWN_ES] = 0,
+            [VIDEO_ES] = UINT_MAX /* TODO: 1 by default, and max if the user checked the multiple-tracks checkbox */,
+            [AUDIO_ES] = 1,
+            [SPU_ES] = 1 /* TODO: 2 if the user checked the multiple-tracks checkbox*/,
+            [DATA_ES] = 0,
+        };
+
+        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);
+        const unsigned max_tracks = max_tracks_by_cat[cat];
+
+        if (max_tracks == 1)
+        {
+            vlc_player_SelectEsId(m_player, es_id);
+            return true;
+        }
+        else if (max_tracks == 0)
+            return false;
+
+        const size_t track_count =
+            vlc_player_GetTrackCount(m_player, cat);
+
+        size_t selected_track_count = 1;
+        for (size_t i = 0; i < track_count; ++i)
+        {
+            const struct vlc_player_track *track =
+                vlc_player_GetTrackAt(m_player, cat, i);
+            if (track->selected && track->es_id != es_id)
+                selected_track_count++;
+        }
+
+        if (selected_track_count == 1)
+        {
+            vlc_player_SelectEsId(m_player, es_id);
+            return true;
+        }
+        vlc_es_id_t **es_id_list = static_cast<vlc_es_id_t **>(
+            vlc_alloc(selected_track_count + 1, sizeof(vlc_es_id_t*)));
+        if (!es_id_list)
+            return false;
+
+        size_t es_id_list_idx = 0;
+
+        for (size_t i = 0; i < track_count; ++i)
+        {
+            const struct vlc_player_track *track =
+                vlc_player_GetTrackAt(m_player, cat, i);
+            if (track->selected || track->es_id == es_id)
+                es_id_list[es_id_list_idx++] = track->es_id;
+        }
+        es_id_list[selected_track_count] = NULL;
+        vlc_player_SelectEsIdList(m_player, cat, es_id_list);
+        free(es_id_list);
+    }
     else
         vlc_player_UnselectEsId(m_player, m_data[row].m_id.get());
     return true;
-- 
2.20.1



More information about the vlc-devel mailing list