core, frontend: Better progress reporter

A new "quick" decryptor is implemented. This is not really much faster (not slower either) but provides the benefit of being able to report progress on a single file. The frontend is updated accordingly to support this feature.
This commit is contained in:
zhupengfei
2019-09-12 22:08:37 +08:00
parent ccffd51904
commit d55af0108e
14 changed files with 541 additions and 54 deletions
+20 -6
View File
@@ -266,18 +266,32 @@ void ImportDialog::StartImporting() {
auto* dialog = new QProgressDialog(tr("Initializing..."), tr("Cancel"), 0,
static_cast<int>(total_size / multiplier), this);
dialog->setWindowModality(Qt::WindowModal);
dialog->setMinimumDuration(0);
dialog->setValue(0);
auto* job = new ImportJob(this, importer, std::move(to_import));
connect(job, &ImportJob::ProgressUpdated, this,
[dialog, multiplier, total_count](u64 size_imported, u64 count,
Core::ContentSpecifier next_content) {
connect(job, &ImportJob::NextContent, this,
[this, dialog, multiplier, total_count](u64 size_imported, u64 count,
Core::ContentSpecifier next_content) {
dialog->setValue(static_cast<int>(size_imported / multiplier));
dialog->setLabelText(tr("Importing %1 (%2/%3)...")
.arg(GetContentName(next_content))
dialog->setLabelText(tr("(%1/%2) Importing %3...")
.arg(count)
.arg(total_count));
.arg(total_count)
.arg(GetContentName(next_content)));
current_content = next_content;
current_count = count;
});
connect(job, &ImportJob::ProgressUpdated, this,
[this, dialog, multiplier, total_count](u64 total_size_imported,
u64 current_size_imported) {
dialog->setValue(static_cast<int>(total_size_imported / multiplier));
dialog->setLabelText(tr("(%1/%2) Importing %3 (%4/%5)...")
.arg(current_count)
.arg(total_count)
.arg(GetContentName(current_content))
.arg(ReadableByteSize(current_size_imported))
.arg(ReadableByteSize(current_content.maximum_size)));
});
connect(job, &ImportJob::ErrorOccured, this,
[this, dialog](Core::ContentSpecifier current_content) {
+4
View File
@@ -41,4 +41,8 @@ private:
// HACK: To tell whether the checkbox state change is a programmatic trigger
// TODO: Is there a more elegant way of doing the same?
bool program_trigger = false;
// TODO: Why this won't work as locals?
Core::ContentSpecifier current_content = {};
u64 current_count = 0;
};
+12 -4
View File
@@ -15,10 +15,17 @@ ImportJob::~ImportJob() = default;
void ImportJob::run() {
u64 size_imported = 0, count = 0;
for (const auto& content : contents) {
emit ProgressUpdated(size_imported, count + 1, content);
if (!importer.ImportContent(content)) {
emit ErrorOccured(content);
return;
emit NextContent(size_imported, count + 1, content);
const auto callback = [this, size_imported](std::size_t current_size,
std::size_t /*total_size*/) {
emit ProgressUpdated(size_imported + current_size, current_size);
};
if (!importer.ImportContent(content, callback)) {
importer.DeleteContent(content);
if (!cancelled) {
emit ErrorOccured(content);
return;
}
}
count++;
size_imported += content.maximum_size;
@@ -32,4 +39,5 @@ void ImportJob::run() {
void ImportJob::Cancel() {
cancelled.store(true);
importer.Abort();
}
+11 -1
View File
@@ -20,7 +20,17 @@ public:
void Cancel();
signals:
void ProgressUpdated(u64 size_imported, u64 count, Core::ContentSpecifier next_content);
/**
* Called when progress is updated on the current content.
* @param total_size_imported Total imported size taking all previous contents into
* consideration.
* @param current_size_imported Imported size of the current content.
*/
void ProgressUpdated(u64 total_size_imported, u64 current_size_imported);
/// Dumping of a content has been finished, go on to the next. Called at start as well.
void NextContent(u64 size_imported, u64 count, Core::ContentSpecifier next_content);
void Completed();
void ErrorOccured(Core::ContentSpecifier current_content);