From c6ee767851dee68bfc67bcbe7f176512080b7e7c Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 30 Mar 2020 00:28:16 +0200 Subject: DolphinQt: Run tasks that use progress dialogs on separate threads --- Source/Core/DolphinQt/Config/VerifyWidget.cpp | 73 ++++++++++++++++----------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'Source/Core/DolphinQt/Config/VerifyWidget.cpp') diff --git a/Source/Core/DolphinQt/Config/VerifyWidget.cpp b/Source/Core/DolphinQt/Config/VerifyWidget.cpp index 925409a81c..ce221bce8f 100644 --- a/Source/Core/DolphinQt/Config/VerifyWidget.cpp +++ b/Source/Core/DolphinQt/Config/VerifyWidget.cpp @@ -4,7 +4,9 @@ #include "DolphinQt/Config/VerifyWidget.h" +#include #include +#include #include #include @@ -12,12 +14,12 @@ #include #include #include -#include #include #include "Common/CommonTypes.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeVerifier.h" +#include "DolphinQt/QtUtils/ParallelProgressDialog.h" VerifyWidget::VerifyWidget(std::shared_ptr volume) : m_volume(std::move(volume)) { @@ -131,33 +133,44 @@ void VerifyWidget::Verify() // We have to divide the number of processed bytes with something so it won't make ints overflow constexpr int DIVISOR = 0x100; - QProgressDialog progress(tr("Verifying"), tr("Cancel"), 0, verifier.GetTotalBytes() / DIVISOR, - this); - progress.setWindowTitle(tr("Verifying")); - progress.setWindowFlags(progress.windowFlags() & ~Qt::WindowContextHelpButtonHint); - progress.setMinimumDuration(500); - progress.setWindowModality(Qt::WindowModal); - - verifier.Start(); - while (verifier.GetBytesProcessed() != verifier.GetTotalBytes()) - { - progress.setValue(verifier.GetBytesProcessed() / DIVISOR); - if (progress.wasCanceled()) - return; - - verifier.Process(); - } - verifier.Finish(); - - DiscIO::VolumeVerifier::Result result = verifier.GetResult(); - progress.setValue(verifier.GetBytesProcessed() / DIVISOR); - - m_summary_text->setText(QString::fromStdString(result.summary_text)); - - m_problems->setRowCount(static_cast(result.problems.size())); + ParallelProgressDialog progress(tr("Verifying"), tr("Cancel"), 0, + static_cast(verifier.GetTotalBytes() / DIVISOR), this); + progress.GetRaw()->setWindowTitle(tr("Verifying")); + progress.GetRaw()->setMinimumDuration(500); + progress.GetRaw()->setWindowModality(Qt::WindowModal); + + auto future = + std::async(std::launch::async, + [&verifier, &progress]() -> std::optional { + progress.SetValue(0); + verifier.Start(); + while (verifier.GetBytesProcessed() != verifier.GetTotalBytes()) + { + progress.SetValue(static_cast(verifier.GetBytesProcessed() / DIVISOR)); + if (progress.WasCanceled()) + return std::nullopt; + + verifier.Process(); + } + verifier.Finish(); + + const DiscIO::VolumeVerifier::Result result = verifier.GetResult(); + progress.Reset(); + + return result; + }); + progress.GetRaw()->exec(); + + std::optional result = future.get(); + if (!result) + return; + + m_summary_text->setText(QString::fromStdString(result->summary_text)); + + m_problems->setRowCount(static_cast(result->problems.size())); for (int i = 0; i < m_problems->rowCount(); ++i) { - const DiscIO::VolumeVerifier::Problem problem = result.problems[i]; + const DiscIO::VolumeVerifier::Problem problem = result->problems[i]; QString severity; switch (problem.severity) @@ -179,12 +192,12 @@ void VerifyWidget::Verify() SetProblemCellText(i, 1, severity); } - SetHash(m_crc32_line_edit, result.hashes.crc32); - SetHash(m_md5_line_edit, result.hashes.md5); - SetHash(m_sha1_line_edit, result.hashes.sha1); + SetHash(m_crc32_line_edit, result->hashes.crc32); + SetHash(m_md5_line_edit, result->hashes.md5); + SetHash(m_sha1_line_edit, result->hashes.sha1); if (m_redump_line_edit) - m_redump_line_edit->setText(QString::fromStdString(result.redump.message)); + m_redump_line_edit->setText(QString::fromStdString(result->redump.message)); } void VerifyWidget::SetProblemCellText(int row, int column, QString text) -- cgit v1.2.3