From 817c3ea1a846be939e15a1329e9e3be610fa0da2 Mon Sep 17 00:00:00 2001 From: Pengfei Date: Mon, 28 Jun 2021 00:20:54 +0800 Subject: [PATCH] Rename ProgressiveJob to SimpleJob Because I had to. --- src/frontend/CMakeLists.txt | 4 ++-- .../{progressive_job.cpp => simple_job.cpp} | 13 +++++------ .../{progressive_job.h => simple_job.h} | 6 ++--- src/frontend/import_dialog.cpp | 23 +++++++++---------- src/frontend/import_dialog.h | 4 ++-- 5 files changed, 24 insertions(+), 26 deletions(-) rename src/frontend/helpers/{progressive_job.cpp => simple_job.cpp} (53%) rename src/frontend/helpers/{progressive_job.h => simple_job.h} (81%) diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index d9f7e17..a459ab4 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -11,8 +11,8 @@ file(GLOB_RECURSE THEMES ${PROJECT_SOURCE_DIR}/dist/themes/*) add_executable(threeSD helpers/import_job.cpp helpers/import_job.h - helpers/progressive_job.cpp - helpers/progressive_job.h + helpers/simple_job.cpp + helpers/simple_job.h import_dialog.cpp import_dialog.h import_dialog.ui diff --git a/src/frontend/helpers/progressive_job.cpp b/src/frontend/helpers/simple_job.cpp similarity index 53% rename from src/frontend/helpers/progressive_job.cpp rename to src/frontend/helpers/simple_job.cpp index 0439fe4..2ca001d 100644 --- a/src/frontend/helpers/progressive_job.cpp +++ b/src/frontend/helpers/simple_job.cpp @@ -2,15 +2,14 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "frontend/helpers/progressive_job.h" +#include "frontend/helpers/simple_job.h" -ProgressiveJob::ProgressiveJob(QObject* parent, const ExecuteFunc& execute_, - const AbortFunc& abort_) - : QThread(parent), execute(execute_), abort(abort_) {} +SimpleJob::SimpleJob(QObject* parent, ExecuteFunc execute_, AbortFunc abort_) + : QThread(parent), execute(std::move(execute_)), abort(std::move(abort_)) {} -ProgressiveJob::~ProgressiveJob() = default; +SimpleJob::~SimpleJob() = default; -void ProgressiveJob::run() { +void SimpleJob::run() { const bool ret = execute( [this](std::size_t current, std::size_t total) { emit ProgressUpdated(current, total); }); @@ -21,7 +20,7 @@ void ProgressiveJob::run() { } } -void ProgressiveJob::Cancel() { +void SimpleJob::Cancel() { canceled = true; abort(); } diff --git a/src/frontend/helpers/progressive_job.h b/src/frontend/helpers/simple_job.h similarity index 81% rename from src/frontend/helpers/progressive_job.h rename to src/frontend/helpers/simple_job.h index 2787617..42931e6 100644 --- a/src/frontend/helpers/progressive_job.h +++ b/src/frontend/helpers/simple_job.h @@ -11,7 +11,7 @@ /** * Lightweight wrapper around QThread, for easy use with progressive jobs. */ -class ProgressiveJob : public QThread { +class SimpleJob : public QThread { Q_OBJECT public: @@ -19,8 +19,8 @@ public: using ExecuteFunc = std::function; using AbortFunc = std::function; - explicit ProgressiveJob(QObject* parent, const ExecuteFunc& execute, const AbortFunc& abort); - ~ProgressiveJob() override; + explicit SimpleJob(QObject* parent, ExecuteFunc execute, AbortFunc abort); + ~SimpleJob() override; void run() override; void Cancel(); diff --git a/src/frontend/import_dialog.cpp b/src/frontend/import_dialog.cpp index f38cd44..1c2acb5 100644 --- a/src/frontend/import_dialog.cpp +++ b/src/frontend/import_dialog.cpp @@ -20,7 +20,7 @@ #include "common/logging/log.h" #include "common/scope_exit.h" #include "frontend/helpers/import_job.h" -#include "frontend/helpers/progressive_job.h" +#include "frontend/helpers/simple_job.h" #include "frontend/import_dialog.h" #include "ui_import_dialog.h" @@ -634,7 +634,7 @@ void ImportDialog::OnContextMenu(const QPoint& point) { } // Runs the job, opening a dialog to report its progress. -void ImportDialog::RunProgressiveJob(ProgressiveJob* job) { +void ImportDialog::RunSimpleJob(SimpleJob* job) { // We need to create the bar ourselves to circumvent an issue caused by modal ProgressDialog's // event handling. auto* bar = new QProgressBar(this); @@ -646,7 +646,7 @@ void ImportDialog::RunProgressiveJob(ProgressiveJob* job) { dialog->setWindowModality(Qt::WindowModal); dialog->setMinimumDuration(0); - connect(job, &ProgressiveJob::ProgressUpdated, this, [bar, dialog](u64 current, u64 total) { + connect(job, &SimpleJob::ProgressUpdated, this, [bar, dialog](u64 current, u64 total) { // Try to map total to int range // This is equal to ceil(total / INT_MAX) const u64 multiplier = @@ -656,13 +656,12 @@ void ImportDialog::RunProgressiveJob(ProgressiveJob* job) { dialog->setLabelText( tr("%1 / %2").arg(ReadableByteSize(current)).arg(ReadableByteSize(total))); }); - connect(job, &ProgressiveJob::ErrorOccured, this, [this, dialog] { + connect(job, &SimpleJob::ErrorOccured, this, [this, dialog] { QMessageBox::critical(this, tr("threeSD"), tr("Operation failed. Please refer to the log.")); dialog->hide(); }); - connect(job, &ProgressiveJob::Completed, this, - [dialog] { dialog->setValue(dialog->maximum()); }); + connect(job, &SimpleJob::Completed, this, [dialog] { dialog->setValue(dialog->maximum()); }); connect(dialog, &QProgressDialog::canceled, this, [job] { job->Cancel(); }); job->start(); @@ -676,9 +675,9 @@ void ImportDialog::StartDumpingCXI(const Core::ContentSpecifier& specifier) { } last_dump_cxi_path = QFileInfo(path).path(); - auto* job = new ProgressiveJob( + auto* job = new SimpleJob( this, - [this, specifier, path](const ProgressiveJob::ProgressCallback& callback) { + [this, specifier, path](const SimpleJob::ProgressCallback& callback) { if (!importer.DumpCXI(specifier, path.toStdString(), callback)) { FileUtil::Delete(path.toStdString()); return false; @@ -686,7 +685,7 @@ void ImportDialog::StartDumpingCXI(const Core::ContentSpecifier& specifier) { return true; }, [this] { importer.AbortDumpCXI(); }); - RunProgressiveJob(job); + RunSimpleJob(job); } void ImportDialog::StartBuildingCIA(const Core::ContentSpecifier& specifier) { @@ -697,9 +696,9 @@ void ImportDialog::StartBuildingCIA(const Core::ContentSpecifier& specifier) { } last_build_cia_path = QFileInfo(path).path(); - auto* job = new ProgressiveJob( + auto* job = new SimpleJob( this, - [this, specifier, path](const ProgressiveJob::ProgressCallback& callback) { + [this, specifier, path](const SimpleJob::ProgressCallback& callback) { if (!importer.BuildCIA(specifier, path.toStdString(), callback)) { FileUtil::Delete(path.toStdString()); return false; @@ -707,5 +706,5 @@ void ImportDialog::StartBuildingCIA(const Core::ContentSpecifier& specifier) { return true; }, [this] { importer.AbortBuildCIA(); }); - RunProgressiveJob(job); + RunSimpleJob(job); } diff --git a/src/frontend/import_dialog.h b/src/frontend/import_dialog.h index 3684534..27eb1f1 100644 --- a/src/frontend/import_dialog.h +++ b/src/frontend/import_dialog.h @@ -12,7 +12,7 @@ #include "core/importer.h" #include "core/ncch/ncch_container.h" -class ProgressiveJob; +class SimpleJob; class QTreeWidgetItem; namespace Ui { @@ -43,7 +43,7 @@ private: Core::ContentSpecifier SpecifierFromItem(QTreeWidgetItem* item) const; void OnContextMenu(const QPoint& point); - void RunProgressiveJob(ProgressiveJob* job); + void RunSimpleJob(SimpleJob* job); void StartDumpingCXI(const Core::ContentSpecifier& content); QString last_dump_cxi_path; // Used for recording last path in StartDumpingCXI