mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-07 10:39:16 +02:00
feat: move qr code glue in MSALoginDialog (#3676)
This commit is contained in:
commit
0a89f5cfaa
4
.gitmodules
vendored
4
.gitmodules
vendored
@ -19,6 +19,6 @@
|
|||||||
[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/qt-qrcodegenerator/QR-Code-generator"]
|
[submodule "libraries/qrcodegenerator"]
|
||||||
path = libraries/qt-qrcodegenerator/QR-Code-generator
|
path = libraries/qrcodegenerator
|
||||||
url = https://github.com/nayuki/QR-Code-generator
|
url = https://github.com/nayuki/QR-Code-generator
|
||||||
|
@ -475,7 +475,6 @@ add_subdirectory(libraries/libnbtplusplus)
|
|||||||
add_subdirectory(libraries/systeminfo) # system information library
|
add_subdirectory(libraries/systeminfo) # system information library
|
||||||
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
||||||
add_subdirectory(libraries/javacheck) # java compatibility checker
|
add_subdirectory(libraries/javacheck) # java compatibility checker
|
||||||
add_subdirectory(libraries/qt-qrcodegenerator) # qr code generator
|
|
||||||
if(FORCE_BUNDLED_ZLIB)
|
if(FORCE_BUNDLED_ZLIB)
|
||||||
message(STATUS "Using bundled zlib")
|
message(STATUS "Using bundled zlib")
|
||||||
|
|
||||||
@ -533,6 +532,15 @@ 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
|
||||||
|
|
||||||
|
# qr code generator
|
||||||
|
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)
|
||||||
|
|
||||||
############################### Built Artifacts ###############################
|
############################### Built Artifacts ###############################
|
||||||
|
|
||||||
add_subdirectory(buildconfig)
|
add_subdirectory(buildconfig)
|
||||||
|
@ -404,7 +404,7 @@
|
|||||||
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/>.
|
||||||
|
|
||||||
## qt-qrcodegenerator (`libraries/qt-qrcodegenerator`)
|
## QR-Code-generator (`libraries/qrcodegenerator`)
|
||||||
|
|
||||||
Copyright © 2024 Project Nayuki. (MIT License)
|
Copyright © 2024 Project Nayuki. (MIT License)
|
||||||
https://www.nayuki.io/page/qr-code-generator-library
|
https://www.nayuki.io/page/qr-code-generator-library
|
||||||
|
4
flake.lock
generated
4
flake.lock
generated
@ -32,7 +32,7 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"qt-qrcodegenerator": {
|
"qrcodegenerator": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1737616857,
|
"lastModified": 1737616857,
|
||||||
@ -52,7 +52,7 @@
|
|||||||
"inputs": {
|
"inputs": {
|
||||||
"libnbtplusplus": "libnbtplusplus",
|
"libnbtplusplus": "libnbtplusplus",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"qt-qrcodegenerator": "qt-qrcodegenerator"
|
"qrcodegenerator": "qrcodegenerator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
qt-qrcodegenerator = {
|
qrcodegenerator = {
|
||||||
url = "github:nayuki/QR-Code-generator";
|
url = "github:nayuki/QR-Code-generator";
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
@ -27,7 +27,7 @@
|
|||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
libnbtplusplus,
|
libnbtplusplus,
|
||||||
qt-qrcodegenerator,
|
qrcodegenerator,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -175,7 +175,7 @@
|
|||||||
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
|
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
|
||||||
inherit
|
inherit
|
||||||
libnbtplusplus
|
libnbtplusplus
|
||||||
qt-qrcodegenerator
|
qrcodegenerator
|
||||||
self
|
self
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
@ -1311,7 +1311,7 @@ target_link_libraries(Launcher_logic
|
|||||||
qdcss
|
qdcss
|
||||||
BuildConfig
|
BuildConfig
|
||||||
Qt${QT_VERSION_MAJOR}::Widgets
|
Qt${QT_VERSION_MAJOR}::Widgets
|
||||||
qrcode
|
qrcodegenerator
|
||||||
)
|
)
|
||||||
|
|
||||||
if (UNIX AND NOT CYGWIN AND NOT APPLE)
|
if (UNIX AND NOT CYGWIN AND NOT APPLE)
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "MSALoginDialog.h"
|
#include "MSALoginDialog.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
#include "qr.h"
|
|
||||||
#include "ui_MSALoginDialog.h"
|
#include "ui_MSALoginDialog.h"
|
||||||
|
|
||||||
#include "DesktopServices.h"
|
#include "DesktopServices.h"
|
||||||
@ -44,10 +43,15 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QColor>
|
||||||
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QSize>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtWidgets/QPushButton>
|
#include <QtWidgets/QPushButton>
|
||||||
|
|
||||||
|
#include "qrcodegen.hpp"
|
||||||
|
|
||||||
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
@ -139,6 +143,33 @@ 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 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:
|
||||||
|
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).
|
||||||
|
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);
|
||||||
|
painter.drawRects(&r, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, [[maybe_unused]] int expiresIn)
|
void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, [[maybe_unused]] int expiresIn)
|
||||||
{
|
{
|
||||||
ui->stackedWidget->setCurrentIndex(1);
|
ui->stackedWidget->setCurrentIndex(1);
|
||||||
|
@ -99,7 +99,7 @@ Canonical implementation of the murmur2 hash, taken from [SMHasher](https://gith
|
|||||||
|
|
||||||
Public domain (the author disclaimed the copyright).
|
Public domain (the author disclaimed the copyright).
|
||||||
|
|
||||||
## qt-qrcodegenerator
|
## QR-Code-generator
|
||||||
|
|
||||||
A simple library for generating QR codes
|
A simple library for generating QR codes
|
||||||
|
|
||||||
|
1
libraries/qrcodegenerator
Submodule
1
libraries/qrcodegenerator
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 2c9044de6b049ca25cb3cd1649ed7e27aa055138
|
@ -1,32 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
|
||||||
|
|
||||||
project(qrcode)
|
|
||||||
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
|
||||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
|
||||||
set(CMAKE_C_STANDARD_REQUIRED true)
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
|
||||||
|
|
||||||
|
|
||||||
if(QT_VERSION_MAJOR EQUAL 5)
|
|
||||||
find_package(Qt5 COMPONENTS Core Gui REQUIRED)
|
|
||||||
elseif(Launcher_QT_VERSION_MAJOR EQUAL 6)
|
|
||||||
find_package(Qt6 COMPONENTS Core Gui Core5Compat REQUIRED)
|
|
||||||
list(APPEND systeminfo_LIBS Qt${QT_VERSION_MAJOR}::Core5Compat)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_library(qrcode STATIC qr.h qr.cpp QR-Code-generator/cpp/qrcodegen.cpp QR-Code-generator/cpp/qrcodegen.hpp )
|
|
||||||
|
|
||||||
target_link_libraries(qrcode Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ${systeminfo_LIBS})
|
|
||||||
|
|
||||||
|
|
||||||
# needed for statically linked qrcode in shared libs on x86_64
|
|
||||||
set_target_properties(qrcode
|
|
||||||
PROPERTIES POSITION_INDEPENDENT_CODE TRUE
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(qrcode PUBLIC ./ PRIVATE QR-Code-generator/cpp/)
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
Subproject commit f40366c40d8d1956081f7ec643d240c02a81df52
|
|
@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
#include "qr.h"
|
|
||||||
#include "qrcodegen.hpp"
|
|
||||||
|
|
||||||
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:
|
|
||||||
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).
|
|
||||||
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);
|
|
||||||
painter.drawRects(&r, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QColor>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QSize>
|
|
||||||
|
|
||||||
// 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);
|
|
@ -9,7 +9,7 @@
|
|||||||
jdk17,
|
jdk17,
|
||||||
kdePackages,
|
kdePackages,
|
||||||
libnbtplusplus,
|
libnbtplusplus,
|
||||||
qt-qrcodegenerator,
|
qrcodegenerator,
|
||||||
ninja,
|
ninja,
|
||||||
self,
|
self,
|
||||||
stripJavaArchivesHook,
|
stripJavaArchivesHook,
|
||||||
@ -64,8 +64,8 @@ stdenv.mkDerivation {
|
|||||||
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/qt-qrcodegenerator/QR-Code-generator
|
rm -rf source/libraries/qrcodegenerator
|
||||||
ln -s ${qt-qrcodegenerator} source/libraries/qt-qrcodegenerator/QR-Code-generator
|
ln -s ${qrcodegenerator} source/libraries/qrcodegenerator
|
||||||
'';
|
'';
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user