From e78e7c71d102661925d2edcab37574e501806dac Mon Sep 17 00:00:00 2001 From: Steve Erlenborn <1751095+SteveErl@users.noreply.github.com> Date: Thu, 24 Jul 2025 15:15:42 -0500 Subject: [PATCH] Add option to default to Last Captions State This solution adds a LastCaptions entry into the Settings database. This boolean gets updated each time a user toggles captions on or off, and indicates whether captions were enabled or disabled the last time it changed. The m_captionsEnabledbyDefault variable is switched from a boolean to an unsigned int so that it can hold 0, 1, or 2. It's set to 2 when the Last Captions State configuration is selected. When starting up viewing of a video recording or Live TV, captions are either disabled (0), enabled (1), or set to match the last caption state (2). Resolves: #1154 --- mythtv/libs/libmythtv/mythplayer.cpp | 3 ++- mythtv/libs/libmythtv/mythplayer.h | 3 ++- mythtv/libs/libmythtv/mythplayercaptionsui.cpp | 4 +++- mythtv/libs/libmythtv/mythplayerui.cpp | 15 ++++++++++++++- mythtv/programs/mythfrontend/globalsettings.cpp | 10 ++++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp index 1994bf37fc1..701c5c3b31f 100644 --- a/mythtv/libs/libmythtv/mythplayer.cpp +++ b/mythtv/libs/libmythtv/mythplayer.cpp @@ -93,7 +93,8 @@ MythPlayer::MythPlayer(PlayerContext* Context, PlayerFlags Flags) m_deleteMap.SetPlayerContext(m_playerCtx); m_vbiMode = VBIMode::Parse(gCoreContext->GetSetting("VbiFormat")); - m_captionsEnabledbyDefault = gCoreContext->GetBoolSetting("DefaultCCMode"); + m_captionsEnabledbyDefault = gCoreContext->GetNumSetting("DefaultCCMode"); + m_lastCaptionsEnabled = gCoreContext->GetBoolSetting("LastCaptions", false); m_endExitPrompt = gCoreContext->GetNumSetting("EndOfRecordingExitPrompt"); // Get VBI page number diff --git a/mythtv/libs/libmythtv/mythplayer.h b/mythtv/libs/libmythtv/mythplayer.h index 991d977ed11..2c0849e6b3a 100644 --- a/mythtv/libs/libmythtv/mythplayer.h +++ b/mythtv/libs/libmythtv/mythplayer.h @@ -459,7 +459,8 @@ class MTV_PUBLIC MythPlayer : public QObject TeletextReader m_ttxReader; /// This allows us to enable captions/subtitles later if the streams /// are not immediately available when the video starts playing. - bool m_captionsEnabledbyDefault {false}; + uint m_captionsEnabledbyDefault {0}; // 0=off, 1=on, 2=last + bool m_lastCaptionsEnabled {false}; bool m_enableForcedSubtitles {false}; bool m_disableForcedSubtitles {false}; bool m_allowForcedSubtitles {true}; diff --git a/mythtv/libs/libmythtv/mythplayercaptionsui.cpp b/mythtv/libs/libmythtv/mythplayercaptionsui.cpp index 59f4a542171..c9757494ad7 100644 --- a/mythtv/libs/libmythtv/mythplayercaptionsui.cpp +++ b/mythtv/libs/libmythtv/mythplayercaptionsui.cpp @@ -267,7 +267,9 @@ void MythPlayerCaptionsUI::SetAllowForcedSubtitles(bool Allow) void MythPlayerCaptionsUI::ToggleCaptions() { - SetCaptionsEnabled(!(static_cast(m_captionsState.m_textDisplayMode))); + bool togval = !(static_cast(m_captionsState.m_textDisplayMode)); + SetCaptionsEnabled(togval); + gCoreContext->SaveSetting("LastCaptions", togval); } void MythPlayerCaptionsUI::ToggleCaptionsByType(uint Type) diff --git a/mythtv/libs/libmythtv/mythplayerui.cpp b/mythtv/libs/libmythtv/mythplayerui.cpp index a0c4e6b60e0..387d6c06177 100644 --- a/mythtv/libs/libmythtv/mythplayerui.cpp +++ b/mythtv/libs/libmythtv/mythplayerui.cpp @@ -463,7 +463,20 @@ void MythPlayerUI::VideoStart() if (hasForcedTextTrack) SetTrack(kTrackTypeRawText, forcedTrackNumber); else - SetCaptionsEnabled(m_captionsEnabledbyDefault, false); + { + switch (m_captionsEnabledbyDefault) + { + case 0: // Captions off + SetCaptionsEnabled(false, false); + break; + case 1: // Captions on + SetCaptionsEnabled(true, false); + break; + default: // Last captions state + SetCaptionsEnabled(m_lastCaptionsEnabled, false); + break; + } + } m_osdLock.unlock(); diff --git a/mythtv/programs/mythfrontend/globalsettings.cpp b/mythtv/programs/mythfrontend/globalsettings.cpp index eba468b1037..13b8dc2b3ec 100644 --- a/mythtv/programs/mythfrontend/globalsettings.cpp +++ b/mythtv/programs/mythfrontend/globalsettings.cpp @@ -1673,14 +1673,16 @@ static HostSpinBoxSetting *YScanDisplacement() return gs; }; -static HostCheckBoxSetting *DefaultCCMode() +static HostComboBoxSetting *DefaultCCMode() { - auto *gc = new HostCheckBoxSetting("DefaultCCMode"); + auto *gc = new HostComboBoxSetting("DefaultCCMode"); - gc->setLabel(OSDSettings::tr("Always display closed captioning or " + gc->setLabel(OSDSettings::tr("Default to display closed captioning or " "subtitles")); - gc->setValue(false); + gc->addSelection(OSDSettings::tr("Captions off"), "0"); + gc->addSelection(OSDSettings::tr("Captions on"), "1"); + gc->addSelection(OSDSettings::tr("Last captions state"), "2"); gc->setHelpText(OSDSettings::tr("If enabled, captions will be displayed " "when playing back recordings or watching "