Ensure names are valid

Ensure that a source has a valid name.  Duplicates aren't a big deal
internally, but sources without a name are probably something that
should be avoided.  Made is so that if a source is programmatically
created without a name, it's assigned an index based name.

In the main basic-mode window, made it check to make sure the name was
valid as well.
This commit is contained in:
jp9000 2014-03-10 13:39:51 -07:00
parent 35e7a2a9fe
commit 5288467aeb
5 changed files with 37 additions and 4 deletions

View file

@ -18,6 +18,8 @@ MainWindow.AddSourceDlg.Text="Please enter the name of the source"
MainWindow.NameExists.Title="Name already exists"
MainWindow.NameExists.Text="The name is already in use by another source."
MainWindow.NoNameEntered="Please enter a valid name"
MainWindow.Exit="Exit"
MainWindow.Lock="Lock Preview"
MainWindow.Preview="Enable Preview"
@ -50,7 +52,7 @@ Settings.Video.DisableAeroWindows="Disable Aero (Windows only)"
Settings.Video.FPS="FPS:"
Settings.Video.FPS.Common="Common FPS Values"
Settings.Video.FPS.Integer="Integer FPS Value"
Settings.VIdeo.FPS.Fraction="Fractional FPS Value"
Settings.Video.FPS.Fraction="Fractional FPS Value"
Settings.Video.FPS.Nanoseconds="Frame Interval (nanoseconds)"
Settings.Video.FPS.Numerator="Numerator:"
Settings.Video.FPS.Denominator="Denominator:"

View file

@ -141,6 +141,8 @@ struct obs_core_data {
struct obs_view main_view;
long long unnamed_index;
volatile bool valid;
};

View file

@ -202,7 +202,7 @@ static const char *obs_scene_signals[] = {
NULL
};
void source_init_name(struct obs_source *source, const char *name);
obs_scene_t obs_scene_create(const char *name)
{
@ -229,7 +229,7 @@ obs_scene_t obs_scene_create(const char *name)
return NULL;
}
source->name = bstrdup(name);
source_init_name(source, name);
scene->source = source;
obs_source_init(source, &scene_info);

View file

@ -151,6 +151,18 @@ static inline void obs_source_dosignal(struct obs_source *source,
calldata_free(&data);
}
void source_init_name(struct obs_source *source, const char *name)
{
if (!name || !*name) {
struct dstr unnamed = {0};
dstr_printf(&unnamed, "__unnamed%004lld",
obs->data.unnamed_index++);
source->name = unnamed.array;
} else {
source->name = bstrdup(name);
}
}
obs_source_t obs_source_create(enum obs_source_type type, const char *id,
const char *name, obs_data_t settings)
{
@ -167,7 +179,8 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *id,
if (!obs_source_init_handlers(source))
goto fail;
source->name = bstrdup(name);
source_init_name(source, name);
source->settings = obs_data_newref(settings);
source->data = info->create(source->settings, source);

View file

@ -586,6 +586,14 @@ void OBSBasic::on_actionAddScene_triggered()
name);
if (accepted) {
if (name.empty()) {
QMessageBox::information(this,
QTStr("MainWindow.NoNameEntered"),
QTStr("MainWindow.NoNameEntered"));
on_actionAddScene_triggered();
return;
}
obs_source_t source = obs_get_source_by_name(name.c_str());
if (source) {
QMessageBox::information(this,
@ -661,9 +669,17 @@ void OBSBasic::AddSource(obs_scene_t scene, const char *id)
if (!accepted)
break;
if (name.empty()) {
QMessageBox::information(this,
QTStr("MainWindow.NoNameEntered"),
QTStr("MainWindow.NoNameEntered"));
continue;
}
obs_source_t source = obs_get_source_by_name(name.c_str());
if (!source) {
success = true;
break;
} else {
QMessageBox::information(this,
QTStr("MainWindow.NameExists.Title"),