mirror of
https://github.com/obsproject/obs-studio.git
synced 2024-09-20 04:42:18 +02:00
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.
This commit is contained in:
parent
03ca5919ce
commit
e7ea34f417
@ -15,6 +15,7 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
#include <QMessageBox>
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user