Skip to content

Commit a70b581

Browse files
committed
feat(qr): add new QR library SCodes to scan qr codes
1 parent 9c6904d commit a70b581

File tree

9 files changed

+52
-57
lines changed

9 files changed

+52
-57
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@
127127
[submodule "vendor/status-keycard-qt"]
128128
path = vendor/status-keycard-qt
129129
url = https://github.com/status-im/status-keycard-qt
130+
[submodule "vendor/SCodes"]
131+
path = vendor/SCodes
132+
url = https://github.com/somcosoftware/SCodes.git

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ $(NIM_STATUS_CLIENT): update-qmake-previous
676676
endif
677677

678678
STATUSQ_LIB_PATH := $(STATUSQ_INSTALL_PATH)/StatusQ
679+
EXTRA_LIBS_PATH := $(STATUSQ_BUILD_PATH)/lib
679680
ifeq ($(mkspecs),win32)
680681
STATUSQ_LIB_PATH := $(STATUSQ_BUILD_PATH)/lib/$(COMMON_CMAKE_BUILD_TYPE)
681682
endif
@@ -687,11 +688,13 @@ $(NIM_STATUS_CLIENT): $(NIM_SOURCES) | statusq dotherside check-qt-dir $(STATUSG
687688
--passL:"-L$(STATUSGO_LIBDIR)" \
688689
--passL:"-lstatus" \
689690
--passL:"-L$(STATUSQ_LIB_PATH)" \
691+
--passL:"-L$(EXTRA_LIBS_PATH)" \
690692
--passL:"-lStatusQ" \
691693
--passL:"-L$(KEYCARD_LIBDIR)" \
692694
--passL:"-l$(KEYCARD_LINKNAME)" \
693695
--passL:"$(QRCODEGEN)" \
694696
--passL:"-lm" \
697+
--passL:"-l:libZXing.so.3" \
695698
--parallelBuild:0 \
696699
$(NIM_EXTRA_PARAMS) src/nim_status_client.nim
697700
ifeq ($(mkspecs),macx)
@@ -937,12 +940,12 @@ run: $(RUN_TARGET)
937940

938941
run-linux: nim_status_client
939942
echo -e "\033[92mRunning:\033[39m bin/nim_status_client"
940-
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_INSTALL_PATH)/StatusQ":"$(LD_LIBRARY_PATH)" \
943+
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_LIB_PATH)":"$(EXTRA_LIBS_PATH)":"$(LD_LIBRARY_PATH)" \
941944
./bin/nim_status_client $(ARGS)
942945

943946
run-linux-gdb: nim_status_client
944947
echo -e "\033[92mRunning:\033[39m bin/nim_status_client"
945-
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_INSTALL_PATH)/StatusQ":"$(LD_LIBRARY_PATH)" \
948+
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_LIB_PATH)":"$(EXTRA_LIBS_PATH)":"$(LD_LIBRARY_PATH)" \
946949
gdb -ex=r ./bin/nim_status_client $(ARGS)
947950

948951
run-macos: nim_status_client
@@ -953,7 +956,7 @@ run-macos: nim_status_client
953956
ln -fs ../../../nim_status_client ./
954957
fileicon set bin/nim_status_client status-dev.icns
955958
echo -e "\033[92mRunning:\033[39m bin/StatusDev.app/Contents/MacOS/nim_status_client"
956-
DYLD_LIBRARY_PATH="$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_INSTALL_PATH)/StatusQ":"$(DYLD_LIBRARY_PATH)" \
959+
DYLD_LIBRARY_PATH="$(STATUSGO_LIBDIR)":"$(KEYCARD_LIBDIR)":"$(STATUSQ_LIB_PATH)":"$(EXTRA_LIBS_PATH)":"$(DYLD_LIBRARY_PATH)" \
957960
./bin/StatusDev.app/Contents/MacOS/nim_status_client $(ARGS)
958961

959962
run-windows: STATUS_RC_FILE = status-dev.rc
@@ -975,7 +978,7 @@ NIM_TEST_FILES := $(wildcard test/nim/*.nim)
975978
NIM_TESTS := $(foreach test_file,$(NIM_TEST_FILES),nim-test-run/$(test_file))
976979

977980
nim-test-run/%: | dotherside $(STATUSGO) $(QRCODEGEN)
978-
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(LD_LIBRARY_PATH)" $(ENV_SCRIPT) \
981+
LD_LIBRARY_PATH="$(QT_LIBDIR)":"$(LIBWAKU_LIBDIR)":"$(NIMSDS_LIBDIR)":"$(STATUSGO_LIBDIR)":"$(EXTRA_LIBS_PATH)":"$(LD_LIBRARY_PATH)" $(ENV_SCRIPT) \
979982
nim c $(NIM_PARAMS) $(NIM_EXTRA_PARAMS) --mm:refc --passL:"-L$(STATUSGO_LIBDIR)" --passL:"-lstatus" --passL:"$(QRCODEGEN)" -r $(subst nim-test-run/,,$@)
980983

981984
tests-nim-linux: $(NIM_TESTS)

mobile/scripts/buildStatusQ.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ cmake -S "${STATUSQ}" -B "${BUILD_DIR}" \
3232
-DSTATUSQ_TESTMODE=$([[ "${STATUSQ_TESTMODE}" == "true" ]] && echo ON || echo OFF)
3333

3434
make -C "${BUILD_DIR}" qzxing -j "$(nproc)"
35+
make -C "${BUILD_DIR}" SCodes -j "$(nproc)"
3536
make -C "${BUILD_DIR}" StatusQ -j "$(nproc)"
3637

3738
mkdir -p "${LIB_DIR}"
3839

3940
STATUSQ_LIB=$(find "${BUILD_DIR}" -name "libStatusQ${LIB_SUFFIX}${LIB_EXT}")
41+
SCODES_LIB=$(find "${BUILD_DIR}" -name "libSCodes.a")
4042
QZXING_LIB=$(find "${BUILD_DIR}" -name "libqzxing.a")
4143

4244
cp "${STATUSQ_LIB}" "${LIB_DIR}/libStatusQ${LIB_SUFFIX}${LIB_EXT}"
43-
cp "${QZXING_LIB}" "${LIB_DIR}/libqzxing.a"
45+
cp "${QZXING_LIB}" "${LIB_DIR}/libqzxing.a"
46+
cp "${SCODES_LIB}" "${LIB_DIR}/libSCodes.a"

scripts/init_app_dir.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mkdir -p \
1616

1717
cp bin/nim_status_client "${APP_DIR}/usr/bin"
1818
cp bin/StatusQ/* "${APP_DIR}/usr/lib"
19+
cp -R bin/lib/* "${APP_DIR}/usr/lib"
1920
cp nim-status.desktop "${APP_DIR}/."
2021
cp status.png "${APP_DIR}/status.png"
2122
cp status.png "${APP_DIR}/usr/"

ui/StatusQ/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ endif()
8282

8383
add_subdirectory(../../vendor/SortFilterProxyModel SortFilterProxyModel)
8484
add_subdirectory(../../vendor/qzxing/src qzxing)
85+
add_subdirectory(../../vendor/SCodes/src SCodes)
8586

8687
target_compile_options(qzxing PRIVATE -w)
88+
target_compile_options(SCodes PRIVATE -w)
8789
target_compile_options(SortFilterProxyModel PRIVATE -w)
8890

8991
### StatusQ library
@@ -286,6 +288,7 @@ target_link_libraries(StatusQ PRIVATE
286288
QtModelsToolkit
287289
MobileUI
288290
qzxing
291+
SCodes
289292
)
290293

291294
if (CMAKE_BUILD_TYPE STREQUAL "Debug")

ui/StatusQ/src/StatusQ/Components/StatusQrCodeCapture.qml

Lines changed: 27 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import QtQuick
22

33
import QtMultimedia
44
import QZXing
5+
import com.scythestudio.scodes 1.0
56

67
Item {
78
id: root
@@ -13,28 +14,27 @@ Item {
1314
readonly property real sourceRatio: videoOutput.sourceRect.width
1415
/ videoOutput.sourceRect.height
1516

16-
readonly property int failsCount: d.failsCount
17-
readonly property int tagsCount: d.tagsCount
18-
readonly property int decodeTime: d.decodeTime
1917
readonly property string lastTag: d.lastTag
20-
readonly property string currentTag: d.currentTag
2118

2219
readonly property alias contentRect: videoOutput.contentRect
2320

21+
required property int captureRectWidth
22+
required property int captureRectHeight
23+
2424
readonly property var availableCameras: {
2525
return mediaDevices.videoInputs.map(d => ({
2626
deviceId: d.id.toString(),
2727
displayName: d.description
2828
}))
2929
}
3030

31-
readonly property bool cameraAvailable: camera.active
32-
readonly property string cameraError: camera.errorString
31+
readonly property bool cameraAvailable: barcodeScanner.camera.active
32+
readonly property string cameraError: barcodeScanner.camera.errorString
3333

3434
signal tagFound(string tag)
3535

3636
function setCameraDevice(deviceId: string) {
37-
camera.cameraDevice = mediaDevices.videoInputs.find(
37+
barcodeScanner.camera.cameraDevice = mediaDevices.videoInputs.find(
3838
d => d.id.toString() === deviceId)
3939
}
4040

@@ -45,59 +45,39 @@ Item {
4545
QtObject {
4646
id: d
4747

48-
property int failsCount: 0
49-
property int tagsCount: 0
50-
property int decodeTime: 0
5148
property string lastTag
52-
property string currentTag
5349
}
5450

55-
Camera {
56-
id: camera
5751

58-
active: true
59-
focusMode: Camera.FocusModeAutoNear
52+
SBarcodeScanner {
53+
id: barcodeScanner
6054

61-
Component.onDestruction: camera.active = false
62-
}
55+
forwardVideoSink: videoOutput.videoSink
56+
scanning: true
57+
58+
captureRect: contentZoneHighlight
6359

64-
CaptureSession {
65-
camera: camera
66-
videoOutput: videoOutput
60+
onCapturedChanged: (tag) => {
61+
d.lastTag = tag
62+
root.tagFound(tag)
63+
}
6764
}
6865

6966
VideoOutput {
7067
id: videoOutput
7168

7269
anchors.fill: parent
73-
fillMode: VideoOutput.PreserveAspectCrop
74-
}
7570

76-
QZXingFilter {
77-
id: zxingFilter
78-
videoSink: videoOutput.videoSink
79-
orientation: videoOutput.orientation
80-
81-
captureRect: videoOutput.sourceRect
82-
83-
decoder {
84-
enabledDecoders: QZXing.DecoderFormat_EAN_13 | QZXing.DecoderFormat_CODE_39 | QZXing.DecoderFormat_QR_CODE
85-
onTagFound: (tag) => {
86-
d.currentTag = tag
87-
d.lastTag = tag
88-
root.tagFound(tag)
89-
}
90-
tryHarder: false
91-
}
71+
width: root.width
9272

93-
onDecodingFinished: (succeeded, decodeTime) => {
94-
if (succeeded) {
95-
++d.tagsCount
96-
} else {
97-
++d.failsCount
98-
d.currentTag = ""
99-
}
100-
d.decodeTime = decodeTime
101-
}
73+
focus: visible
74+
fillMode: VideoOutput.PreserveAspectCrop
75+
}
76+
Rectangle {
77+
id: captureRect
78+
width: root.captureRectWidth
79+
height: root.captureRectHeight
80+
anchors.centerIn: parent
81+
visible: false
10282
}
10383
}

ui/StatusQ/src/StatusQ/Components/StatusQrCodeScanner.qml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ Item {
3232
readonly property size contentSize: capture.contentSize
3333
readonly property real sourceRatio: capture.sourceRatio
3434

35-
readonly property int failsCount: capture.failsCount
36-
readonly property int tagsCount: capture.tagsCount
37-
readonly property int decodeTime: capture.decodeTime
3835
readonly property string lastTag: capture.lastTag
39-
readonly property string currentTag: capture.currentTag
4036

4137
property int state: StatusQrCodeScanner.State.None
4238

@@ -74,6 +70,8 @@ Item {
7470
anchors.fill: parent
7571
visible: false
7672
clip: true
73+
captureRectWidth: scanCorners.width
74+
captureRectHeight: scanCorners.height
7775

7876
onTagFound: (tag) => root.tagFound(tag)
7977
}
@@ -113,7 +111,7 @@ Item {
113111

114112
StatusScanCorners {
115113
id: scanCorners
116-
width: root.width / 1.5
114+
width: root.width / 1.4
117115
height: width
118116
anchors.centerIn: parent
119117
color: {

ui/StatusQ/src/typesregistration.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "onboarding/enums.h"
3434

3535
#include <QZXing.h>
36+
#include <SBarcodeScanner.h>
3637

3738
#include <QQmlEngine>
3839

@@ -65,6 +66,8 @@ void registerStatusQTypes() {
6566
qmlRegisterType<StatusEmojiModel>("StatusQ", 0, 1, "StatusEmojiModel");
6667
qmlRegisterType<FormattedDoubleProperty>("StatusQ", 0, 1, "FormattedDoubleProperty");
6768

69+
qmlRegisterType<SBarcodeScanner>("com.scythestudio.scodes", 1, 0, "SBarcodeScanner");
70+
6871
qmlRegisterSingletonType<ClipboardUtils>("StatusQ", 0, 1, "ClipboardUtils", &ClipboardUtils::qmlInstance);
6972
qmlRegisterSingletonType<UrlUtils>("StatusQ", 0, 1, "UrlUtils", [](QQmlEngine* engine, QJSEngine*) {
7073
return new UrlUtils(engine);

vendor/SCodes

Submodule SCodes added at c064729

0 commit comments

Comments
 (0)