@@ -368,101 +368,13 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
368368
369369void ControllerBindingWidget::onMultipleDeviceAutomaticBindingTriggered ()
370370{
371- // force a refresh after mapping
372- if (doMultipleDeviceAutomaticBinding (this , m_dialog, m_port_number))
373- onTypeChanged ();
374- }
375-
376- bool ControllerBindingWidget::doMultipleDeviceAutomaticBinding (QWidget* parent, ControllerSettingsWindow* parent_dialog,
377- u32 port)
378- {
379- QDialog dialog (parent);
380-
381- QVBoxLayout* layout = new QVBoxLayout (&dialog);
382- QLabel help (tr (" Select the devices from the list below that you want to bind to this controller." ), &dialog);
383- layout->addWidget (&help);
384-
385- QListWidget list (&dialog);
386- list.setSelectionMode (QListWidget::SingleSelection);
387- layout->addWidget (&list);
388-
389- for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel ()->getDeviceList ())
390- {
391- QListWidgetItem* item = new QListWidgetItem;
392- item->setText (QStringLiteral (" %1 (%2)" ).arg (dev.identifier ).arg (dev.display_name ));
393- item->setData (Qt::UserRole, dev.identifier );
394- item->setIcon (InputDeviceListModel::getIconForKey (dev.key ));
395- item->setFlags (item->flags () | Qt::ItemIsUserCheckable);
396- item->setCheckState (Qt::Unchecked);
397- list.addItem (item);
398- }
399-
400- QDialogButtonBox bb (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog);
401- connect (&bb, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
402- connect (&bb, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
403- layout->addWidget (&bb);
404-
405- if (dialog.exec () == QDialog::Rejected)
406- return false ;
407-
408- auto lock = Host::GetSettingsLock ();
409- const bool global = (!parent_dialog || parent_dialog->isEditingGlobalSettings ());
410- SettingsInterface& si =
411- *(global ? Host::Internal::GetBaseSettingsLayer () : parent_dialog->getEditingSettingsInterface ());
412-
413- // first device should clear mappings
414- bool tried_any = false ;
415- bool mapped_any = false ;
416- const int count = list.count ();
417- for (int i = 0 ; i < count; i++)
418- {
419- QListWidgetItem* item = list.item (i);
420- if (item->checkState () != Qt::Checked)
421- continue ;
422-
423- tried_any = true ;
424-
425- const QString identifier = item->data (Qt::UserRole).toString ();
426- std::vector<std::pair<GenericInputBinding, std::string>> mapping =
427- InputManager::GetGenericBindingMapping (identifier.toStdString ());
428- if (mapping.empty ())
429- {
430- lock.unlock ();
431- QtUtils::MessageBoxCritical (
432- parent, tr (" Automatic Mapping" ),
433- tr (" No generic bindings were generated for device '%1'. The controller/source may not "
434- " support automatic mapping." )
435- .arg (identifier));
436- lock.lock ();
437- continue ;
438- }
439-
440- mapped_any |= InputManager::MapController (si, port, mapping, !mapped_any);
441- }
442-
443- lock.unlock ();
444-
445- if (!tried_any)
446- {
447- QtUtils::MessageBoxInformation (parent, tr (" Automatic Mapping" ), tr (" No devices were selected." ));
448- return false ;
449- }
371+ QDialog* const dialog = new MultipleDeviceAutobindDialog (this , m_dialog, m_port_number);
372+ dialog->setAttribute (Qt::WA_DeleteOnClose);
450373
451- if (mapped_any)
452- {
453- if (global)
454- {
455- QtHost::SaveGameSettings (&si, false );
456- g_emu_thread->reloadGameSettings (false );
457- }
458- else
459- {
460- QtHost::QueueSettingsSave ();
461- g_emu_thread->reloadInputBindings ();
462- }
463- }
374+ // force a refresh after mapping
375+ connect (dialog, &QDialog::accepted, this , [this ] { onTypeChanged (); });
464376
465- return mapped_any ;
377+ dialog-> open () ;
466378}
467379
468380void ControllerBindingWidget::saveAndRefresh ()
@@ -1077,3 +989,98 @@ ControllerCustomSettingsDialog::ControllerCustomSettingsDialog(QWidget* parent,
1077989}
1078990
1079991ControllerCustomSettingsDialog::~ControllerCustomSettingsDialog () = default ;
992+
993+ MultipleDeviceAutobindDialog::MultipleDeviceAutobindDialog (QWidget* parent, ControllerSettingsWindow* settings_window,
994+ u32 port)
995+ : QDialog(parent), m_settings_window(settings_window), m_port(port)
996+ {
997+ QVBoxLayout* layout = new QVBoxLayout (this );
998+ layout->addWidget (new QLabel (tr (" Select the devices from the list below that you want to bind to this controller." )));
999+
1000+ m_list = new QListWidget;
1001+ m_list->setSelectionMode (QListWidget::SingleSelection);
1002+ layout->addWidget (m_list);
1003+
1004+ for (const InputDeviceListModel::Device& dev : g_emu_thread->getInputDeviceListModel ()->getDeviceList ())
1005+ {
1006+ QListWidgetItem* item = new QListWidgetItem;
1007+ item->setIcon (InputDeviceListModel::getIconForKey (dev.key ));
1008+ item->setText (QStringLiteral (" %1 (%2)" ).arg (dev.identifier ).arg (dev.display_name ));
1009+ item->setData (Qt::UserRole, dev.identifier );
1010+ item->setFlags (item->flags () | Qt::ItemIsUserCheckable);
1011+ item->setCheckState (Qt::Unchecked);
1012+ m_list->addItem (item);
1013+ }
1014+
1015+ QDialogButtonBox* bb = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
1016+ connect (bb, &QDialogButtonBox::accepted, this , &MultipleDeviceAutobindDialog::doAutomaticBinding);
1017+ connect (bb, &QDialogButtonBox::rejected, this , &QDialog::reject);
1018+ layout->addWidget (bb);
1019+ }
1020+
1021+ MultipleDeviceAutobindDialog::~MultipleDeviceAutobindDialog () = default ;
1022+
1023+ void MultipleDeviceAutobindDialog::doAutomaticBinding ()
1024+ {
1025+ auto lock = Host::GetSettingsLock ();
1026+ const bool global = (!m_settings_window || m_settings_window->isEditingGlobalSettings ());
1027+ SettingsInterface* si =
1028+ global ? Host::Internal::GetBaseSettingsLayer () : m_settings_window->getEditingSettingsInterface ();
1029+
1030+ // first device should clear mappings
1031+ bool tried_any = false ;
1032+ bool mapped_any = false ;
1033+ const int count = m_list->count ();
1034+ for (int i = 0 ; i < count; i++)
1035+ {
1036+ const QListWidgetItem* item = m_list->item (i);
1037+ if (item->checkState () != Qt::Checked)
1038+ continue ;
1039+
1040+ tried_any = true ;
1041+
1042+ const QString identifier = item->data (Qt::UserRole).toString ();
1043+ std::vector<std::pair<GenericInputBinding, std::string>> mapping =
1044+ InputManager::GetGenericBindingMapping (identifier.toStdString ());
1045+ if (mapping.empty ())
1046+ {
1047+ lock.unlock ();
1048+ QtUtils::MessageBoxCritical (
1049+ this , tr (" Automatic Mapping" ),
1050+ tr (" No generic bindings were generated for device '%1'. The controller/source may not "
1051+ " support automatic mapping." )
1052+ .arg (identifier));
1053+ lock.lock ();
1054+ continue ;
1055+ }
1056+
1057+ mapped_any |= InputManager::MapController (*si, m_port, mapping, !mapped_any);
1058+ }
1059+
1060+ lock.unlock ();
1061+
1062+ if (!tried_any)
1063+ {
1064+ QtUtils::MessageBoxInformation (this , tr (" Automatic Mapping" ), tr (" No devices were selected." ));
1065+ return ;
1066+ }
1067+
1068+ if (mapped_any)
1069+ {
1070+ if (global)
1071+ {
1072+ QtHost::SaveGameSettings (si, false );
1073+ g_emu_thread->reloadGameSettings (false );
1074+ }
1075+ else
1076+ {
1077+ QtHost::QueueSettingsSave ();
1078+ g_emu_thread->reloadInputBindings ();
1079+ }
1080+ accept ();
1081+ }
1082+ else
1083+ {
1084+ reject ();
1085+ }
1086+ }
0 commit comments