From 39ceabb68dd32b076c3f7b29b2258901b272d0ce Mon Sep 17 00:00:00 2001 From: Palana Date: Tue, 13 May 2014 01:12:22 +0200 Subject: [PATCH] Make generated source name unique --- obs/window-basic-source-select.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/obs/window-basic-source-select.cpp b/obs/window-basic-source-select.cpp index 8773a9214..2ea8fa7e3 100644 --- a/obs/window-basic-source-select.cpp +++ b/obs/window-basic-source-select.cpp @@ -168,11 +168,16 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, const char *type_) { ui->setupUi(this); - const char *placeHolderText = obs_source_getdisplayname( - OBS_SOURCE_TYPE_INPUT, - type_, App()->GetLocale()); + QString placeHolderText{QT_UTF8(obs_source_getdisplayname( + OBS_SOURCE_TYPE_INPUT, + type_, App()->GetLocale()))}; - ui->sourceName->setText(QT_UTF8(placeHolderText)); + QString text{placeHolderText}; + int i = 1; + while (obs_get_source_by_name(QT_TO_UTF8(text))) + text = QString("%1 %2").arg(placeHolderText).arg(i++); + + ui->sourceName->setText(text); ui->sourceName->setFocus(); //Fixes deselect of text. ui->sourceName->selectAll();