mirror of https://github.com/procxx/kepka.git
Allow uploading many scans at once in passport.
This commit is contained in:
parent
7be1f16313
commit
da60739893
|
@ -945,20 +945,24 @@ void PanelController::editWithUpload(int index, int documentIndex) {
|
||||||
Expects(documentIndex >= 0
|
Expects(documentIndex >= 0
|
||||||
&& documentIndex < _scopes[index].documents.size());
|
&& documentIndex < _scopes[index].documents.size());
|
||||||
|
|
||||||
|
const auto &document = _scopes[index].documents[documentIndex];
|
||||||
|
const auto requiresSpecialScan = document->requiresSpecialScan(
|
||||||
|
SpecialFile::FrontSide,
|
||||||
|
false);
|
||||||
|
const auto allowMany = !requiresSpecialScan;
|
||||||
const auto widget = _panel->widget();
|
const auto widget = _panel->widget();
|
||||||
EditScans::ChooseScan(widget.get(), [=](QByteArray &&content) {
|
EditScans::ChooseScan(widget.get(), [=](QByteArray &&content) {
|
||||||
base::take(_scopeDocumentTypeBox);
|
if (!_editScope || !_editDocument) {
|
||||||
editScope(index, documentIndex);
|
editScope(index, documentIndex);
|
||||||
if (_scopes[index].documents[documentIndex]->requiresSpecialScan(
|
}
|
||||||
SpecialFile::FrontSide,
|
if (requiresSpecialScan) {
|
||||||
false)) {
|
|
||||||
uploadSpecialScan(SpecialFile::FrontSide, std::move(content));
|
uploadSpecialScan(SpecialFile::FrontSide, std::move(content));
|
||||||
} else {
|
} else {
|
||||||
uploadScan(std::move(content));
|
uploadScan(std::move(content));
|
||||||
}
|
}
|
||||||
}, [=](ReadScanError error) {
|
}, [=](ReadScanError error) {
|
||||||
readScanError(error);
|
readScanError(error);
|
||||||
});
|
}, allowMany);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PanelController::readScanError(ReadScanError error) {
|
void PanelController::readScanError(ReadScanError error) {
|
||||||
|
|
|
@ -659,7 +659,7 @@ void EditScans::chooseScan() {
|
||||||
_controller->uploadScan(std::move(content));
|
_controller->uploadScan(std::move(content));
|
||||||
}, [=](ReadScanError error) {
|
}, [=](ReadScanError error) {
|
||||||
_controller->readScanError(error);
|
_controller->readScanError(error);
|
||||||
});
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditScans::chooseSpecialScan(SpecialFile type) {
|
void EditScans::chooseSpecialScan(SpecialFile type) {
|
||||||
|
@ -667,24 +667,33 @@ void EditScans::chooseSpecialScan(SpecialFile type) {
|
||||||
_controller->uploadSpecialScan(type, std::move(content));
|
_controller->uploadSpecialScan(type, std::move(content));
|
||||||
}, [=](ReadScanError error) {
|
}, [=](ReadScanError error) {
|
||||||
_controller->readScanError(error);
|
_controller->readScanError(error);
|
||||||
});
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditScans::ChooseScan(
|
void EditScans::ChooseScan(
|
||||||
QPointer<QWidget> parent,
|
QPointer<QWidget> parent,
|
||||||
Fn<void(QByteArray&&)> doneCallback,
|
Fn<void(QByteArray&&)> doneCallback,
|
||||||
Fn<void(ReadScanError)> errorCallback) {
|
Fn<void(ReadScanError)> errorCallback,
|
||||||
|
bool allowMany) {
|
||||||
Expects(parent != nullptr);
|
Expects(parent != nullptr);
|
||||||
|
|
||||||
|
const auto processFiles = std::make_shared<Fn<void(QStringList&&)>>();
|
||||||
const auto filter = FileDialog::AllFilesFilter()
|
const auto filter = FileDialog::AllFilesFilter()
|
||||||
+ qsl(";;Image files (*")
|
+ qsl(";;Image files (*")
|
||||||
+ cImgExtensions().join(qsl(" *"))
|
+ cImgExtensions().join(qsl(" *"))
|
||||||
+ qsl(")");
|
+ qsl(")");
|
||||||
const auto guardedCallback = crl::guard(parent, doneCallback);
|
const auto guardedCallback = crl::guard(parent, doneCallback);
|
||||||
const auto guardedError = crl::guard(parent, errorCallback);
|
const auto guardedError = crl::guard(parent, errorCallback);
|
||||||
const auto onMainCallback = [=](QByteArray content) {
|
const auto onMainCallback = [=](
|
||||||
crl::on_main([=, bytes = std::move(content)]() mutable {
|
QByteArray &&content,
|
||||||
|
QStringList &&remainingFiles) {
|
||||||
|
crl::on_main([
|
||||||
|
=,
|
||||||
|
bytes = std::move(content),
|
||||||
|
remainingFiles = std::move(remainingFiles)
|
||||||
|
]() mutable {
|
||||||
guardedCallback(std::move(bytes));
|
guardedCallback(std::move(bytes));
|
||||||
|
(*processFiles)(std::move(remainingFiles));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const auto onMainError = [=](ReadScanError error) {
|
const auto onMainError = [=](ReadScanError error) {
|
||||||
|
@ -692,22 +701,38 @@ void EditScans::ChooseScan(
|
||||||
guardedError(error);
|
guardedError(error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const auto processImage = [=](QByteArray &&content) {
|
const auto processImage = [=](
|
||||||
crl::async([=, bytes = std::move(content)]() mutable {
|
QByteArray &&content,
|
||||||
|
QStringList &&remainingFiles) {
|
||||||
|
crl::async([
|
||||||
|
=,
|
||||||
|
bytes = std::move(content),
|
||||||
|
remainingFiles = std::move(remainingFiles)
|
||||||
|
]() mutable {
|
||||||
auto result = ProcessImage(std::move(bytes));
|
auto result = ProcessImage(std::move(bytes));
|
||||||
if (const auto error = base::get_if<ReadScanError>(&result)) {
|
if (const auto error = base::get_if<ReadScanError>(&result)) {
|
||||||
onMainError(*error);
|
onMainError(*error);
|
||||||
} else {
|
} else {
|
||||||
auto content = base::get_if<QByteArray>(&result);
|
auto content = base::get_if<QByteArray>(&result);
|
||||||
Assert(content != nullptr);
|
Assert(content != nullptr);
|
||||||
onMainCallback(std::move(*content));
|
onMainCallback(std::move(*content), std::move(remainingFiles));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const auto processFile = [=](FileDialog::OpenResult &&result) {
|
const auto processOpened = [=](FileDialog::OpenResult &&result) {
|
||||||
if (result.paths.size() == 1) {
|
if (result.paths.size() > 0) {
|
||||||
|
(*processFiles)(std::move(result.paths));
|
||||||
|
} else if (!result.remoteContent.isEmpty()) {
|
||||||
|
processImage(std::move(result.remoteContent), {});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*processFiles = [=](QStringList &&files) {
|
||||||
|
while (!files.isEmpty()) {
|
||||||
|
auto file = files.front();
|
||||||
|
files.removeAt(0);
|
||||||
|
|
||||||
auto content = [&] {
|
auto content = [&] {
|
||||||
QFile f(result.paths.front());
|
QFile f(file);
|
||||||
if (f.size() > App::kImageSizeLimit) {
|
if (f.size() > App::kImageSizeLimit) {
|
||||||
guardedError(ReadScanError::FileTooLarge);
|
guardedError(ReadScanError::FileTooLarge);
|
||||||
return QByteArray();
|
return QByteArray();
|
||||||
|
@ -718,17 +743,17 @@ void EditScans::ChooseScan(
|
||||||
return f.readAll();
|
return f.readAll();
|
||||||
}();
|
}();
|
||||||
if (!content.isEmpty()) {
|
if (!content.isEmpty()) {
|
||||||
processImage(std::move(content));
|
processImage(std::move(content), std::move(files));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (!result.remoteContent.isEmpty()) {
|
|
||||||
processImage(std::move(result.remoteContent));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FileDialog::GetOpenPath(
|
(allowMany ? FileDialog::GetOpenPaths : FileDialog::GetOpenPath)(
|
||||||
parent,
|
parent,
|
||||||
lang(lng_passport_choose_image),
|
lang(lng_passport_choose_image),
|
||||||
filter,
|
filter,
|
||||||
processFile);
|
processOpened,
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpl::producer<QString> EditScans::uploadButtonText() const {
|
rpl::producer<QString> EditScans::uploadButtonText() const {
|
||||||
|
|
|
@ -56,7 +56,8 @@ public:
|
||||||
static void ChooseScan(
|
static void ChooseScan(
|
||||||
QPointer<QWidget> parent,
|
QPointer<QWidget> parent,
|
||||||
Fn<void(QByteArray&&)> doneCallback,
|
Fn<void(QByteArray&&)> doneCallback,
|
||||||
Fn<void(ReadScanError)> errorCallback);
|
Fn<void(ReadScanError)> errorCallback,
|
||||||
|
bool allowMany);
|
||||||
|
|
||||||
~EditScans();
|
~EditScans();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue