From e7ea34f4179faeab40e7d97a7b1bb879b26990c3 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Mon, 12 May 2014 15:32:55 -0700 Subject: [PATCH] UI: Check for valid source name and duplicates When creating a source, it was possible to create duplicates. That has now been fixed. I think that perhaps libobs shouldn't even allow for duplicates in its core code, just to be safe. Will have to consider doing that in the future. --- obs/window-basic-source-select.cpp | 46 +++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/obs/window-basic-source-select.cpp b/obs/window-basic-source-select.cpp index f48831f82..8773a9214 100644 --- a/obs/window-basic-source-select.cpp +++ b/obs/window-basic-source-select.cpp @@ -15,6 +15,7 @@ along with this program. If not, see . ******************************************************************************/ +#include #include "window-basic-main.hpp" #include "window-basic-source-select.hpp" #include "qt-wrappers.hpp" @@ -98,21 +99,36 @@ static void AddExisting(const char *name) obs_scene_release(scene); } -void AddNew(const char *id, const char *name) +bool AddNew(QWidget *parent, const char *id, const char *name) { - obs_source_t source = obs_get_output_source(0); - obs_scene_t scene = obs_scene_fromsource(source); - if (!scene) - return; + obs_source_t source = obs_get_output_source(0); + obs_scene_t scene = obs_scene_fromsource(source); + bool success = false; + if (!source) + return false; - source = obs_source_create(OBS_SOURCE_TYPE_INPUT, - id, name, NULL); + source = obs_get_source_by_name(name); + if (source) { + QMessageBox::information(parent, + QTStr("NameExists.Title"), + QTStr("NameExists.Text")); + + } else { + source = obs_source_create(OBS_SOURCE_TYPE_INPUT, + id, name, NULL); + + if (source) { + obs_add_source(source); + obs_scene_add(scene, source); + + success = true; + } + } - obs_add_source(source); - obs_scene_add(scene, source); obs_source_release(source); - obs_scene_release(scene); + + return success; } void OBSBasicSourceSelect::on_buttonBox_accepted() @@ -126,7 +142,15 @@ void OBSBasicSourceSelect::on_buttonBox_accepted() AddExisting(QT_TO_UTF8(item->text())); } else { - AddNew(type, QT_TO_UTF8(ui->sourceName->text())); + if (ui->sourceName->text().isEmpty()) { + QMessageBox::information(this, + QTStr("NoNameEntered"), + QTStr("NoNameEntered")); + return; + } + + if (!AddNew(this, type, QT_TO_UTF8(ui->sourceName->text()))) + return; } done(DialogCode::Accepted);