From b78cdc910b0f4fecafadcc9a58cec56f0e24b454 Mon Sep 17 00:00:00 2001 From: JohannMG Date: Tue, 26 Nov 2019 14:55:46 -0800 Subject: [PATCH] UI: Add Start Streaming settings check on start When we use the server error to respond to user's failing to start a stream it is slow to return an error and unclear to the user what went wrong. This diff introduces a simple settings check before attempting to stream and catch and explain specific URL/key issues to the user. In the case of preset services we check there is a Stream Key before attempting to start a stream. In the case of "custom" we only verify there is a URL since for some services that's all that is required or the user may use user/password authentication. --- UI/data/locale/en-US.ini | 5 ++++ UI/ui-validation.cpp | 63 ++++++++++++++++++++++++++++++++++++++++ UI/ui-validation.hpp | 23 ++++++++++++--- UI/window-basic-main.cpp | 14 +++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 7daf8f420..44978dd8c 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -679,6 +679,11 @@ Basic.Settings.Stream.TTVAddon.None="None" Basic.Settings.Stream.TTVAddon.BTTV="BetterTTV" Basic.Settings.Stream.TTVAddon.FFZ="FrankerFaceZ" Basic.Settings.Stream.TTVAddon.Both="BetterTTV and FrankerFaceZ" +Basic.Settings.Stream.MissingSettingAlert="Missing Stream Setup" +Basic.Settings.Stream.StreamSettingsWarning="Open Settings" +Basic.Settings.Stream.MissingUrlAndApiKey="URL and Stream Key are missing.\n\nOpen settings to enter the URL and Stream Key in the 'stream' tab." +Basic.Settings.Stream.MissingUrl="Stream URL is missing.\n\nOpen settings to enter the URL in the 'Stream' tab." +Basic.Settings.Stream.MissingStreamKey="Stream key is missing.\n\nOpen settings to enter the stream key in the 'Stream' tab." # basic mode 'output' settings Basic.Settings.Output="Output" diff --git a/UI/ui-validation.cpp b/UI/ui-validation.cpp index 596aab656..e441cbb6a 100644 --- a/UI/ui-validation.cpp +++ b/UI/ui-validation.cpp @@ -6,6 +6,7 @@ #include #include +#include static int CountVideoSources() { @@ -54,3 +55,65 @@ bool UIValidation::NoSourcesConfirmation(QWidget *parent) else return true; } + +StreamSettingsAction +UIValidation::StreamSettingsConfirmation(QWidget *parent, OBSService service) +{ + // Custom services can user API key in URL or user/pass combo. + // So only check there is a URL + char const *serviceType = obs_service_get_type(service); + bool isCustomUrlService = (strcmp(serviceType, "rtmp_custom") == 0); + + char const *streamUrl = obs_service_get_url(service); + char const *streamKey = obs_service_get_key(service); + + bool hasStreamUrl = (streamUrl != NULL && streamUrl[0] != '\0'); + bool hasStreamKey = ((streamKey != NULL && streamKey[0] != '\0') || + isCustomUrlService); + + if (hasStreamUrl && hasStreamKey) + return StreamSettingsAction::ContinueStream; + + QString msg; + + if (!hasStreamUrl && !hasStreamKey) { + msg = QTStr("Basic.Settings.Stream.MissingUrlAndApiKey"); + } else if (!hasStreamKey) { + msg = QTStr("Basic.Settings.Stream.MissingStreamKey"); + } else { + msg = QTStr("Basic.Settings.Stream.MissingUrl"); + } + + QMessageBox messageBox(parent); + messageBox.setWindowTitle( + QTStr("Basic.Settings.Stream.MissingSettingAlert")); + messageBox.setText(msg); + + QPushButton *cancel; + QPushButton *settings; + +#ifdef __APPLE__ +#define ACCEPT_BUTTON QMessageBox::AcceptRole +#define REJECT_BUTTON QMessageBox::ResetRole +#else +#define ACCEPT_BUTTON QMessageBox::NoRole +#define REJECT_BUTTON QMessageBox::NoRole +#endif + settings = messageBox.addButton( + QTStr("Basic.Settings.Stream.StreamSettingsWarning"), + ACCEPT_BUTTON); + cancel = messageBox.addButton(QTStr("Cancel"), REJECT_BUTTON); + + messageBox.setDefaultButton(settings); + messageBox.setEscapeButton(cancel); + + messageBox.setIcon(QMessageBox::Warning); + messageBox.exec(); + + if (messageBox.clickedButton() == settings) + return StreamSettingsAction::OpenSettings; + if (messageBox.clickedButton() == cancel) + return StreamSettingsAction::Cancel; + + return StreamSettingsAction::ContinueStream; +} diff --git a/UI/ui-validation.hpp b/UI/ui-validation.hpp index 161d7a168..5dbe14b63 100644 --- a/UI/ui-validation.hpp +++ b/UI/ui-validation.hpp @@ -3,13 +3,28 @@ #include #include +#include + +enum class StreamSettingsAction { + OpenSettings, + Cancel, + ContinueStream, +}; + class UIValidation : public QObject { Q_OBJECT public: - // Shows alert box notifying there are no video sources - // Returns true if user clicks "Yes" - // Returns false if user clicks "No" - // Blocks UI + /* Confirm video about to record or stream has sources. Shows alert + * box notifying there are no video sources Returns true if user clicks + * "Yes" Returns false if user clicks "No" */ static bool NoSourcesConfirmation(QWidget *parent); + + /* Check streaming requirements, shows warning with options to open + * settings, cancel stream, or attempt connection anyways. If setup + * basics is missing in stream, explain missing fields and offer to + * open settings, cancel, or continue. Returns Continue if all + * settings are valid. */ + static StreamSettingsAction + StreamSettingsConfirmation(QWidget *parent, OBSService service); }; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index dabdb701c..a54f95785 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -5754,6 +5754,20 @@ void OBSBasic::on_streamButton_clicked() return; } + auto action = + UIValidation::StreamSettingsConfirmation(this, service); + switch (action) { + case StreamSettingsAction::ContinueStream: + break; + case StreamSettingsAction::OpenSettings: + on_action_Settings_triggered(); + ui->streamButton->setChecked(false); + return; + case StreamSettingsAction::Cancel: + ui->streamButton->setChecked(false); + return; + } + bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow", "WarnBeforeStartingStream");