mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 13:08:50 +02:00
c4396e03a7
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.
57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#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;
|
|
}
|