[neon/forks/kaidan/Neon/release] debian/patches: add code from master to use newer xzing library

Jonathan Esk-Riddell null at kde.org
Wed Feb 22 12:33:50 GMT 2023


Git commit bd481a42d5cdc1abce537fd883d8776ee568bd4a by Jonathan Esk-Riddell.
Committed on 22/02/2023 at 12:33.
Pushed by jriddell into branch 'Neon/release'.

add code from master to use newer xzing library

A  +142  -0    debian/patches/qrcode.diff
A  +1    -0    debian/patches/series

https://invent.kde.org/neon/forks/kaidan/commit/bd481a42d5cdc1abce537fd883d8776ee568bd4a

diff --git a/debian/patches/qrcode.diff b/debian/patches/qrcode.diff
new file mode 100644
index 0000000..f56590a
--- /dev/null
+++ b/debian/patches/qrcode.diff
@@ -0,0 +1,142 @@
+--- kaiden/src/QrCodeDecoder.cpp	2021-05-28 22:55:43.000000000 +0100
++++ kaidan/src/QrCodeDecoder.cpp	2023-02-15 13:16:35.918315698 +0000
+@@ -1,7 +1,7 @@
+ /*
+  *  Kaidan - A user-friendly XMPP client for every device!
+  *
+- *  Copyright (C) 2016-2021 Kaidan developers and contributors
++ *  Copyright (C) 2016-2022 Kaidan developers and contributors
+  *  (see the LICENSE file for a full list of copyright authors)
+  *
+  *  Kaidan is free software: you can redistribute it and/or modify
+@@ -60,7 +60,11 @@
+ {
+ 	// 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)
++# if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 1)
++	const auto decodeHints = DecodeHints().setFormats(BarcodeFormat::QRCode);
++# else
+ 	const auto decodeHints = DecodeHints().setFormats(BarcodeFormat::QR_CODE);
++# endif
+ 	const auto result = ReadBarcode({image.bits(), image.width(), image.height(), ZXing::ImageFormat::Lum, image.bytesPerLine()}, decodeHints);
+ #else
+ 	const auto decodeHints =
+@@ -74,10 +78,23 @@
+ 	const auto result = MultiFormatReader(decodeHints).read(binImage);
+ #endif
+ 
++	// FIXME: `this` is not supposed to become nullptr in well-defined C++ code,
++	//        so if we are unlucky, the compiler may optimize the entire check away.
++	//        Additionally, this could be racy if the object is deleted on the other thread
++	//        in between this check and the emit.
++	const auto *self = this;
++	if (!self) {
++		return;
++	}
++
+ 	// If a QR code could be found and decoded, emit a signal with the decoded string.
+ 	// Otherwise, emit a signal for failed decoding.
+ 	if (result.isValid())
++#if ZXING_VERSION < QT_VERSION_CHECK(2, 0, 0)
+ 		emit decodingSucceeded(QString::fromStdString(TextUtfEncoding::ToUtf8(result.text())));
++#else
++		emit decodingSucceeded(QString::fromStdString(result.text()));
++#endif
+ 	else
+ 		emit decodingFailed();
+ }
+--- kaidan/src/QrCodeGenerator.cpp	2021-05-28 22:55:43.000000000 +0100
++++ kaidan/src/QrCodeGenerator.cpp	2022-10-14 15:30:40.902041831 +0100
+@@ -1,7 +1,7 @@
+ /*
+  *  Kaidan - A user-friendly XMPP client for every device!
+  *
+- *  Copyright (C) 2016-2021 Kaidan developers and contributors
++ *  Copyright (C) 2016-2022 Kaidan developers and contributors
+  *  (see the LICENSE file for a full list of copyright authors)
+  *
+  *  Kaidan is free software: you can redistribute it and/or modify
+@@ -33,11 +33,17 @@
+ #include <QImage>
+ #include <QRgb>
+ 
++#include <ZXing/ZXVersion.h>
++#define ZXING_VERSION \
++	QT_VERSION_CHECK(ZXING_VERSION_MAJOR, ZXING_VERSION_MINOR, ZXING_VERSION_PATCH)
++
+ #include <ZXing/BarcodeFormat.h>
+ #include <ZXing/MultiFormatWriter.h>
+ 
+ #include "AccountManager.h"
++#include "MessageModel.h"
+ #include "Kaidan.h"
++#include "Settings.h"
+ #include "qxmpp-exts/QXmppUri.h"
+ 
+ #include <stdexcept>
+@@ -57,16 +63,50 @@
+ 	uri.setJid(AccountManager::instance()->jid());
+ 	uri.setAction(QXmppUri::Login);
+ 
+-	if (Kaidan::instance()->passwordVisibility() != Kaidan::PasswordInvisible)
++	if (Kaidan::instance()->settings()->authPasswordVisibility() != Kaidan::PasswordInvisible)
+ 		uri.setPassword(AccountManager::instance()->password());
+ 
+ 	return generateQrCode(edgePixelCount, uri.toString());
+ }
+ 
+-QImage QrCodeGenerator::generateBareJidQrCode(int edgePixelCount, const QString &bareJid)
++QImage QrCodeGenerator::generateOwnTrustMessageQrCode(int edgePixelCount)
+ {
++	return generateTrustMessageQrCode(edgePixelCount, AccountManager::instance()->jid());
++}
++
++QImage QrCodeGenerator::generateContactTrustMessageQrCode(int edgePixelCount, const QString &contactJid)
++{
++	return generateTrustMessageQrCode(edgePixelCount, contactJid);
++}
++
++QImage QrCodeGenerator::generateTrustMessageQrCode(int edgePixelCount, const QString &jid)
++{
++	const auto keys = MessageModel::instance()->keys().value(jid);
++	QList<QString> authenticatedKeys;
++	QList<QString> distrustedKeys;
++
++	for (auto itr = keys.constBegin(); itr != keys.constEnd(); ++itr) {
++		const auto key = itr.key().toHex();
++		const auto trustLevel = itr.value();
++
++		if (trustLevel == QXmpp::TrustLevel::Authenticated) {
++			authenticatedKeys.append(key);
++		} else if (trustLevel == QXmpp::TrustLevel::ManuallyDistrusted) {
++			distrustedKeys.append(key);
++		}
++	}
++
+ 	QXmppUri uri;
+-	uri.setJid(bareJid);
++	uri.setJid(jid);
++
++	// Create a Trust Message URI only if there are keys for it.
++	if (!authenticatedKeys.isEmpty() || !distrustedKeys.isEmpty()) {
++		uri.setAction(QXmppUri::TrustMessage);
++		// TODO: Find solution to pass enum to "uri.setEncryption()" instead of string (see QXmppGlobal::encryptionToString())
++		uri.setEncryption(QStringLiteral("urn:xmpp:omemo:2"));
++		uri.setTrustedKeysIds(authenticatedKeys);
++		uri.setDistrustedKeysIds(distrustedKeys);
++	}
+ 
+ 	return generateQrCode(edgePixelCount, uri.toString());
+ }
+@@ -74,7 +114,11 @@
+ QImage QrCodeGenerator::generateQrCode(int edgePixelCount, const QString &text)
+ {
+ 	try {
++#if ZXING_VERSION >= QT_VERSION_CHECK(1, 1, 1)
++		ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::QRCode);
++#else
+ 		ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::QR_CODE);
++#endif
+ 		const ZXing::BitMatrix &bitMatrix = writer.encode(text.toStdWString(), edgePixelCount, edgePixelCount);
+ 		return toImage(bitMatrix);
+ 	} catch (const std::invalid_argument &e) {
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..b76d443
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+qrcode.diff


More information about the Neon-commits mailing list