mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-08-04 03:47:57 -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 \
|
sudo apt-get -y install \
|
||||||
dpkg-dev \
|
dpkg-dev \
|
||||||
ninja-build extra-cmake-modules scdoc \
|
ninja-build extra-cmake-modules scdoc \
|
||||||
|
libqrencode-dev \
|
||||||
appstream libxcb-cursor-dev
|
appstream libxcb-cursor-dev
|
||||||
|
|
||||||
- name: Setup AppImage tooling
|
- name: Setup AppImage tooling
|
||||||
|
@ -14,7 +14,7 @@ runs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
brew update
|
brew update
|
||||||
brew install ninja extra-cmake-modules temurin@17
|
brew install ninja extra-cmake-modules temurin@17 qrencode
|
||||||
|
|
||||||
- name: Set JAVA_HOME
|
- name: Set JAVA_HOME
|
||||||
shell: bash
|
shell: bash
|
||||||
|
@ -71,6 +71,7 @@ runs:
|
|||||||
qt6-5compat:p
|
qt6-5compat:p
|
||||||
qt6-networkauth:p
|
qt6-networkauth:p
|
||||||
cmark:p
|
cmark:p
|
||||||
|
qrencode:p
|
||||||
tomlplusplus:p
|
tomlplusplus:p
|
||||||
quazip-qt6:p
|
quazip-qt6:p
|
||||||
|
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -19,6 +19,3 @@
|
|||||||
[submodule "flatpak/shared-modules"]
|
[submodule "flatpak/shared-modules"]
|
||||||
path = flatpak/shared-modules
|
path = flatpak/shared-modules
|
||||||
url = https://github.com/flathub/shared-modules.git
|
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})
|
set(QT_LIBEXECS_DIR ${QT${QT_VERSION_MAJOR}_INSTALL_PREFIX}/${QT${QT_VERSION_MAJOR}_INSTALL_LIBEXECS})
|
||||||
endif()
|
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)
|
if(NOT Launcher_FORCE_BUNDLED_LIBS)
|
||||||
# Find toml++
|
# Find toml++
|
||||||
find_package(tomlplusplus 3.2.0 QUIET)
|
find_package(tomlplusplus 3.2.0 QUIET)
|
||||||
# Fallback to pkg-config (if available) if CMake files aren't found
|
# Fallback to pkg-config (if available) if CMake files aren't found
|
||||||
if(NOT tomlplusplus_FOUND)
|
if(NOT tomlplusplus_FOUND)
|
||||||
find_package(PkgConfig)
|
|
||||||
if(PkgConfig_FOUND)
|
if(PkgConfig_FOUND)
|
||||||
pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0)
|
pkg_check_modules(tomlplusplus IMPORTED_TARGET tomlplusplus>=3.2.0)
|
||||||
endif()
|
endif()
|
||||||
@ -359,9 +371,6 @@ if(NOT Launcher_FORCE_BUNDLED_LIBS)
|
|||||||
|
|
||||||
# Find cmark
|
# Find cmark
|
||||||
find_package(cmark QUIET)
|
find_package(cmark QUIET)
|
||||||
|
|
||||||
# Find qrcodegencpp-cmake
|
|
||||||
find_package(qrcodegencpp QUIET)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(ECMQtDeclareLoggingCategory)
|
include(ECMQtDeclareLoggingCategory)
|
||||||
@ -523,18 +532,6 @@ if(NOT cmark_FOUND)
|
|||||||
else()
|
else()
|
||||||
message(STATUS "Using system cmark")
|
message(STATUS "Using system cmark")
|
||||||
endif()
|
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/gamemode)
|
||||||
add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API
|
add_subdirectory(libraries/murmur2) # Hash for usage with the CurseForge API
|
||||||
add_subdirectory(libraries/qdcss) # css parser
|
add_subdirectory(libraries/qdcss) # css parser
|
||||||
|
@ -404,15 +404,6 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public
|
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/>.
|
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`)
|
## vcpkg (`cmake/vcpkg-ports`)
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
19
flake.lock
generated
19
flake.lock
generated
@ -32,27 +32,10 @@
|
|||||||
"type": "github"
|
"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": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"libnbtplusplus": "libnbtplusplus",
|
"libnbtplusplus": "libnbtplusplus",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs"
|
||||||
"qrcodegenerator": "qrcodegenerator"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -15,11 +15,6 @@
|
|||||||
url = "github:PrismLauncher/libnbtplusplus";
|
url = "github:PrismLauncher/libnbtplusplus";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
qrcodegenerator = {
|
|
||||||
url = "github:nayuki/QR-Code-generator";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
@ -27,7 +22,6 @@
|
|||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
libnbtplusplus,
|
libnbtplusplus,
|
||||||
qrcodegenerator,
|
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -175,7 +169,6 @@
|
|||||||
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
|
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
|
||||||
inherit
|
inherit
|
||||||
libnbtplusplus
|
libnbtplusplus
|
||||||
qrcodegenerator
|
|
||||||
self
|
self
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
@ -1321,8 +1321,15 @@ target_link_libraries(Launcher_logic
|
|||||||
qdcss
|
qdcss
|
||||||
BuildConfig
|
BuildConfig
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
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)
|
if(TARGET PkgConfig::tomlplusplus)
|
||||||
target_link_libraries(Launcher_logic PkgConfig::tomlplusplus)
|
target_link_libraries(Launcher_logic PkgConfig::tomlplusplus)
|
||||||
else()
|
else()
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
#include "qrcodegen.hpp"
|
#include "qrencode.h"
|
||||||
|
|
||||||
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
||||||
{
|
{
|
||||||
@ -146,27 +146,32 @@ void MSALoginDialog::authorizeWithBrowser(const QUrl& url)
|
|||||||
m_url = 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 canvasSize, const QString& data, QColor fg)
|
||||||
void paintQR(QPainter& painter, const QSize sz, 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:
|
const auto* qr = QRcode_encodeString(data.toUtf8().constData(), 0, QRecLevel::QR_ECLEVEL_M, QRencodeMode::QR_MODE_8, 1);
|
||||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(data.toUtf8().constData(), qrcodegen::QrCode::Ecc::LOW);
|
if(!qr) {
|
||||||
const int s = qr.getSize() > 0 ? qr.getSize() : 1;
|
qWarning() << "Unable to encode '" << data << "' as QR code";
|
||||||
const double w = sz.width();
|
return;
|
||||||
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).
|
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
painter.setBrush(fg);
|
painter.setBrush(fg);
|
||||||
for (int y = 0; y < s; y++) {
|
|
||||||
for (int x = 0; x < s; x++) {
|
// Make sure the QR code fits in the canvas with some padding
|
||||||
const int color = qr.getModule(x, y); // 0 for white, 1 for black
|
const auto qrSize = qr->width;
|
||||||
if (0 != color) {
|
const auto canvasWidth = canvasSize.width();
|
||||||
const double rx1 = (x + 1) * scale, ry1 = (y + 1) * scale;
|
const auto canvasHeight = canvasSize.height();
|
||||||
QRectF r(rx1, ry1, scale, scale);
|
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);
|
painter.drawRects(&r, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Subproject commit 2c9044de6b049ca25cb3cd1649ed7e27aa055138
|
|
@ -9,8 +9,8 @@
|
|||||||
jdk17,
|
jdk17,
|
||||||
kdePackages,
|
kdePackages,
|
||||||
libnbtplusplus,
|
libnbtplusplus,
|
||||||
qrcodegenerator,
|
|
||||||
ninja,
|
ninja,
|
||||||
|
qrencode,
|
||||||
self,
|
self,
|
||||||
stripJavaArchivesHook,
|
stripJavaArchivesHook,
|
||||||
tomlplusplus,
|
tomlplusplus,
|
||||||
@ -63,9 +63,6 @@ stdenv.mkDerivation {
|
|||||||
postUnpack = ''
|
postUnpack = ''
|
||||||
rm -rf source/libraries/libnbtplusplus
|
rm -rf source/libraries/libnbtplusplus
|
||||||
ln -s ${libnbtplusplus} source/libraries/libnbtplusplus
|
ln -s ${libnbtplusplus} source/libraries/libnbtplusplus
|
||||||
|
|
||||||
rm -rf source/libraries/qrcodegenerator
|
|
||||||
ln -s ${qrcodegenerator} source/libraries/qrcodegenerator
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
@ -82,6 +79,7 @@ stdenv.mkDerivation {
|
|||||||
kdePackages.qtbase
|
kdePackages.qtbase
|
||||||
kdePackages.qtnetworkauth
|
kdePackages.qtnetworkauth
|
||||||
kdePackages.quazip
|
kdePackages.quazip
|
||||||
|
qrencode
|
||||||
tomlplusplus
|
tomlplusplus
|
||||||
zlib
|
zlib
|
||||||
]
|
]
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"bzip2",
|
"bzip2",
|
||||||
"cmark",
|
"cmark",
|
||||||
{ "name": "ecm", "host": true },
|
{ "name": "ecm", "host": true },
|
||||||
|
"libqrencode",
|
||||||
{ "name": "pkgconf", "host": true },
|
{ "name": "pkgconf", "host": true },
|
||||||
"tomlplusplus",
|
"tomlplusplus",
|
||||||
"zlib"
|
"zlib"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user