diff --git a/.github/actions/setup-dependencies/linux/action.yml b/.github/actions/setup-dependencies/linux/action.yml
index 94c04abe5..21ba30dc7 100644
--- a/.github/actions/setup-dependencies/linux/action.yml
+++ b/.github/actions/setup-dependencies/linux/action.yml
@@ -11,6 +11,7 @@ runs:
sudo apt-get -y install \
dpkg-dev \
ninja-build extra-cmake-modules scdoc \
+ libqrencode-dev \
appstream libxcb-cursor-dev
- name: Setup AppImage tooling
diff --git a/.github/actions/setup-dependencies/macos/action.yml b/.github/actions/setup-dependencies/macos/action.yml
index 6fc3ed3bf..cc3f2bc66 100644
--- a/.github/actions/setup-dependencies/macos/action.yml
+++ b/.github/actions/setup-dependencies/macos/action.yml
@@ -14,7 +14,7 @@ runs:
shell: bash
run: |
brew update
- brew install ninja extra-cmake-modules temurin@17
+ brew install ninja extra-cmake-modules temurin@17 qrencode
- name: Set JAVA_HOME
shell: bash
diff --git a/.github/actions/setup-dependencies/windows/action.yml b/.github/actions/setup-dependencies/windows/action.yml
index 97033747e..4f963c7c2 100644
--- a/.github/actions/setup-dependencies/windows/action.yml
+++ b/.github/actions/setup-dependencies/windows/action.yml
@@ -71,6 +71,7 @@ runs:
qt6-5compat:p
qt6-networkauth:p
cmark:p
+ qrencode:p
tomlplusplus:p
quazip-qt6:p
diff --git a/.gitmodules b/.gitmodules
index 0a0a50bee..7ad40becb 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,6 +19,3 @@
[submodule "flatpak/shared-modules"]
path = flatpak/shared-modules
url = https://github.com/flathub/shared-modules.git
-[submodule "libraries/qrcodegenerator"]
- path = libraries/qrcodegenerator
- url = https://github.com/nayuki/QR-Code-generator
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 929e1b394..fba65fb30 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -345,12 +345,24 @@ if(Launcher_QT_VERSION_MAJOR EQUAL 6)
set(QT_LIBEXECS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_LIBEXECS})
endif()
+find_package(PkgConfig)
+
+# Find libqrencode
+## NOTE(@getchoo): Never use pkg-config with MSVC since the vcpkg port makes our install bundle fail to find the dll
+if(PkgConfig_FOUND AND NOT MSVC)
+ pkg_check_modules(libqrencode REQUIRED IMPORTED_TARGET libqrencode)
+else()
+ find_path(LIBQRENCODE_INCLUDE_DIR qrencode.h REQUIRED)
+ find_library(LIBQRENCODE_LIBRARY_RELEASE qrencode REQUIRED)
+ find_library(LIBQRENCODE_LIBRARY_DEBUG qrencoded)
+ set(LIBQRENCODE_LIBRARIES optimized ${LIBQRENCODE_LIBRARY_RELEASE} debug ${LIBQRENCODE_LIBRARY_DEBUG})
+endif()
+
if(NOT Launcher_FORCE_BUNDLED_LIBS)
# Find toml++
find_package(tomlplusplus 3.2.0 QUIET)
# Fallback to pkg-config (if available) if CMake files aren't found
if(NOT tomlplusplus_FOUND)
- find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0)
endif()
@@ -359,9 +371,6 @@ if(NOT Launcher_FORCE_BUNDLED_LIBS)
# Find cmark
find_package(cmark QUIET)
-
- # Find qrcodegencpp-cmake
- find_package(qrcodegencpp QUIET)
endif()
include(ECMQtDeclareLoggingCategory)
@@ -523,18 +532,6 @@ if(NOT cmark_FOUND)
else()
message(STATUS "Using system cmark")
endif()
-if(NOT qrcodegencpp_FOUND)
- set(QRCODE_SOURCES
- libraries/qrcodegenerator/cpp/qrcodegen.cpp
- libraries/qrcodegenerator/cpp/qrcodegen.hpp
- )
- add_library(qrcodegenerator STATIC ${QRCODE_SOURCES})
- target_include_directories(qrcodegenerator PUBLIC "libraries/qrcodegenerator/cpp/" )
- generate_export_header(qrcodegenerator)
-else()
- add_library(qrcodegenerator ALIAS qrcodegencpp::qrcodegencpp)
- message(STATUS "Using system qrcodegencpp-cmake")
-endif()
add_subdirectory(libraries/gamemode)
add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API
add_subdirectory(libraries/qdcss) # css parser
diff --git a/COPYING.md b/COPYING.md
index e64bb8760..2d6f1860b 100644
--- a/COPYING.md
+++ b/COPYING.md
@@ -404,15 +404,6 @@
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see .
-## QR-Code-generator (`libraries/qrcodegenerator`)
-
- Copyright © 2024 Project Nayuki. (MIT License)
- https://www.nayuki.io/page/qr-code-generator-library
-
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
- - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- - The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
-
## vcpkg (`cmake/vcpkg-ports`)
MIT License
diff --git a/flake.lock b/flake.lock
index 162ad5baa..4073f67d0 100644
--- a/flake.lock
+++ b/flake.lock
@@ -32,27 +32,10 @@
"type": "github"
}
},
- "qrcodegenerator": {
- "flake": false,
- "locked": {
- "lastModified": 1737616857,
- "narHash": "sha256-6SugPt0lp1Gz7nV23FLmsmpfzgFItkSw7jpGftsDPWc=",
- "owner": "nayuki",
- "repo": "QR-Code-generator",
- "rev": "2c9044de6b049ca25cb3cd1649ed7e27aa055138",
- "type": "github"
- },
- "original": {
- "owner": "nayuki",
- "repo": "QR-Code-generator",
- "type": "github"
- }
- },
"root": {
"inputs": {
"libnbtplusplus": "libnbtplusplus",
- "nixpkgs": "nixpkgs",
- "qrcodegenerator": "qrcodegenerator"
+ "nixpkgs": "nixpkgs"
}
}
},
diff --git a/flake.nix b/flake.nix
index 751ef2eeb..594a82d91 100644
--- a/flake.nix
+++ b/flake.nix
@@ -15,11 +15,6 @@
url = "github:PrismLauncher/libnbtplusplus";
flake = false;
};
-
- qrcodegenerator = {
- url = "github:nayuki/QR-Code-generator";
- flake = false;
- };
};
outputs =
@@ -27,7 +22,6 @@
self,
nixpkgs,
libnbtplusplus,
- qrcodegenerator,
}:
let
@@ -175,7 +169,6 @@
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
inherit
libnbtplusplus
- qrcodegenerator
self
;
};
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 194694d7f..4e7a338f4 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -1321,8 +1321,15 @@ target_link_libraries(Launcher_logic
qdcss
BuildConfig
Qt${QT_VERSION_MAJOR}::Widgets
- qrcodegenerator
)
+
+if(TARGET PkgConfig::libqrencode)
+ target_link_libraries(Launcher_logic PkgConfig::libqrencode)
+else()
+ target_include_directories(Launcher_logic PRIVATE ${LIBQRENCODE_INCLUDE_DIR})
+ target_link_libraries(Launcher_logic ${LIBQRENCODE_LIBRARIES})
+endif()
+
if(TARGET PkgConfig::tomlplusplus)
target_link_libraries(Launcher_logic PkgConfig::tomlplusplus)
else()
diff --git a/launcher/ui/dialogs/MSALoginDialog.cpp b/launcher/ui/dialogs/MSALoginDialog.cpp
index 9e2c3df02..748be1d96 100644
--- a/launcher/ui/dialogs/MSALoginDialog.cpp
+++ b/launcher/ui/dialogs/MSALoginDialog.cpp
@@ -50,7 +50,7 @@
#include
#include
-#include "qrcodegen.hpp"
+#include "qrencode.h"
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
{
@@ -146,27 +146,32 @@ void MSALoginDialog::authorizeWithBrowser(const QUrl& url)
m_url = url;
}
-// https://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
-void paintQR(QPainter& painter, const QSize sz, const QString& data, QColor fg)
+void paintQR(QPainter& painter, const QSize canvasSize, const QString& data, QColor fg)
{
- // NOTE: At this point you will use the API to get the encoding and format you want, instead of my hardcoded stuff:
- qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(data.toUtf8().constData(), qrcodegen::QrCode::Ecc::LOW);
- const int s = qr.getSize() > 0 ? qr.getSize() : 1;
- const double w = sz.width();
- const double h = sz.height();
- const double aspect = w / h;
- const double size = ((aspect > 1.0) ? h : w);
- const double scale = size / (s + 2);
- // NOTE: For performance reasons my implementation only draws the foreground parts in supplied color.
- // It expects background to be prepared already (in white or whatever is preferred).
+ const auto* qr = QRcode_encodeString(data.toUtf8().constData(), 0, QRecLevel::QR_ECLEVEL_M, QRencodeMode::QR_MODE_8, 1);
+ if(!qr) {
+ qWarning() << "Unable to encode '" << data << "' as QR code";
+ return;
+ }
+
painter.setPen(Qt::NoPen);
painter.setBrush(fg);
- for (int y = 0; y < s; y++) {
- for (int x = 0; x < s; x++) {
- const int color = qr.getModule(x, y); // 0 for white, 1 for black
- if (0 != color) {
- const double rx1 = (x + 1) * scale, ry1 = (y + 1) * scale;
- QRectF r(rx1, ry1, scale, scale);
+
+ // Make sure the QR code fits in the canvas with some padding
+ const auto qrSize = qr->width;
+ const auto canvasWidth = canvasSize.width();
+ const auto canvasHeight = canvasSize.height();
+ const auto scale = 0.8 * std::min(canvasWidth / qrSize, canvasHeight / qrSize);
+
+ // Find an offset to center it in the canvas
+ const auto offsetX = (canvasWidth - qrSize * scale) / 2;
+ const auto offsetY = (canvasHeight - qrSize * scale) / 2;
+
+ for (int y = 0; y < qrSize; y++) {
+ for (int x = 0; x < qrSize; x++) {
+ auto shouldFillIn = qr->data[y * qrSize + x] & 1;
+ if (shouldFillIn) {
+ QRectF r(offsetX + x * scale, offsetY + y * scale, scale, scale);
painter.drawRects(&r, 1);
}
}
diff --git a/libraries/qrcodegenerator b/libraries/qrcodegenerator
deleted file mode 160000
index 2c9044de6..000000000
--- a/libraries/qrcodegenerator
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 2c9044de6b049ca25cb3cd1649ed7e27aa055138
diff --git a/nix/unwrapped.nix b/nix/unwrapped.nix
index d9144410f..56bfebc3c 100644
--- a/nix/unwrapped.nix
+++ b/nix/unwrapped.nix
@@ -9,8 +9,8 @@
jdk17,
kdePackages,
libnbtplusplus,
- qrcodegenerator,
ninja,
+ qrencode,
self,
stripJavaArchivesHook,
tomlplusplus,
@@ -63,9 +63,6 @@ stdenv.mkDerivation {
postUnpack = ''
rm -rf source/libraries/libnbtplusplus
ln -s ${libnbtplusplus} source/libraries/libnbtplusplus
-
- rm -rf source/libraries/qrcodegenerator
- ln -s ${qrcodegenerator} source/libraries/qrcodegenerator
'';
nativeBuildInputs = [
@@ -82,6 +79,7 @@ stdenv.mkDerivation {
kdePackages.qtbase
kdePackages.qtnetworkauth
kdePackages.quazip
+ qrencode
tomlplusplus
zlib
]
diff --git a/vcpkg.json b/vcpkg.json
index 4abf8d1b7..c4ab81011 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -3,6 +3,7 @@
"bzip2",
"cmark",
{ "name": "ecm", "host": true },
+ "libqrencode",
{ "name": "pkgconf", "host": true },
"tomlplusplus",
"zlib"