mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-03 11:27:33 -04:00
feat(ui/MSALoginDialog): use libqrencode for qr codes
`qrcodegen` isn't available in most repositories, package discovery scripts for it are maintained in a different repository, and they are bugged for Windows at least. This basically forces us into vendoring it, which isn't cool; libqrencode seems like viable alternative used by many more apps Signed-off-by: Seth Flynn <getchoo@tuta.io>
This commit is contained in:
parent
9565affa64
commit
5b1debab60
@ -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
|
||||
|
@ -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
|
||||
|
@ -71,6 +71,7 @@ runs:
|
||||
qt6-5compat:p
|
||||
qt6-networkauth:p
|
||||
cmark:p
|
||||
qrencode:p
|
||||
tomlplusplus:p
|
||||
quazip-qt6:p
|
||||
|
||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
@ -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
|
||||
|
@ -404,15 +404,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
## 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
|
||||
|
19
flake.lock
generated
19
flake.lock
generated
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -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
|
||||
;
|
||||
};
|
||||
|
@ -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()
|
||||
|
@ -50,7 +50,7 @@
|
||||
#include <QUrl>
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
Subproject commit 2c9044de6b049ca25cb3cd1649ed7e27aa055138
|
@ -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
|
||||
]
|
||||
|
@ -3,6 +3,7 @@
|
||||
"bzip2",
|
||||
"cmark",
|
||||
{ "name": "ecm", "host": true },
|
||||
"libqrencode",
|
||||
{ "name": "pkgconf", "host": true },
|
||||
"tomlplusplus",
|
||||
"zlib"
|
||||
|
Loading…
x
Reference in New Issue
Block a user