[multimedia/haruna] src: tracksmodel: add streamIndex and externalPath roles and set them in MpvItem
George Florea Bănuș <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 5ddfde0ad650959277075389670453f9b9a72ad2 by George Florea Bănuș, on behalf of M. Sadık Uğursoy.
Committed on 13/08/2026 at 20:57.
Pushed by georgefb into branch 'master'.
tracksmodel: add streamIndex and externalPath roles and set them in MpvItem
M +14 -5 src/models/tracksmodel.cpp
M +6 -1 src/models/tracksmodel.h
M +10 -0 src/mpv/mpvitem.cpp
https://invent.kde.org/multimedia/haruna/-/commit/5ddfde0ad650959277075389670453f9b9a72ad2
diff --git a/src/models/tracksmodel.cpp b/src/models/tracksmodel.cpp
index 98c1fbda..c2d9f607 100644
--- a/src/models/tracksmodel.cpp
+++ b/src/models/tracksmodel.cpp
@@ -43,6 +43,13 @@ QVariant TracksModel::data(const QModelIndex &index, int role) const
return item.title;
case CodecRole:
return item.codec;
+ case ExternalPathRole:
+ if (item.externalPath.has_value()) {
+ return item.externalPath.value();
+ }
+ return {};
+ case StreamIndexRole:
+ return item.streamIndex;
}
return {};
@@ -52,11 +59,13 @@ QHash<int, QByteArray> TracksModel::roleNames() const
{
// clang-format off
static QHash<int, QByteArray> roles{
- {IdRole, QByteArrayLiteral("trackId")},
- {TextRole, QByteArrayLiteral("displayText")},
- {LanguageRole, QByteArrayLiteral("language")},
- {TitleRole, QByteArrayLiteral("title")},
- {CodecRole, QByteArrayLiteral("codec")},
+ {IdRole, QByteArrayLiteral("trackId")},
+ {TextRole, QByteArrayLiteral("displayText")},
+ {LanguageRole, QByteArrayLiteral("language")},
+ {TitleRole, QByteArrayLiteral("title")},
+ {CodecRole, QByteArrayLiteral("codec")},
+ {ExternalPathRole, QByteArrayLiteral("externalPath")},
+ {StreamIndexRole, QByteArrayLiteral("streamIndex")},
};
// clang-format on
diff --git a/src/models/tracksmodel.h b/src/models/tracksmodel.h
index 90dc9232..39a54184 100644
--- a/src/models/tracksmodel.h
+++ b/src/models/tracksmodel.h
@@ -8,6 +8,7 @@
#define TRACKSMODEL_H
#include <QAbstractListModel>
+#include <QUrl>
#include <qqmlregistration.h>
using namespace Qt::StringLiterals;
@@ -17,6 +18,8 @@ struct Track {
QString lang;
QString title;
QString codec;
+ std::optional<QUrl> externalPath;
+ int streamIndex{-1};
QString display() const
{
@@ -51,7 +54,9 @@ public:
TextRole,
LanguageRole,
TitleRole,
- CodecRole
+ CodecRole,
+ ExternalPathRole,
+ StreamIndexRole,
};
Q_ENUM(Roles)
// clang-format on
diff --git a/src/mpv/mpvitem.cpp b/src/mpv/mpvitem.cpp
index c562bd25..0252bfce 100644
--- a/src/mpv/mpvitem.cpp
+++ b/src/mpv/mpvitem.cpp
@@ -552,6 +552,8 @@ void MpvItem::loadTracks(const QList<QVariant> &tracks)
QString{},
i18nc("@action The \"None\" subtitle track is used to clear/unset selected track", "None"),
QString{},
+ std::nullopt,
+ 0,
};
m_subtitleTracksModel->addTrack(noneTrack);
@@ -559,11 +561,19 @@ void MpvItem::loadTracks(const QList<QVariant> &tracks)
uint sr = 0;
for (const auto &item : tracks) {
const auto map = item.toMap();
+
Track track;
track.trackid = map.value(u"id"_s).toInt();
track.lang = map.value(u"lang"_s).toString();
track.title = map.value(u"title"_s).toString();
track.codec = map.value(u"codec"_s).toString();
+ track.streamIndex = map.value(u"ff-index"_s).toInt();
+ track.externalPath = std::nullopt;
+
+ auto externalPath = QUrl::fromUserInput(map[u"external-filename"_s].toString());
+ if (map[u"external"_s].toBool() && externalPath != m_currentUrl) {
+ track.externalPath = externalPath;
+ }
const auto type = map.value(u"type"_s).toString();
if (type == u"sub"_s) {