kaidan/0001-Port-deprecations-and-little-refactoring-of-the-QrCo.patch

96 lines
3.5 KiB
Diff

From ed31a672465bc19b43e6c204ee8b5172fc96eacf Mon Sep 17 00:00:00 2001
From: Linus Jahn <lnj@kaidan.im>
Date: Fri, 31 Jul 2020 14:59:28 +0200
Subject: [PATCH] Port deprecations and little refactoring of the QrCodeDecoder
---
src/QrCodeDecoder.cpp | 42 +++++++++++++------------------------
src/RegistrationManager.cpp | 8 +++++--
2 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/src/QrCodeDecoder.cpp b/src/QrCodeDecoder.cpp
index 38df5f9..b2b4437 100644
--- a/src/QrCodeDecoder.cpp
+++ b/src/QrCodeDecoder.cpp
@@ -41,6 +41,10 @@
#include <ZXing/MultiFormatReader.h>
#include <ZXing/Result.h>
#include <ZXing/TextUtfEncoding.h>
+#include <ZXing/ZXVersion.h>
+
+#define ZXING_VERSION \
+ QT_VERSION_CHECK(ZXING_VERSION_MAJOR, ZXING_VERSION_MINOR, ZXING_VERSION_PATCH)
using namespace ZXing;
@@ -51,36 +55,20 @@ QrCodeDecoder::QrCodeDecoder(QObject *parent)
void QrCodeDecoder::decodeImage(const QImage &image)
{
- // options for decoding
- DecodeHints decodeHints;
-
- // Advise the decoder to also decode rotated QR codes.
- decodeHints.setTryRotate(true);
-
- // Advise the decoder to only decode QR codes.
- std::vector<BarcodeFormat> allowedFormats;
- allowedFormats.emplace_back(BarcodeFormat::QR_CODE);
- decodeHints.setPossibleFormats(allowedFormats);
-
- MultiFormatReader reader(decodeHints);
-
- // Create an image source to be decoded later.
- GenericLuminanceSource source(
- image.width(),
- image.height(),
- image.bits(),
- image.width(),
- 1,
- 0,
- 1,
- 2
- );
+ // Advise the decoder to check for QR codes and to try decoding rotated versions of the image.
+#if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 0)
+ const auto decodeHints = DecodeHints().setTryRotate(true).setFormats(BarcodeFormat::QR_CODE);
+#else
+ const auto decodeHints =
+ DecodeHints().setTryRotate(true).setPossibleFormats({BarcodeFormat::QR_CODE});
+#endif
- // Create an image source specific for decoding black data on white background.
- HybridBinarizer binImage(std::shared_ptr<LuminanceSource>(&source, [](void*) {}));
+ // Create a binarized image by the luminance of the image.
+ HybridBinarizer binImage(std::make_shared<GenericLuminanceSource>(GenericLuminanceSource(
+ image.width(), image.height(), image.bits(), image.width(), 1, 0, 1, 2)));
// Decode the specific image source.
- auto result = reader.read(binImage);
+ auto result = MultiFormatReader(decodeHints).read(binImage);
// If a QR code could be found and decoded, emit a signal with the decoded string.
// Otherwise, emit a signal for failed decoding.
diff --git a/src/RegistrationManager.cpp b/src/RegistrationManager.cpp
index 3014e0f..f095343 100644
--- a/src/RegistrationManager.cpp
+++ b/src/RegistrationManager.cpp
@@ -258,8 +258,12 @@ void RegistrationManager::copyUserDefinedValuesToNewForm(const QXmppDataForm &ol
// Copy values from the last form.
const QList<QXmppDataForm::Field> oldFields = oldForm.fields();
for (const auto &field : oldFields) {
- // Only copy fields which are required, visible to the user and do not have a media element (e.g. CAPTCHA).
- if (field.isRequired() && field.type() != QXmppDataForm::Field::HiddenField && field.media().isNull()) {
+ // Only copy fields which:
+ // * are required,
+ // * are visible to the user
+ // * do not have a media element (e.g. CAPTCHA)
+ if (field.isRequired() && field.type() != QXmppDataForm::Field::HiddenField &&
+ field.mediaSources().isEmpty()) {
for (auto &fieldFromNewForm : newForm.fields()) {
if (fieldFromNewForm.key() == field.key()) {
fieldFromNewForm.setValue(field.value());
--
2.28.0