mirror of
https://github.com/savoirfairelinux/jami-client-qt.git
synced 2025-12-16 23:14:57 +08:00
qrcode: use ZXing for code generation
Change-Id: Ifd451a709e95a5c950d0b4602254de17a579774a
This commit is contained in:
committed by
Adrien Béraud
parent
2da0f18213
commit
609496840e
8
.gitmodules
vendored
8
.gitmodules
vendored
@@ -1,11 +1,3 @@
|
||||
[submodule "3rdparty/qrencode-win32"]
|
||||
path = 3rdparty/qrencode-win32
|
||||
url = https://github.com/blizzard4591/qrencode-win32.git
|
||||
ignore = dirty
|
||||
[submodule "3rdparty/libqrencode"]
|
||||
url = https://github.com/fukuchi/libqrencode.git
|
||||
ignore = dirty
|
||||
path = 3rdparty/libqrencode
|
||||
[submodule "3rdparty/SortFilterProxyModel"]
|
||||
path = 3rdparty/SortFilterProxyModel
|
||||
url = https://github.com/atraczyk/SortFilterProxyModel.git
|
||||
|
||||
1
3rdparty/libqrencode
vendored
1
3rdparty/libqrencode
vendored
Submodule 3rdparty/libqrencode deleted from 715e29fd4c
1
3rdparty/qrencode-win32
vendored
1
3rdparty/qrencode-win32
vendored
Submodule 3rdparty/qrencode-win32 deleted from 5ccf9bd445
@@ -533,12 +533,6 @@ if(MSVC)
|
||||
"/LTCG"
|
||||
"/NODEFAULTLIB:LIBCMT")
|
||||
|
||||
# client deps
|
||||
set(QRENCODE_DIR ${PROJECT_SOURCE_DIR}/3rdparty/qrencode-win32/qrencode-win32)
|
||||
file(GLOB_RECURSE QRENCODE_LIB ${QRENCODE_DIR}/qrcodelib.lib)
|
||||
file(GLOB_RECURSE QRENCODE_INCLUDE ${QRENCODE_DIR}/qrencode.h)
|
||||
get_filename_component(QRENCODE_INCLUDE_DIR ${QRENCODE_INCLUDE} DIRECTORY)
|
||||
|
||||
# daemon
|
||||
set(JAMID_SRC_PATH ${DAEMON_DIR}/contrib/msvc/include)
|
||||
set(GNUTLS_LIB ${DAEMON_DIR}/contrib/msvc/lib/x64/libgnutls.lib)
|
||||
@@ -546,7 +540,7 @@ if(MSVC)
|
||||
include_directories(
|
||||
${JAMID_SRC_PATH}
|
||||
${LIBCLIENT_SRC_DIR}
|
||||
${QRENCODE_INCLUDE_DIR})
|
||||
)
|
||||
elseif (NOT APPLE)
|
||||
list(APPEND COMMON_SOURCES
|
||||
${APP_SRC_DIR}/xrectsel.c
|
||||
@@ -598,7 +592,6 @@ elseif (NOT APPLE)
|
||||
set(JAMI_DATA_PREFIX "${CMAKE_INSTALL_PREFIX}/share")
|
||||
|
||||
find_library(${LIBCLIENT_NAME} ${LIBCLIENT_NAME} NO_DEFAULT_PATH)
|
||||
find_library(qrencode qrencode)
|
||||
find_library(X11 X11)
|
||||
else() # APPLE
|
||||
list(APPEND COMMON_SOURCES
|
||||
@@ -618,8 +611,6 @@ else() # APPLE
|
||||
${myApp_ICON}
|
||||
PROPERTIES
|
||||
MACOSX_PACKAGE_LOCATION Resources)
|
||||
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rdparty/libqrencode/include)
|
||||
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/3rdparty/libqrencode/lib)
|
||||
if(ENABLE_SPARKLE)
|
||||
message("Sparkle auto-update enabled")
|
||||
set(sparkle_dir "${PACKAGING_DIR}/update/sparkle")
|
||||
@@ -766,7 +757,6 @@ if(MSVC)
|
||||
${GNUTLS_LIB}
|
||||
${LIBCLIENT_NAME}
|
||||
${QT_LIBS}
|
||||
${QRENCODE_LIB}
|
||||
${WINDOWS_SYS_LIBS})
|
||||
|
||||
# specify output executable files
|
||||
@@ -801,7 +791,6 @@ elseif (NOT APPLE)
|
||||
list(APPEND CLIENT_LIBS
|
||||
${QT_LIBS}
|
||||
${LIBCLIENT_NAME}
|
||||
${qrencode}
|
||||
${X11}
|
||||
${LIBNM_LIBRARIES}
|
||||
${LIBNOTIFY_LIBRARIES}
|
||||
@@ -938,7 +927,7 @@ elseif (NOT APPLE)
|
||||
else()
|
||||
set(resources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources/images/jami.icns)
|
||||
set(libs ${QT_LIBS} ${SYSTEM_CONFIGURATUION} qrencode ${LIBCLIENT_NAME})
|
||||
set(libs ${QT_LIBS} ${SYSTEM_CONFIGURATUION} ${LIBCLIENT_NAME})
|
||||
if(ENABLE_SPARKLE)
|
||||
set(resources ${resources} ${SPARKLE_FRAMEWORK})
|
||||
set(libs ${libs} ${SPARKLE_FRAMEWORK})
|
||||
|
||||
@@ -241,11 +241,6 @@ fi
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
client_cmake_flags+=(-DCMAKE_OSX_ARCHITECTURES="${CMAKE_OSX_ARCHITECTURES}")
|
||||
# build qrencode
|
||||
(
|
||||
cd ${TOP}
|
||||
./extras/scripts/build_qrencode.sh -a "$arch"
|
||||
)
|
||||
fi
|
||||
|
||||
if [ "${global}" = "true" ]; then
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
#include <api/contact.h>
|
||||
|
||||
#include <qrencode.h>
|
||||
#include <BitMatrix.h>
|
||||
#include <MultiFormatWriter.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QBitmap>
|
||||
@@ -832,37 +833,31 @@ Utils::pixmapFromSvg(const QString& svg_resource, const QSize& size)
|
||||
QImage
|
||||
Utils::getQRCodeImage(QString data, int margin)
|
||||
{
|
||||
auto qrcode = QRcode_encodeString(data.toStdString().c_str(),
|
||||
0, // Let the version be decided by libqrencode
|
||||
QR_ECLEVEL_L, // Lowest level of error correction
|
||||
QR_MODE_8, // 8-bit data mode
|
||||
1);
|
||||
if (not qrcode) {
|
||||
qWarning() << "Failed to generate QR code";
|
||||
try {
|
||||
ZXing::MultiFormatWriter writer(ZXing::BarcodeFormat::QRCode);
|
||||
writer.setEccLevel(0);
|
||||
writer.setMargin(margin);
|
||||
auto bitMatrix = writer.encode(data.toStdString(), 0, 0);
|
||||
int qrwidth = bitMatrix.width();
|
||||
int qrheight = bitMatrix.height();
|
||||
|
||||
// Create QImage with the QR code data
|
||||
QImage result(qrwidth, qrheight, QImage::Format_Mono);
|
||||
result.fill(1); // Fill with white
|
||||
|
||||
// Copy the bitmap data to QImage
|
||||
for (int y = 0; y < qrheight; y++) {
|
||||
for (int x = 0; x < qrwidth; x++) {
|
||||
if (bitMatrix.get(x, y)) {
|
||||
result.setPixel(x, y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (const std::exception& e) {
|
||||
qWarning() << "Failed to generate QR code:" << e.what();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
int qrwidth = qrcode->width + margin * 2;
|
||||
QImage result(QSize(qrwidth, qrwidth), QImage::Format_Mono);
|
||||
QPainter painter;
|
||||
painter.begin(&result);
|
||||
painter.setClipRect(QRect(0, 0, qrwidth, qrwidth));
|
||||
painter.setPen(QPen(Qt::black, 0.1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
|
||||
painter.setBrush(Qt::black);
|
||||
painter.fillRect(QRect(0, 0, qrwidth, qrwidth), Qt::white);
|
||||
unsigned char* p;
|
||||
p = qrcode->data;
|
||||
for (int y = 0; y < qrcode->width; y++) {
|
||||
unsigned char* row = (p + (y * qrcode->width));
|
||||
for (int x = 0; x < qrcode->width; x++) {
|
||||
if (*(row + x) & 0x1) {
|
||||
painter.drawRect(margin + x, margin + y, 1, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
painter.end();
|
||||
QRcode_free(qrcode);
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray
|
||||
|
||||
Reference in New Issue
Block a user