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