Christophe Giboudeaux 2020-08-16 18:31:50 +00:00 committed by Git OBS Bridge
parent c3389b50fb
commit 8b9a3e297a
3 changed files with 100 additions and 1 deletions

View File

@ -0,0 +1,95 @@
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

View File

@ -27,6 +27,8 @@ Sun Aug 16 18:02:07 UTC 2020 - Christophe Giboudeaux <christophe@krop.fr>
* Improve build scripts for better cross-platform support
* Refactor code for better performance and stability
* Add documentation to achieve easier maintenance
- Add upstream patch:
* 0001-Port-deprecations-and-little-refactoring-of-the-QrCo.patch
-------------------------------------------------------------------
Wed Jul 17 19:19:46 UTC 2019 - Wolfgang Bauer <wbauer@tmo.at>

View File

@ -24,6 +24,8 @@ License: GPL-3.0-or-later AND SUSE-GPL-3.0+-with-openssl-exception AND MI
Group: Productivity/Networking/Instant Messenger
URL: https://www.kaidan.im/
Source: https://download.kde.org/stable/%{name}/%{version}/%{name}-%{version}.tar.xz
# PATCH-FIX-UPSTREAM
Patch0: 0001-Port-deprecations-and-little-refactoring-of-the-QrCo.patch
BuildRequires: cmake >= 3.3
BuildRequires: extra-cmake-modules >= 5.40.0
BuildRequires: libqxmpp-devel >= 0.8.3
@ -52,7 +54,7 @@ Kirigami and QtQuick. The back-end of Kaidan is entirely written in C++
using the qxmpp XMPP client library and Qt 5.
%prep
%setup -q
%autosetup -p1
%build
%cmake_kf5 -d build '-DI18N:BOOL=ON'