feat: show only the translated subtitle once translation finishes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
triandClaude Opus 5.5 committed 2026-10-28 00:17:34 +07:00
1 parent 6b5742b2ca
commit 169cb1360b
5 files changed
+22 -15

No files matched your search

+13 -7
View File
@@ -194,7 +194,7 @@ void MpvItem::addSubtitleFile(const QUrl &url)
commandAsync(QStringList{QStringLiteral("sub-add"), localPathOrUrl(url), QStringLiteral("select")});
}
void MpvItem::showSecondarySubtitleFile(const QUrl &url, const QString &title)
void MpvItem::showTranslatedSubtitleFile(const QUrl &url, const QString &title)
{
if (!url.isValid()) {
return;
@@ -203,15 +203,21 @@ void MpvItem::showSecondarySubtitleFile(const QUrl &url, const QString &title)
for (const QVariant &entry : std::as_const(m_subtitleTracks)) {
const QVariantMap track = entry.toMap();
if (track.value(QStringLiteral("externalFilename")).toString() == path) {
setSecondarySubtitleId(track.value(QStringLiteral("id")).toInt());
showOnlySubtitle(track.value(QStringLiteral("id")).toInt());
return;
}
}
// "auto" adds the track without selecting it; updateTracks() selects it as secondary.
m_pendingSecondaryPath = path;
// "auto" adds the track without selecting it; updateTracks() selects it once mpv lists it.
m_pendingTranslatedPath = path;
commandAsync(QStringList{QStringLiteral("sub-add"), path, QStringLiteral("auto"), title});
}
void MpvItem::showOnlySubtitle(int id)
{
setSubtitleId(id);
setSecondarySubtitleId(0);
}
void MpvItem::showText(const QString &text)
{
commandAsync(QStringList{QStringLiteral("show-text"), text});
@@ -330,9 +336,9 @@ void MpvItem::updateTracks(const QVariantList &trackList)
{QStringLiteral("ffIndex"), track.value(QStringLiteral("ff-index"), -1).toInt()},
});
if (!m_pendingSecondaryPath.isEmpty() && track.value(QStringLiteral("external-filename")).toString() == m_pendingSecondaryPath) {
m_pendingSecondaryPath.clear();
setSecondarySubtitleId(id);
if (!m_pendingTranslatedPath.isEmpty() && track.value(QStringLiteral("external-filename")).toString() == m_pendingTranslatedPath) {
m_pendingTranslatedPath.clear();
showOnlySubtitle(id);
}
}