Skip to content

Commit 5626fe0

Browse files
committed
Qt: Replace most blocking message boxes with async
1 parent 459ee19 commit 5626fe0

23 files changed

+187
-179
lines changed

src/duckstation-qt/achievementlogindialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ void AchievementLoginDialog::processLoginResult(bool result, const QString& mess
7272
{
7373
if (!result)
7474
{
75-
QtUtils::MessageBoxCritical(
76-
this, tr("Login Error"),
75+
QtUtils::AsyncMessageBox(
76+
this, QMessageBox::Critical, tr("Login Error"),
7777
tr("Login failed.\nError: %1\n\nPlease check your username and password, and try again.").arg(message));
7878
m_ui.status->setText(tr("Login failed."));
7979
enableUI(true);

src/duckstation-qt/controllerbindingwidgets.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ void ControllerBindingWidget::doDeviceAutomaticBinding(const QString& device)
341341
InputManager::GetGenericBindingMapping(device.toStdString());
342342
if (mapping.empty())
343343
{
344-
QtUtils::MessageBoxCritical(
345-
this, tr("Automatic Mapping Failed"),
344+
QtUtils::AsyncMessageBox(
345+
this, QMessageBox::Critical, tr("Automatic Mapping Failed"),
346346
tr("No generic bindings were generated for device '%1'. The controller/source may not support automatic mapping.")
347347
.arg(device));
348348
return;
@@ -1063,7 +1063,8 @@ void MultipleDeviceAutobindDialog::doAutomaticBinding()
10631063

10641064
if (!tried_any)
10651065
{
1066-
QtUtils::MessageBoxInformation(this, tr("Automatic Mapping Failed"), tr("No devices were selected."));
1066+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Automatic Mapping Failed"),
1067+
tr("No devices were selected."));
10671068
return;
10681069
}
10691070

src/duckstation-qt/controllerglobalsettingswidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void ControllerGlobalSettingsWidget::ledSettingsClicked()
135135
g_emu_thread->getInputDeviceListModel()->getDeviceList(),
136136
[](const InputDeviceListModel::Device& dev) { return (dev.key.source_type == InputSourceType::SDL); }))
137137
{
138-
QtUtils::MessageBoxCritical(this, tr("Error"), tr("No SDL devices are currently connected."));
138+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"), tr("No SDL devices are currently connected."));
139139
return;
140140
}
141141

src/duckstation-qt/controllersettingswindow.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ void ControllerSettingsWindow::onNewProfileClicked()
176176
std::string profile_path = System::GetInputProfilePath(profile_name);
177177
if (FileSystem::FileExists(profile_path.c_str()))
178178
{
179-
QtUtils::MessageBoxCritical(
180-
this, tr("Error"), tr("A preset with the name '%1' already exists.").arg(QString::fromStdString(profile_name)));
179+
QtUtils::AsyncMessageBox(
180+
this, QMessageBox::Critical, tr("Error"),
181+
tr("A preset with the name '%1' already exists.").arg(QString::fromStdString(profile_name)));
181182
return;
182183
}
183184

@@ -231,8 +232,9 @@ void ControllerSettingsWindow::onNewProfileClicked()
231232

232233
if (!temp_si.Save())
233234
{
234-
QtUtils::MessageBoxCritical(
235-
this, tr("Error"), tr("Failed to save the new preset to '%1'.").arg(QString::fromStdString(temp_si.GetPath())));
235+
QtUtils::AsyncMessageBox(
236+
this, QMessageBox::Critical, tr("Error"),
237+
tr("Failed to save the new preset to '%1'.").arg(QString::fromStdString(temp_si.GetPath())));
236238
return;
237239
}
238240

@@ -278,8 +280,8 @@ void ControllerSettingsWindow::onDeleteProfileClicked()
278280
std::string profile_path(System::GetInputProfilePath(m_profile_name.toStdString()));
279281
if (!FileSystem::DeleteFile(profile_path.c_str()))
280282
{
281-
QtUtils::MessageBoxCritical(this, tr("Error"),
282-
tr("Failed to delete '%1'.").arg(QString::fromStdString(profile_path)));
283+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
284+
tr("Failed to delete '%1'.").arg(QString::fromStdString(profile_path)));
283285
return;
284286
}
285287

@@ -319,10 +321,9 @@ void ControllerSettingsWindow::onCopyGlobalSettingsClicked()
319321
g_emu_thread->reloadGameSettings();
320322
createWidgets();
321323

322-
QtUtils::MessageBoxInformation(QtUtils::GetRootWidget(this), tr("DuckStation Controller Settings"),
323-
isEditingGameSettings() ?
324-
tr("Per-game controller configuration reset to global settings.") :
325-
tr("Controller preset reset to global settings."));
324+
QtUtils::AsyncMessageBox(this, QMessageBox::Information, tr("DuckStation Controller Settings"),
325+
isEditingGameSettings() ? tr("Per-game controller configuration reset to global settings.") :
326+
tr("Controller preset reset to global settings."));
326327
}
327328

328329
bool ControllerSettingsWindow::getBoolValue(const char* section, const char* key, bool default_value) const
@@ -585,8 +586,8 @@ void ControllerSettingsWindow::switchProfile(const std::string_view name)
585586
std::string path = System::GetInputProfilePath(name);
586587
if (!FileSystem::FileExists(path.c_str()))
587588
{
588-
QtUtils::MessageBoxCritical(this, tr("Error"),
589-
tr("The controller preset named '%1' cannot be found.").arg(name_qstr));
589+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
590+
tr("The controller preset named '%1' cannot be found.").arg(name_qstr));
590591
return;
591592
}
592593

src/duckstation-qt/debuggermodels.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ void DebuggerAddBreakpointDialog::okClicked()
201201

202202
if (!ok)
203203
{
204-
QtUtils::MessageBoxCritical(
205-
this, tr("Error"), tr("DebuggerWindow", "Invalid address. It should be in hex (0x12345678 or 12345678)"));
204+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
205+
tr("DebuggerWindow", "Invalid address. It should be in hex (0x12345678 or 12345678)"));
206206
return;
207207
}
208208

src/duckstation-qt/debuggerwindow.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void DebuggerWindow::onRunToCursorTriggered()
115115
std::optional<VirtualMemoryAddress> addr = m_ui.codeView->getSelectedAddress();
116116
if (!addr.has_value())
117117
{
118-
QtUtils::MessageBoxCritical(this, windowTitle(), tr("No address selected."));
118+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, windowTitle(), tr("No address selected."));
119119
return;
120120
}
121121

@@ -164,13 +164,14 @@ void DebuggerWindow::onTraceTriggered()
164164

165165
if (trace_enabled)
166166
{
167-
QtUtils::MessageBoxCritical(
168-
win, win->windowTitle(),
167+
QtUtils::AsyncMessageBox(
168+
win, QMessageBox::Critical, win->windowTitle(),
169169
tr("Trace logging started to cpu_log.txt.\nThis file can be several gigabytes, so be aware of SSD wear."));
170170
}
171171
else
172172
{
173-
QtUtils::MessageBoxCritical(win, win->windowTitle(), tr("Trace logging to cpu_log.txt stopped."));
173+
QtUtils::AsyncMessageBox(win, QMessageBox::Critical, win->windowTitle(),
174+
tr("Trace logging to cpu_log.txt stopped."));
174175
}
175176
});
176177
});
@@ -261,8 +262,8 @@ void DebuggerWindow::onStepOutActionTriggered()
261262
Assert(QtHost::IsSystemPaused());
262263
if (!CPU::AddStepOutBreakpoint())
263264
{
264-
QtUtils::MessageBoxCritical(this, tr("Debugger"),
265-
tr("Failed to add step-out breakpoint, are you in a valid function?"));
265+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Debugger"),
266+
tr("Failed to add step-out breakpoint, are you in a valid function?"));
266267
return;
267268
}
268269

@@ -361,8 +362,8 @@ void DebuggerWindow::onMemorySearchTriggered()
361362
}
362363
else
363364
{
364-
QtUtils::MessageBoxCritical(this, windowTitle(),
365-
tr("Invalid search pattern. It should contain hex digits or question marks."));
365+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, windowTitle(),
366+
tr("Invalid search pattern. It should contain hex digits or question marks."));
366367
return;
367368
}
368369

@@ -388,8 +389,8 @@ void DebuggerWindow::onMemorySearchTriggered()
388389

389390
if (pattern.empty())
390391
{
391-
QtUtils::MessageBoxCritical(this, windowTitle(),
392-
tr("Invalid search pattern. It should contain hex digits or question marks."));
392+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, windowTitle(),
393+
tr("Invalid search pattern. It should contain hex digits or question marks."));
393394
return;
394395
}
395396

@@ -711,8 +712,8 @@ void DebuggerWindow::addBreakpoint(CPU::BreakpointType type, u32 address)
711712

712713
if (!result)
713714
{
714-
QtUtils::MessageBoxCritical(win, win->windowTitle(),
715-
tr("Failed to add breakpoint. A breakpoint may already exist at this address."));
715+
QtUtils::AsyncMessageBox(win, QMessageBox::Critical, win->windowTitle(),
716+
tr("Failed to add breakpoint. A breakpoint may already exist at this address."));
716717
return;
717718
}
718719

@@ -732,8 +733,8 @@ void DebuggerWindow::removeBreakpoint(CPU::BreakpointType type, u32 address)
732733

733734
if (!result)
734735
{
735-
QtUtils::MessageBoxCritical(win, win->windowTitle(),
736-
tr("Failed to remove breakpoint. This breakpoint may not exist."));
736+
QtUtils::AsyncMessageBox(win, QMessageBox::Critical, win->windowTitle(),
737+
tr("Failed to remove breakpoint. This breakpoint may not exist."));
737738
return;
738739
}
739740

src/duckstation-qt/gamecheatsettingswidget.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,11 @@ void GameCheatSettingsWidget::checkForMasterDisable()
396396

397397
if (!game_settings_enabled)
398398
{
399-
QMessageBox* mbox = QtUtils::NewMessageBox(
399+
QMessageBox* const mbox = QtUtils::NewMessageBox(
400400
this, QMessageBox::Warning, tr("Confirm Game Settings Enable"),
401401
tr("<h3>Game settings are currently disabled.</h3><p>This is <strong>not</strong> the default. Enabling this "
402402
"cheat will not have any effect until game settings are enabled. Do you want to do this now?"),
403-
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton);
403+
QMessageBox::Yes | QMessageBox::No);
404404
QCheckBox* cb = new QCheckBox(mbox);
405405
cb->setText(tr("Do not show again"));
406406
mbox->setCheckBox(cb);
@@ -416,11 +416,11 @@ void GameCheatSettingsWidget::checkForMasterDisable()
416416

417417
if (!cheats_enabled)
418418
{
419-
QMessageBox* mbox = QtUtils::NewMessageBox(
419+
QMessageBox* const mbox = QtUtils::NewMessageBox(
420420
this, QMessageBox::Warning, tr("Confirm Cheat Enable"),
421421
tr("<h3>Cheats are not currently enabled for this game.</h3><p>Enabling this cheat will not have any "
422422
"effect until cheats are enabled for this game. Do you want to do this now?"),
423-
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton);
423+
QMessageBox::Yes | QMessageBox::No);
424424
QCheckBox* cb = new QCheckBox(mbox);
425425
cb->setText(tr("Do not show again"));
426426
cb->setChecked(m_master_enable_ignored);
@@ -574,8 +574,8 @@ void GameCheatSettingsWidget::onImportFromFileTriggered()
574574
const std::optional<std::string> file_contents = FileSystem::ReadFileToString(filename.toStdString().c_str(), &error);
575575
if (!file_contents.has_value())
576576
{
577-
QtUtils::MessageBoxCritical(this, tr("Error"),
578-
tr("Failed to read file:\n%1").arg(QString::fromStdString(error.GetDescription())));
577+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
578+
tr("Failed to read file:\n%1").arg(QString::fromStdString(error.GetDescription())));
579579
return;
580580
}
581581

@@ -597,15 +597,15 @@ void GameCheatSettingsWidget::importCodes(const std::string& file_contents)
597597
Cheats::CodeInfoList new_codes;
598598
if (!Cheats::ImportCodesFromString(&new_codes, file_contents, Cheats::FileFormat::Unknown, true, &error))
599599
{
600-
QtUtils::MessageBoxCritical(this, tr("Error"),
601-
tr("Failed to parse file:\n%1").arg(QString::fromStdString(error.GetDescription())));
600+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
601+
tr("Failed to parse file:\n%1").arg(QString::fromStdString(error.GetDescription())));
602602
return;
603603
}
604604

605605
if (!Cheats::SaveCodesToFile(getPathForSavingCheats().c_str(), new_codes, &error))
606606
{
607-
QtUtils::MessageBoxCritical(this, tr("Error"),
608-
tr("Failed to save file:\n%1").arg(QString::fromStdString(error.GetDescription())));
607+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
608+
tr("Failed to save file:\n%1").arg(QString::fromStdString(error.GetDescription())));
609609
}
610610

611611
reloadList();
@@ -651,8 +651,8 @@ void GameCheatSettingsWidget::removeCode(const std::string_view code_name, bool
651651

652652
if (code->from_database)
653653
{
654-
QtUtils::MessageBoxCritical(
655-
this, tr("Error"),
654+
QtUtils::AsyncMessageBox(
655+
this, QMessageBox::Critical, tr("Error"),
656656
tr("This code is from the built-in cheat database, and cannot be removed. To hide this code, "
657657
"uncheck the \"Load Database Cheats\" option."));
658658
return;
@@ -670,8 +670,8 @@ void GameCheatSettingsWidget::removeCode(const std::string_view code_name, bool
670670
Error error;
671671
if (!Cheats::UpdateCodeInFile(getPathForSavingCheats().c_str(), code->name, nullptr, &error))
672672
{
673-
QtUtils::MessageBoxCritical(this, tr("Error"),
674-
tr("Failed to save file:\n%1").arg(QString::fromStdString(error.GetDescription())));
673+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
674+
tr("Failed to save file:\n%1").arg(QString::fromStdString(error.GetDescription())));
675675
return;
676676
}
677677

@@ -690,8 +690,8 @@ void GameCheatSettingsWidget::onExportClicked()
690690
Error error;
691691
if (!Cheats::ExportCodesToFile(filename.toStdString(), m_codes, &error))
692692
{
693-
QtUtils::MessageBoxCritical(
694-
this, tr("Error"), tr("Failed to save cheat file:\n%1").arg(QString::fromStdString(error.GetDescription())));
693+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
694+
tr("Failed to save cheat file:\n%1").arg(QString::fromStdString(error.GetDescription())));
695695
}
696696
}
697697

@@ -843,14 +843,14 @@ void CheatCodeEditorDialog::saveClicked()
843843
std::string new_name = m_ui.name->text().toStdString();
844844
if (new_name.empty())
845845
{
846-
QtUtils::MessageBoxCritical(this, tr("Error"), tr("Name cannot be empty."));
846+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"), tr("Name cannot be empty."));
847847
return;
848848
}
849849

850850
std::string new_body = QtUtils::NormalizeLineEndings(m_ui.instructions->toPlainText()).trimmed().toStdString();
851851
if (new_body.empty())
852852
{
853-
QtUtils::MessageBoxCritical(this, tr("Error"), tr("Instructions cannot be empty."));
853+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"), tr("Instructions cannot be empty."));
854854
return;
855855
}
856856

@@ -882,8 +882,8 @@ void CheatCodeEditorDialog::saveClicked()
882882
// if the name has changed, then we need to make sure it hasn't already been used
883883
if (new_name != m_code.name && m_parent->hasCodeWithName(new_name))
884884
{
885-
QtUtils::MessageBoxCritical(this, tr("Error"),
886-
tr("A code with the name '%1' already exists.").arg(QString::fromStdString(new_name)));
885+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
886+
tr("A code with the name '%1' already exists.").arg(QString::fromStdString(new_name)));
887887
return;
888888
}
889889

@@ -923,8 +923,9 @@ void CheatCodeEditorDialog::saveClicked()
923923
std::string path = m_parent->getPathForSavingCheats();
924924
if (!Cheats::UpdateCodeInFile(path.c_str(), old_name, &m_code, &error))
925925
{
926-
QtUtils::MessageBoxCritical(
927-
this, tr("Error"), tr("Failed to save cheat code:\n%1").arg(QString::fromStdString(error.GetDescription())));
926+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
927+
tr("Failed to save cheat code:\n%1").arg(QString::fromStdString(error.GetDescription())));
928+
return;
928929
}
929930

930931
accept();
@@ -1059,7 +1060,7 @@ void GameCheatCodeChoiceEditorDialog::onSaveClicked()
10591060
const int count = m_ui.optionList->topLevelItemCount();
10601061
if (count == 0)
10611062
{
1062-
QtUtils::MessageBoxCritical(this, tr("Error"), tr("At least one option must be defined."));
1063+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"), tr("At least one option must be defined."));
10631064
return;
10641065
}
10651066

@@ -1074,7 +1075,8 @@ void GameCheatCodeChoiceEditorDialog::onSaveClicked()
10741075

10751076
if (m_ui.optionList->topLevelItem(j)->text(0) == this_name)
10761077
{
1077-
QtUtils::MessageBoxCritical(this, tr("Error"), tr("The option '%1' is defined twice.").arg(this_name));
1078+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
1079+
tr("The option '%1' is defined twice.").arg(this_name));
10781080
return;
10791081
}
10801082
}
@@ -1083,8 +1085,8 @@ void GameCheatCodeChoiceEditorDialog::onSaveClicked()
10831085
const QString this_value = it->text(1);
10841086
if (bool ok; this_value.toUInt(&ok), !ok)
10851087
{
1086-
QtUtils::MessageBoxCritical(
1087-
this, tr("Error"), tr("The option '%1' does not have a valid value. It must be a number.").arg(this_name));
1088+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
1089+
tr("The option '%1' does not have a valid value. It must be a number.").arg(this_name));
10881090
return;
10891091
}
10901092
}

src/duckstation-qt/gamesummarywidget.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,8 @@ void GameSummaryWidget::onInputProfileChanged(int index)
403403
SettingsInterface* base_sif = Host::Internal::GetBaseSettingsLayer();
404404
InputManager::CopyConfiguration(sif, *base_sif, true, true, true, false);
405405

406-
QWidget* dlg_parent = QtUtils::GetRootWidget(this);
407-
QtUtils::MessageBoxInformation(dlg_parent, dlg_parent->windowTitle(),
408-
tr("Per-game controller configuration initialized with global settings."));
406+
QtUtils::AsyncMessageBox(this, QMessageBox::Information, QtUtils::GetRootWidget(this)->windowTitle(),
407+
tr("Per-game controller configuration initialized with global settings."));
409408
}
410409
}
411410
}

src/duckstation-qt/graphicssettingswidget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,8 @@ void TextureReplacementSettingsDialog::onExportClicked()
14271427
if (!FileSystem::WriteStringToFile(QDir::toNativeSeparators(path).toUtf8().constData(),
14281428
idlg->textValue().toStdString(), &error))
14291429
{
1430-
QtUtils::MessageBoxCritical(this, tr("Write Failed"), QString::fromStdString(error.GetDescription()));
1430+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Write Failed"),
1431+
QString::fromStdString(error.GetDescription()));
14311432
}
14321433
});
14331434
idlg->open();

src/duckstation-qt/inputbindingwidgets.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ void InputBindingWidget::showEffectBindingDialog()
444444
{
445445
if (!g_emu_thread->getInputDeviceListModel()->hasEffectsOfType(m_bind_type))
446446
{
447-
QtUtils::MessageBoxCritical(this, tr("Error"),
448-
(m_bind_type == InputBindingInfo::Type::Motor) ?
449-
tr("No devices with vibration motors were detected.") :
450-
tr("No devices with LEDs were detected."));
447+
QtUtils::AsyncMessageBox(this, QMessageBox::Critical, tr("Error"),
448+
(m_bind_type == InputBindingInfo::Type::Motor) ?
449+
tr("No devices with vibration motors were detected.") :
450+
tr("No devices with LEDs were detected."));
451451
return;
452452
}
453453

0 commit comments

Comments
 (0)