mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-26 06:18:32 +00:00
DolphinQt: Run tasks that use progress dialogs on separate threads
This commit is contained in:
parent
4ff855921e
commit
c6ee767851
10 changed files with 225 additions and 82 deletions
|
@ -87,6 +87,7 @@
|
|||
#include "DolphinQt/NetPlay/NetPlaySetupDialog.h"
|
||||
#include "DolphinQt/QtUtils/FileOpenEventFilter.h"
|
||||
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
||||
#include "DolphinQt/QtUtils/ParallelProgressDialog.h"
|
||||
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
||||
#include "DolphinQt/QtUtils/RunOnObject.h"
|
||||
#include "DolphinQt/QtUtils/WindowActivationEventFilter.h"
|
||||
|
@ -1510,23 +1511,21 @@ void MainWindow::OnImportNANDBackup()
|
|||
if (file.isEmpty())
|
||||
return;
|
||||
|
||||
QProgressDialog* dialog = new QProgressDialog(this);
|
||||
dialog->setMinimum(0);
|
||||
dialog->setMaximum(0);
|
||||
dialog->setLabelText(tr("Importing NAND backup"));
|
||||
dialog->setCancelButton(nullptr);
|
||||
ParallelProgressDialog dialog(this);
|
||||
dialog.GetRaw()->setMinimum(0);
|
||||
dialog.GetRaw()->setMaximum(0);
|
||||
dialog.GetRaw()->setLabelText(tr("Importing NAND backup"));
|
||||
dialog.GetRaw()->setCancelButton(nullptr);
|
||||
|
||||
auto beginning = QDateTime::currentDateTime().toMSecsSinceEpoch();
|
||||
|
||||
auto result = std::async(std::launch::async, [&] {
|
||||
std::future<void> result = std::async(std::launch::async, [&] {
|
||||
DiscIO::NANDImporter().ImportNANDBin(
|
||||
file.toStdString(),
|
||||
[&dialog, beginning] {
|
||||
QueueOnObject(dialog, [&dialog, beginning] {
|
||||
dialog->setLabelText(
|
||||
tr("Importing NAND backup\n Time elapsed: %1s")
|
||||
.arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000));
|
||||
});
|
||||
dialog.SetLabelText(
|
||||
tr("Importing NAND backup\n Time elapsed: %1s")
|
||||
.arg((QDateTime::currentDateTime().toMSecsSinceEpoch() - beginning) / 1000));
|
||||
},
|
||||
[this] {
|
||||
std::optional<std::string> keys_file = RunOnObject(this, [this] {
|
||||
|
@ -1540,10 +1539,10 @@ void MainWindow::OnImportNANDBackup()
|
|||
return *keys_file;
|
||||
return std::string("");
|
||||
});
|
||||
QueueOnObject(dialog, &QProgressDialog::close);
|
||||
dialog.Reset();
|
||||
});
|
||||
|
||||
dialog->exec();
|
||||
dialog.GetRaw()->exec();
|
||||
|
||||
result.wait();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue