From 8f4edede4af463eab9ec6d4f77a83e1a702bccc8 Mon Sep 17 00:00:00 2001 From: cg2121 Date: Tue, 26 Jun 2018 19:37:21 -0500 Subject: [PATCH] UI: Add confirmation dialog if there are no sources This adds a confirmation dialog for streaming or recording if there are no sources. Closes obsproject/obs-studio#1344 --- UI/data/locale/en-US.ini | 5 ++++ UI/window-basic-main.cpp | 62 ++++++++++++++++++++++++++++++++++++++-- UI/window-basic-main.hpp | 2 ++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 00f6c3fe1..4c594c880 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -845,3 +845,8 @@ OutputWarnings.MP4Recording="Warning: Recordings saved to MP4 will be unrecovera # deleting final scene FinalScene.Title="Delete Scene" FinalScene.Text="There needs to be at least one scene." + +# no sources +NoSources.Title="No Sources" +NoSources.Text="It looks like you haven't added any video sources yet, so you will only be outputting a blank screen. Are you sure you want to do this?" +NoSources.Text.AddSource="You can add sources by clicking the + icon under the Sources box in the main window at any time." diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 6793a640a..2a6881460 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -143,6 +143,26 @@ static void AddExtraModulePaths() extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main); +static int CountVideoSources() +{ + int count = 0; + + auto countSources = [] (void *param, obs_source_t *source) + { + if (!source) + return true; + + uint32_t flags = obs_source_get_output_flags(source); + if ((flags & OBS_SOURCE_VIDEO) != 0) + (*reinterpret_cast(param))++; + + return true; + }; + + obs_enum_sources(countSources, &count); + return count; +} + OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow (parent), ui (new Ui::OBSBasic) @@ -4936,6 +4956,11 @@ void OBSBasic::StartReplayBuffer() if (disableOutputsRef) return; + if (!NoSourcesConfirmation()) { + replayBufferButton->setChecked(false); + return; + } + obs_output_t *output = outputHandler->replayBuffer; obs_data_t *hotkeys = obs_hotkeys_save_output(output); obs_data_array_t *bindings = obs_data_get_array(hotkeys, @@ -5065,6 +5090,28 @@ void OBSBasic::ReplayBufferStop(int code) OnDeactivate(); } +bool OBSBasic::NoSourcesConfirmation() +{ + if (CountVideoSources() == 0 && isVisible()) { + QString msg; + msg = QTStr("NoSources.Text"); + msg += "\n\n"; + msg += QTStr("NoSources.Text.AddSource"); + + QMessageBox messageBox(QMessageBox::Question, + QTStr("NoSources.title"), + msg, + QMessageBox::Yes | QMessageBox::No, + this); + messageBox.setDefaultButton(QMessageBox::No); + + if (QMessageBox::No == messageBox.exec()) + return false; + } + + return true; +} + void OBSBasic::on_streamButton_clicked() { if (outputHandler->StreamingActive()) { @@ -5085,6 +5132,11 @@ void OBSBasic::on_streamButton_clicked() StopStreaming(); } else { + if (!NoSourcesConfirmation()) { + ui->streamButton->setChecked(false); + return; + } + bool confirm = config_get_bool(GetGlobalConfig(), "BasicWindow", "WarnBeforeStartingStream"); @@ -5106,10 +5158,16 @@ void OBSBasic::on_streamButton_clicked() void OBSBasic::on_recordButton_clicked() { - if (outputHandler->RecordingActive()) + if (outputHandler->RecordingActive()) { StopRecording(); - else + } else { + if (!NoSourcesConfirmation()) { + ui->recordButton->setChecked(false); + return; + } + StartRecording(); + } } void OBSBasic::on_settingsButton_clicked() diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index ecf7a4de0..ced5227bf 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -372,6 +372,8 @@ private: void ReceivedIntroJson(const QString &text); + bool NoSourcesConfirmation(); + public slots: void DeferSaveBegin(); void DeferSaveEnd();