@@ -43,37 +43,43 @@ struct AddSourceData {
4343};
4444
4545namespace {
46- const char * getSourceDisplayName (QString type)
46+ QString getSourceDisplayName (QString type)
4747{
48- std::string typeId = type.toStdString ();
49- const char *unversionedId = typeId.c_str ();
48+ if (type == " scene" ) {
49+ return QTStr (" Basic.Scene" );
50+ }
51+
52+ const char *inputChar = obs_get_latest_input_type_id (type.toUtf8 ().constData ());
53+ const char *displayChar = obs_source_get_display_name (inputChar);
54+ std::string displayId = (displayChar) ? displayChar : " " ;
5055
51- if (strcmp (unversionedId, " scene" ) == 0 ) {
52- return Str (" Basic.Scene" );
56+ if (!displayId.empty ()) {
57+ return QString::fromStdString (displayId);
58+ } else {
59+ return QString ();
5360 }
54- const char *id = obs_get_latest_input_type_id (unversionedId);
55- return obs_source_get_display_name (id);
5661}
57- } // namespace
5862
59- char * getNewSourceName (const char * name, const char *format )
63+ std::string getNewSourceName (std::string_view name)
6064{
61- struct dstr new_name = {0 };
62- int inc = 0 ;
65+ std::string newName (name);
6366
64- dstr_copy (&new_name, name) ;
67+ int suffix = 1 ;
6568
6669 for (;;) {
67- OBSSourceAutoRelease existing_source = obs_get_source_by_name (new_name. array );
70+ OBSSourceAutoRelease existing_source = obs_get_source_by_name (newName. c_str () );
6871 if (!existing_source) {
6972 break ;
7073 }
7174
72- dstr_printf (&new_name, format, name, ++inc + 1 );
75+ newName = name;
76+ newName += " " ;
77+ newName += std::to_string (suffix);
7378 }
7479
75- return new_name. array ;
80+ return newName ;
7681}
82+ } // namespace
7783
7884static void AddSource (void *_data, obs_scene_t *scene)
7985{
@@ -111,10 +117,9 @@ static void AddExisting(OBSSource source, bool visible, bool duplicate, obs_tran
111117
112118 if (duplicate) {
113119 OBSSource from = source;
114- char * new_name = getNewSourceName (obs_source_get_name (source), " %s %d " );
115- source = obs_source_duplicate (from, new_name, false );
120+ std::string new_name = getNewSourceName (obs_source_get_name (source));
121+ source = obs_source_duplicate (from, new_name. c_str () , false );
116122 obs_source_release (source);
117- bfree (new_name);
118123
119124 if (!source) {
120125 return ;
@@ -217,6 +222,8 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, undo_stack &undo_s)
217222 &OBSBasicSourceSelect::checkSourceVisibility);
218223
219224 ui->createNewFrame ->setVisible (false );
225+ ui->deprecatedCreateLabel ->setVisible (false );
226+ ui->deprecatedCreateLabel ->setProperty (" class" , " text-muted" );
220227
221228 getSourceTypes ();
222229 getSources ();
@@ -251,8 +258,8 @@ void OBSBasicSourceSelect::checkSourceVisibility()
251258
252259 // Allow some room for previous/next rows to make scrolling a bit more seamless
253260 QRect scrollAreaRect (QPoint (0 , 0 ), ui->existingScrollArea ->size ());
254- scrollAreaRect.setTop (scrollAreaRect.top () - Thumbnail::cy );
255- scrollAreaRect.setBottom (scrollAreaRect.bottom () + Thumbnail::cy );
261+ scrollAreaRect.setTop (scrollAreaRect.top () - Thumbnail::size. width () );
262+ scrollAreaRect.setBottom (scrollAreaRect.bottom () + Thumbnail::size. height () );
256263
257264 for (QAbstractButton *button : buttons) {
258265 SourceSelectButton *sourceButton = qobject_cast<SourceSelectButton *>(button->parent ());
@@ -315,6 +322,10 @@ void OBSBasicSourceSelect::updateExistingSources(int limit)
315322 break ;
316323 }
317324
325+ if (!source || obs_source_removed (source)) {
326+ continue ;
327+ }
328+
318329 const char *id = obs_source_get_unversioned_id (source);
319330 QString stringId = QString (id);
320331
@@ -406,29 +417,50 @@ void OBSBasicSourceSelect::getSourceTypes()
406417 continue ;
407418 }
408419
409- QListWidgetItem *newItem = new QListWidgetItem ();
420+ QListWidgetItem *newItem = new QListWidgetItem (ui-> sourceTypeList );
410421 newItem->setData (Qt::DisplayRole, name);
411422 newItem->setData (UNVERSIONED_ID_ROLE, unversioned_type);
412423
413- QIcon icon;
414- icon = main->GetSourceIcon (type);
415- newItem->setIcon (icon);
424+ if ((caps & OBS_SOURCE_DEPRECATED) != 0 ) {
425+ newItem->setData (DEPRECATED_ROLE, true );
426+ } else {
427+ newItem->setData (DEPRECATED_ROLE, false );
416428
417- ui->sourceTypeList ->addItem (newItem);
429+ QIcon icon;
430+ icon = main->GetSourceIcon (type);
431+ newItem->setIcon (icon);
432+ }
418433 }
419434
420- QListWidgetItem *newItem = new QListWidgetItem ();
435+ QListWidgetItem *newItem = new QListWidgetItem (ui-> sourceTypeList );
421436 newItem->setData (Qt::DisplayRole, Str (" Basic.Scene" ));
422437 newItem->setData (UNVERSIONED_ID_ROLE, " scene" );
423438
424439 QIcon icon;
425440 icon = main->GetSceneIcon ();
426441 newItem->setIcon (icon);
427442
428- ui->sourceTypeList ->addItem (newItem);
429-
430443 ui->sourceTypeList ->sortItems ();
431444
445+ // Shift Deprecated sources to the bottom
446+ QList<QListWidgetItem *> deprecatedItems;
447+ for (int i = 0 ; i < ui->sourceTypeList ->count (); i++) {
448+ QListWidgetItem *item = ui->sourceTypeList ->item (i);
449+ if (!item) {
450+ break ;
451+ }
452+
453+ bool isDeprecated = item->data (DEPRECATED_ROLE).toBool ();
454+ if (isDeprecated) {
455+ ui->sourceTypeList ->takeItem (i);
456+ deprecatedItems.append (item);
457+ }
458+ }
459+
460+ for (auto &item : deprecatedItems) {
461+ ui->sourceTypeList ->addItem (item);
462+ }
463+
432464 QListWidgetItem *allSources = new QListWidgetItem ();
433465 allSources->setData (Qt::DisplayRole, Str (" Basic.SourceSelect.Recent" ));
434466 allSources->setData (UNVERSIONED_ID_ROLE, QVariant ());
@@ -454,26 +486,33 @@ void OBSBasicSourceSelect::setSelectedSourceType(QListWidgetItem *item)
454486 delete child;
455487 }
456488
457- QVariant data = item->data (UNVERSIONED_ID_ROLE);
489+ QVariant unversionedIdData = item->data (UNVERSIONED_ID_ROLE);
490+ QVariant deprecatedData = item->data (DEPRECATED_ROLE);
458491
459- if (data .isNull ()) {
492+ if (unversionedIdData .isNull ()) {
460493 setSelectedSource (nullptr );
461494 sourceTypeId.clear ();
462495 ui->createNewFrame ->setVisible (false );
463496 updateExistingSources (16 );
464497 return ;
465498 }
466499
467- QString type = data .toString ();
500+ QString type = unversionedIdData .toString ();
468501 if (type.compare (sourceTypeId) == 0 ) {
469502 return ;
470503 }
471504
472505 ui->createNewFrame ->setVisible (true );
473506
507+ bool isDeprecatedType = deprecatedData.toBool ();
508+ ui->newSourceName ->setVisible (!isDeprecatedType);
509+ ui->createNewSource ->setVisible (!isDeprecatedType);
510+
511+ ui->deprecatedCreateLabel ->setVisible (isDeprecatedType);
512+
474513 sourceTypeId = type;
475514
476- QString placeHolderText{QT_UTF8 ( getSourceDisplayName (sourceTypeId) )};
515+ QString placeHolderText{getSourceDisplayName (sourceTypeId)};
477516
478517 QString text{placeHolderText};
479518 int i = 2 ;
0 commit comments