Rename ProgressiveJob to SimpleJob

Because I had to.
This commit is contained in:
Pengfei
2021-06-28 00:20:54 +08:00
parent 3db1c43fd6
commit 817c3ea1a8
5 changed files with 24 additions and 26 deletions
+2 -2
View File
@@ -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
@@ -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();
}
@@ -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<bool(const ProgressCallback&)>;
using AbortFunc = std::function<void()>;
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();
+11 -12
View File
@@ -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);
}
+2 -2
View File
@@ -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