mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-06 08:39:06 +00:00
Rename ProgressiveJob to SimpleJob
Because I had to.
This commit is contained in:
@@ -11,8 +11,8 @@ file(GLOB_RECURSE THEMES ${PROJECT_SOURCE_DIR}/dist/themes/*)
|
|||||||
add_executable(threeSD
|
add_executable(threeSD
|
||||||
helpers/import_job.cpp
|
helpers/import_job.cpp
|
||||||
helpers/import_job.h
|
helpers/import_job.h
|
||||||
helpers/progressive_job.cpp
|
helpers/simple_job.cpp
|
||||||
helpers/progressive_job.h
|
helpers/simple_job.h
|
||||||
import_dialog.cpp
|
import_dialog.cpp
|
||||||
import_dialog.h
|
import_dialog.h
|
||||||
import_dialog.ui
|
import_dialog.ui
|
||||||
|
|||||||
@@ -2,15 +2,14 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// 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_,
|
SimpleJob::SimpleJob(QObject* parent, ExecuteFunc execute_, AbortFunc abort_)
|
||||||
const AbortFunc& abort_)
|
: QThread(parent), execute(std::move(execute_)), abort(std::move(abort_)) {}
|
||||||
: QThread(parent), execute(execute_), abort(abort_) {}
|
|
||||||
|
|
||||||
ProgressiveJob::~ProgressiveJob() = default;
|
SimpleJob::~SimpleJob() = default;
|
||||||
|
|
||||||
void ProgressiveJob::run() {
|
void SimpleJob::run() {
|
||||||
const bool ret = execute(
|
const bool ret = execute(
|
||||||
[this](std::size_t current, std::size_t total) { emit ProgressUpdated(current, total); });
|
[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;
|
canceled = true;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
/**
|
/**
|
||||||
* Lightweight wrapper around QThread, for easy use with progressive jobs.
|
* Lightweight wrapper around QThread, for easy use with progressive jobs.
|
||||||
*/
|
*/
|
||||||
class ProgressiveJob : public QThread {
|
class SimpleJob : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -19,8 +19,8 @@ public:
|
|||||||
using ExecuteFunc = std::function<bool(const ProgressCallback&)>;
|
using ExecuteFunc = std::function<bool(const ProgressCallback&)>;
|
||||||
using AbortFunc = std::function<void()>;
|
using AbortFunc = std::function<void()>;
|
||||||
|
|
||||||
explicit ProgressiveJob(QObject* parent, const ExecuteFunc& execute, const AbortFunc& abort);
|
explicit SimpleJob(QObject* parent, ExecuteFunc execute, AbortFunc abort);
|
||||||
~ProgressiveJob() override;
|
~SimpleJob() override;
|
||||||
|
|
||||||
void run() override;
|
void run() override;
|
||||||
void Cancel();
|
void Cancel();
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scope_exit.h"
|
#include "common/scope_exit.h"
|
||||||
#include "frontend/helpers/import_job.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 "frontend/import_dialog.h"
|
||||||
#include "ui_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.
|
// 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
|
// We need to create the bar ourselves to circumvent an issue caused by modal ProgressDialog's
|
||||||
// event handling.
|
// event handling.
|
||||||
auto* bar = new QProgressBar(this);
|
auto* bar = new QProgressBar(this);
|
||||||
@@ -646,7 +646,7 @@ void ImportDialog::RunProgressiveJob(ProgressiveJob* job) {
|
|||||||
dialog->setWindowModality(Qt::WindowModal);
|
dialog->setWindowModality(Qt::WindowModal);
|
||||||
dialog->setMinimumDuration(0);
|
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
|
// Try to map total to int range
|
||||||
// This is equal to ceil(total / INT_MAX)
|
// This is equal to ceil(total / INT_MAX)
|
||||||
const u64 multiplier =
|
const u64 multiplier =
|
||||||
@@ -656,13 +656,12 @@ void ImportDialog::RunProgressiveJob(ProgressiveJob* job) {
|
|||||||
dialog->setLabelText(
|
dialog->setLabelText(
|
||||||
tr("%1 / %2").arg(ReadableByteSize(current)).arg(ReadableByteSize(total)));
|
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"),
|
QMessageBox::critical(this, tr("threeSD"),
|
||||||
tr("Operation failed. Please refer to the log."));
|
tr("Operation failed. Please refer to the log."));
|
||||||
dialog->hide();
|
dialog->hide();
|
||||||
});
|
});
|
||||||
connect(job, &ProgressiveJob::Completed, this,
|
connect(job, &SimpleJob::Completed, this, [dialog] { dialog->setValue(dialog->maximum()); });
|
||||||
[dialog] { dialog->setValue(dialog->maximum()); });
|
|
||||||
connect(dialog, &QProgressDialog::canceled, this, [job] { job->Cancel(); });
|
connect(dialog, &QProgressDialog::canceled, this, [job] { job->Cancel(); });
|
||||||
|
|
||||||
job->start();
|
job->start();
|
||||||
@@ -676,9 +675,9 @@ void ImportDialog::StartDumpingCXI(const Core::ContentSpecifier& specifier) {
|
|||||||
}
|
}
|
||||||
last_dump_cxi_path = QFileInfo(path).path();
|
last_dump_cxi_path = QFileInfo(path).path();
|
||||||
|
|
||||||
auto* job = new ProgressiveJob(
|
auto* job = new SimpleJob(
|
||||||
this,
|
this,
|
||||||
[this, specifier, path](const ProgressiveJob::ProgressCallback& callback) {
|
[this, specifier, path](const SimpleJob::ProgressCallback& callback) {
|
||||||
if (!importer.DumpCXI(specifier, path.toStdString(), callback)) {
|
if (!importer.DumpCXI(specifier, path.toStdString(), callback)) {
|
||||||
FileUtil::Delete(path.toStdString());
|
FileUtil::Delete(path.toStdString());
|
||||||
return false;
|
return false;
|
||||||
@@ -686,7 +685,7 @@ void ImportDialog::StartDumpingCXI(const Core::ContentSpecifier& specifier) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[this] { importer.AbortDumpCXI(); });
|
[this] { importer.AbortDumpCXI(); });
|
||||||
RunProgressiveJob(job);
|
RunSimpleJob(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportDialog::StartBuildingCIA(const Core::ContentSpecifier& specifier) {
|
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();
|
last_build_cia_path = QFileInfo(path).path();
|
||||||
|
|
||||||
auto* job = new ProgressiveJob(
|
auto* job = new SimpleJob(
|
||||||
this,
|
this,
|
||||||
[this, specifier, path](const ProgressiveJob::ProgressCallback& callback) {
|
[this, specifier, path](const SimpleJob::ProgressCallback& callback) {
|
||||||
if (!importer.BuildCIA(specifier, path.toStdString(), callback)) {
|
if (!importer.BuildCIA(specifier, path.toStdString(), callback)) {
|
||||||
FileUtil::Delete(path.toStdString());
|
FileUtil::Delete(path.toStdString());
|
||||||
return false;
|
return false;
|
||||||
@@ -707,5 +706,5 @@ void ImportDialog::StartBuildingCIA(const Core::ContentSpecifier& specifier) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[this] { importer.AbortBuildCIA(); });
|
[this] { importer.AbortBuildCIA(); });
|
||||||
RunProgressiveJob(job);
|
RunSimpleJob(job);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "core/importer.h"
|
#include "core/importer.h"
|
||||||
#include "core/ncch/ncch_container.h"
|
#include "core/ncch/ncch_container.h"
|
||||||
|
|
||||||
class ProgressiveJob;
|
class SimpleJob;
|
||||||
class QTreeWidgetItem;
|
class QTreeWidgetItem;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -43,7 +43,7 @@ private:
|
|||||||
Core::ContentSpecifier SpecifierFromItem(QTreeWidgetItem* item) const;
|
Core::ContentSpecifier SpecifierFromItem(QTreeWidgetItem* item) const;
|
||||||
void OnContextMenu(const QPoint& point);
|
void OnContextMenu(const QPoint& point);
|
||||||
|
|
||||||
void RunProgressiveJob(ProgressiveJob* job);
|
void RunSimpleJob(SimpleJob* job);
|
||||||
|
|
||||||
void StartDumpingCXI(const Core::ContentSpecifier& content);
|
void StartDumpingCXI(const Core::ContentSpecifier& content);
|
||||||
QString last_dump_cxi_path; // Used for recording last path in StartDumpingCXI
|
QString last_dump_cxi_path; // Used for recording last path in StartDumpingCXI
|
||||||
|
|||||||
Reference in New Issue
Block a user