From 2f2fc33f91745c7d5480786080cce7894a149f90 Mon Sep 17 00:00:00 2001 From: gxalpha Date: Tue, 28 Mar 2023 03:39:15 +0200 Subject: [PATCH] UI: Disallow closing settings without selected codec or format --- UI/data/locale/en-US.ini | 4 ++++ UI/window-basic-settings.cpp | 44 ++++++++++++++++++++++++++++++++++++ UI/window-basic-settings.hpp | 1 + 3 files changed, 49 insertions(+) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 3e2daf884..4c03aa7db 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -1335,6 +1335,10 @@ OutputWarnings.CodecIncompatible="The audio or video encoder selection was reset CodecCompat.Incompatible="(Incompatible with %1)" CodecCompat.CodecPlaceholder="Select Encoder..." CodecCompat.ContainerPlaceholder="Select Format..." +CodecCompat.CodecMissingOnExit.Title="No Encoder Selected" +CodecCompat.CodecMissingOnExit.Text="At least one video or audio encoder is not set. Please make sure to select encoders for both recording and streaming." +CodecCompat.ContainerMissingOnExit.Title="No Format Selected" +CodecCompat.ContainerMissingOnExit.Text="No recording format has been selected. Please select a recording format that is compatible with the selected stream encoder." # deleting final scene FinalScene.Title="Delete Scene" diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index 4a30aebfa..25cf7f4c1 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -4197,6 +4197,9 @@ bool OBSBasicSettings::QueryChanges() if (button == QMessageBox::Cancel) { return false; } else if (button == QMessageBox::Yes) { + if (!QueryAllowedToClose()) + return false; + SaveSettings(); } else { if (savedTheme != App()->GetTheme()) @@ -4210,6 +4213,44 @@ bool OBSBasicSettings::QueryChanges() return true; } +bool OBSBasicSettings::QueryAllowedToClose() +{ + bool simple = (ui->outputMode->currentIndex() == 0); + + bool invalidEncoder = false; + bool invalidFormat = false; + if (simple) { + if (ui->simpleOutRecEncoder->currentIndex() == -1 || + ui->simpleOutStrEncoder->currentIndex() == -1 || + ui->simpleOutRecAEncoder->currentIndex() == -1 || + ui->simpleOutStrAEncoder->currentIndex() == -1) + invalidEncoder = true; + + if (ui->simpleOutRecFormat->currentIndex() == -1) + invalidFormat = true; + } else { + if (ui->advOutRecEncoder->currentIndex() == -1 || + ui->advOutEncoder->currentIndex() == -1 || + ui->advOutRecAEncoder->currentIndex() == -1 || + ui->advOutAEncoder->currentIndex() == -1) + invalidEncoder = true; + } + + if (invalidEncoder) { + OBSMessageBox::warning( + this, QTStr("CodecCompat.CodecMissingOnExit.Title"), + QTStr("CodecCompat.CodecMissingOnExit.Text")); + return false; + } else if (invalidFormat) { + OBSMessageBox::warning( + this, QTStr("CodecCompat.ContainerMissingOnExit.Title"), + QTStr("CodecCompat.ContainerMissingOnExit.Text")); + return false; + } + + return true; +} + void OBSBasicSettings::closeEvent(QCloseEvent *event) { if (!AskIfCanCloseSettings()) @@ -4259,6 +4300,9 @@ void OBSBasicSettings::on_buttonBox_clicked(QAbstractButton *button) if (val == QDialogButtonBox::ApplyRole || val == QDialogButtonBox::AcceptRole) { + if (!QueryAllowedToClose()) + return; + SaveSettings(); ClearChanged(); } diff --git a/UI/window-basic-settings.hpp b/UI/window-basic-settings.hpp index aea3edd7d..c2536a062 100644 --- a/UI/window-basic-settings.hpp +++ b/UI/window-basic-settings.hpp @@ -224,6 +224,7 @@ private: void HookWidget(QWidget *widget, const char *signal, const char *slot); bool QueryChanges(); + bool QueryAllowedToClose(); void ResetEncoders(bool streamOnly = false); void LoadColorRanges();