UI: Create UI Validation Helper Class
Pull UI validation and its helpers to their own class. This class will be used to validate forms and perform UI-action checks such as checking stream keys aren't empty and in this diff now holds the logic to ensure there is a source before the person starts a stream.
This commit is contained in:
parent
bcddf4ddbf
commit
c4396e03a7
@ -245,6 +245,7 @@ set(obs_SOURCES
|
|||||||
combobox-ignorewheel.cpp
|
combobox-ignorewheel.cpp
|
||||||
spinbox-ignorewheel.cpp
|
spinbox-ignorewheel.cpp
|
||||||
record-button.cpp
|
record-button.cpp
|
||||||
|
ui-validation.cpp
|
||||||
url-push-button.cpp
|
url-push-button.cpp
|
||||||
volume-control.cpp
|
volume-control.cpp
|
||||||
adv-audio-control.cpp
|
adv-audio-control.cpp
|
||||||
@ -302,6 +303,7 @@ set(obs_HEADERS
|
|||||||
menu-button.hpp
|
menu-button.hpp
|
||||||
mute-checkbox.hpp
|
mute-checkbox.hpp
|
||||||
record-button.hpp
|
record-button.hpp
|
||||||
|
ui-validation.hpp
|
||||||
url-push-button.hpp
|
url-push-button.hpp
|
||||||
volume-control.hpp
|
volume-control.hpp
|
||||||
adv-audio-control.hpp
|
adv-audio-control.hpp
|
||||||
|
56
UI/ui-validation.cpp
Normal file
56
UI/ui-validation.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "ui-validation.hpp"
|
||||||
|
|
||||||
|
#include <obs.hpp>
|
||||||
|
#include <QString>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
#include <obs-app.hpp>
|
||||||
|
|
||||||
|
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<int *>(param))++;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
obs_enum_sources(countSources, &count);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UIValidation::NoSourcesConfirmation(QWidget *parent)
|
||||||
|
{
|
||||||
|
// There are sources, don't need confirmation
|
||||||
|
if (CountVideoSources() != 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Ignore no video if no parent is visible to alert on
|
||||||
|
if (!parent->isVisible())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
QString msg = QTStr("NoSources.Text");
|
||||||
|
msg += "\n\n";
|
||||||
|
msg += QTStr("NoSources.Text.AddSource");
|
||||||
|
|
||||||
|
QMessageBox messageBox(parent);
|
||||||
|
messageBox.setWindowTitle(QTStr("NoSources.Title"));
|
||||||
|
messageBox.setText(msg);
|
||||||
|
|
||||||
|
QAbstractButton *yesButton =
|
||||||
|
messageBox.addButton(QTStr("Yes"), QMessageBox::YesRole);
|
||||||
|
messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
|
||||||
|
messageBox.setIcon(QMessageBox::Question);
|
||||||
|
messageBox.exec();
|
||||||
|
|
||||||
|
if (messageBox.clickedButton() != yesButton)
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
15
UI/ui-validation.hpp
Normal file
15
UI/ui-validation.hpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
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
|
||||||
|
static bool NoSourcesConfirmation(QWidget *parent);
|
||||||
|
};
|
@ -54,6 +54,7 @@
|
|||||||
#include "display-helpers.hpp"
|
#include "display-helpers.hpp"
|
||||||
#include "volume-control.hpp"
|
#include "volume-control.hpp"
|
||||||
#include "remote-text.hpp"
|
#include "remote-text.hpp"
|
||||||
|
#include "ui-validation.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -163,25 +164,6 @@ static void AddExtraModulePaths()
|
|||||||
|
|
||||||
extern obs_frontend_callbacks *InitializeAPIInterface(OBSBasic *main);
|
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<int *>(param))++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
obs_enum_sources(countSources, &count);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void assignDockToggle(QDockWidget *dock, QAction *action)
|
void assignDockToggle(QDockWidget *dock, QAction *action)
|
||||||
{
|
{
|
||||||
auto handleWindowToggle = [action](bool vis) {
|
auto handleWindowToggle = [action](bool vis) {
|
||||||
@ -5600,7 +5582,7 @@ void OBSBasic::StartReplayBuffer()
|
|||||||
if (disableOutputsRef)
|
if (disableOutputsRef)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!NoSourcesConfirmation()) {
|
if (!UIValidation::NoSourcesConfirmation(this)) {
|
||||||
replayBufferButton->setChecked(false);
|
replayBufferButton->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5745,30 +5727,6 @@ void OBSBasic::ReplayBufferStop(int code)
|
|||||||
OnDeactivate();
|
OnDeactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OBSBasic::NoSourcesConfirmation()
|
|
||||||
{
|
|
||||||
if (CountVideoSources() == 0 && isVisible()) {
|
|
||||||
QString msg;
|
|
||||||
msg = QTStr("NoSources.Text");
|
|
||||||
msg += "\n\n";
|
|
||||||
msg += QTStr("NoSources.Text.AddSource");
|
|
||||||
|
|
||||||
QMessageBox messageBox(this);
|
|
||||||
messageBox.setWindowTitle(QTStr("NoSources.Title"));
|
|
||||||
messageBox.setText(msg);
|
|
||||||
QAbstractButton *Yes = messageBox.addButton(
|
|
||||||
QTStr("Yes"), QMessageBox::YesRole);
|
|
||||||
messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
|
|
||||||
messageBox.setIcon(QMessageBox::Question);
|
|
||||||
messageBox.exec();
|
|
||||||
|
|
||||||
if (messageBox.clickedButton() != Yes)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OBSBasic::on_streamButton_clicked()
|
void OBSBasic::on_streamButton_clicked()
|
||||||
{
|
{
|
||||||
if (outputHandler->StreamingActive()) {
|
if (outputHandler->StreamingActive()) {
|
||||||
@ -5791,7 +5749,7 @@ void OBSBasic::on_streamButton_clicked()
|
|||||||
|
|
||||||
StopStreaming();
|
StopStreaming();
|
||||||
} else {
|
} else {
|
||||||
if (!NoSourcesConfirmation()) {
|
if (!UIValidation::NoSourcesConfirmation(this)) {
|
||||||
ui->streamButton->setChecked(false);
|
ui->streamButton->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -5852,7 +5810,7 @@ void OBSBasic::on_recordButton_clicked()
|
|||||||
}
|
}
|
||||||
StopRecording();
|
StopRecording();
|
||||||
} else {
|
} else {
|
||||||
if (!NoSourcesConfirmation()) {
|
if (!UIValidation::NoSourcesConfirmation(this)) {
|
||||||
ui->recordButton->setChecked(false);
|
ui->recordButton->setChecked(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -456,8 +456,6 @@ private:
|
|||||||
|
|
||||||
void ReceivedIntroJson(const QString &text);
|
void ReceivedIntroJson(const QString &text);
|
||||||
|
|
||||||
bool NoSourcesConfirmation();
|
|
||||||
|
|
||||||
#ifdef BROWSER_AVAILABLE
|
#ifdef BROWSER_AVAILABLE
|
||||||
QList<QSharedPointer<QDockWidget>> extraBrowserDocks;
|
QList<QSharedPointer<QDockWidget>> extraBrowserDocks;
|
||||||
QList<QSharedPointer<QAction>> extraBrowserDockActions;
|
QList<QSharedPointer<QAction>> extraBrowserDockActions;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user