mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
DolphinQt: Run tasks that use progress dialogs on separate threads
This commit is contained in:
@ -10,7 +10,6 @@
|
||||
#include <QFileInfo>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QProgressDialog>
|
||||
#include <QStandardItemModel>
|
||||
#include <QStyleFactory>
|
||||
#include <QTreeView>
|
||||
@ -23,6 +22,7 @@
|
||||
#include "DiscIO/Volume.h"
|
||||
|
||||
#include "DolphinQt/QtUtils/ModalMessageBox.h"
|
||||
#include "DolphinQt/QtUtils/ParallelProgressDialog.h"
|
||||
#include "DolphinQt/Resources.h"
|
||||
|
||||
#include "UICommon/UICommon.h"
|
||||
@ -282,28 +282,34 @@ void FilesystemWidget::ExtractDirectory(const DiscIO::Partition& partition, cons
|
||||
std::unique_ptr<DiscIO::FileInfo> info = filesystem->FindFileInfo(path.toStdString());
|
||||
u32 size = info->GetTotalChildren();
|
||||
|
||||
QProgressDialog* dialog = new QProgressDialog(this);
|
||||
dialog->setWindowFlags(dialog->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
dialog->setMinimum(0);
|
||||
dialog->setMaximum(size);
|
||||
dialog->show();
|
||||
dialog->setWindowTitle(tr("Progress"));
|
||||
ParallelProgressDialog dialog(this);
|
||||
dialog.GetRaw()->setMinimum(0);
|
||||
dialog.GetRaw()->setMaximum(size);
|
||||
dialog.GetRaw()->setWindowTitle(tr("Progress"));
|
||||
|
||||
bool all = path.isEmpty();
|
||||
const bool all = path.isEmpty();
|
||||
|
||||
DiscIO::ExportDirectory(
|
||||
*m_volume, partition, *info, true, path.toStdString(), out.toStdString(),
|
||||
[all, dialog](const std::string& current) {
|
||||
dialog->setLabelText(
|
||||
(all ? QObject::tr("Extracting All Files...") : QObject::tr("Extracting Directory..."))
|
||||
.append(QStringLiteral(" %1").arg(QString::fromStdString(current))));
|
||||
dialog->setValue(dialog->value() + 1);
|
||||
std::future<void> future = std::async(std::launch::async, [&] {
|
||||
int progress = 0;
|
||||
|
||||
QCoreApplication::processEvents();
|
||||
return dialog->wasCanceled();
|
||||
});
|
||||
DiscIO::ExportDirectory(
|
||||
*m_volume, partition, *info, true, path.toStdString(), out.toStdString(),
|
||||
[all, &dialog, &progress](const std::string& current) {
|
||||
dialog.SetLabelText(
|
||||
(all ? QObject::tr("Extracting All Files...") :
|
||||
QObject::tr("Extracting Directory..."))
|
||||
.append(QStringLiteral(" %1").arg(QString::fromStdString(current))));
|
||||
dialog.SetValue(++progress);
|
||||
|
||||
dialog->close();
|
||||
QCoreApplication::processEvents();
|
||||
return dialog.WasCanceled();
|
||||
});
|
||||
|
||||
dialog.Reset();
|
||||
});
|
||||
|
||||
dialog.GetRaw()->exec();
|
||||
future.get();
|
||||
}
|
||||
|
||||
void FilesystemWidget::ExtractFile(const DiscIO::Partition& partition, const QString& path,
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QProgressDialog>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
#include "DolphinQt/Config/VerifyWidget.h"
|
||||
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
@ -12,12 +14,12 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QProgressDialog>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DiscIO/Volume.h"
|
||||
#include "DiscIO/VolumeVerifier.h"
|
||||
#include "DolphinQt/QtUtils/ParallelProgressDialog.h"
|
||||
|
||||
VerifyWidget::VerifyWidget(std::shared_ptr<DiscIO::Volume> 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);
|
||||
ParallelProgressDialog progress(tr("Verifying"), tr("Cancel"), 0,
|
||||
static_cast<int>(verifier.GetTotalBytes() / DIVISOR), this);
|
||||
progress.GetRaw()->setWindowTitle(tr("Verifying"));
|
||||
progress.GetRaw()->setMinimumDuration(500);
|
||||
progress.GetRaw()->setWindowModality(Qt::WindowModal);
|
||||
|
||||
verifier.Start();
|
||||
while (verifier.GetBytesProcessed() != verifier.GetTotalBytes())
|
||||
{
|
||||
progress.setValue(verifier.GetBytesProcessed() / DIVISOR);
|
||||
if (progress.wasCanceled())
|
||||
return;
|
||||
auto future =
|
||||
std::async(std::launch::async,
|
||||
[&verifier, &progress]() -> std::optional<DiscIO::VolumeVerifier::Result> {
|
||||
progress.SetValue(0);
|
||||
verifier.Start();
|
||||
while (verifier.GetBytesProcessed() != verifier.GetTotalBytes())
|
||||
{
|
||||
progress.SetValue(static_cast<int>(verifier.GetBytesProcessed() / DIVISOR));
|
||||
if (progress.WasCanceled())
|
||||
return std::nullopt;
|
||||
|
||||
verifier.Process();
|
||||
}
|
||||
verifier.Finish();
|
||||
verifier.Process();
|
||||
}
|
||||
verifier.Finish();
|
||||
|
||||
DiscIO::VolumeVerifier::Result result = verifier.GetResult();
|
||||
progress.setValue(verifier.GetBytesProcessed() / DIVISOR);
|
||||
const DiscIO::VolumeVerifier::Result result = verifier.GetResult();
|
||||
progress.Reset();
|
||||
|
||||
m_summary_text->setText(QString::fromStdString(result.summary_text));
|
||||
return result;
|
||||
});
|
||||
progress.GetRaw()->exec();
|
||||
|
||||
m_problems->setRowCount(static_cast<int>(result.problems.size()));
|
||||
std::optional<DiscIO::VolumeVerifier::Result> result = future.get();
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
m_summary_text->setText(QString::fromStdString(result->summary_text));
|
||||
|
||||
m_problems->setRowCount(static_cast<int>(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)
|
||||
|
Reference in New Issue
Block a user