Commit 63e1745f authored by Volker Krause's avatar Volker Krause
Browse files

Add ability to directly scan and import from barcodes

parent ffc537c6
Pipeline #178582 passed with stage
in 2 minutes and 2 seconds
......@@ -10,7 +10,7 @@ set (RELEASE_SERVICE_VERSION_MICRO "70")
set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
project(itinerary VERSION ${RELEASE_SERVICE_VERSION})
set(KF5_MIN_VERSION 5.90)
set(KF5_MIN_VERSION 5.94)
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake)
......@@ -59,11 +59,13 @@ set_package_properties("ZLIB" PROPERTIES PURPOSE "Needed for retrieving weather
set_package_properties(KF5Solid PROPERTIES TYPE OPTIONAL TYPE RUNTIME PURPOSE "Used for controlling the screen brightness.")
set_package_properties(KHealthCertificate PROPERTIES TYPE OPTIONAL PURPOSE "Needed for the vaccination certificate manager.")
include(ECMQMLModules)
include(ECMFindQmlModule)
ecm_find_qmlmodule(QtLocation 5.11)
ecm_find_qmlmodule(QtMultimedia 5.15)
ecm_find_qmlmodule(QtPositioning 5.11)
ecm_find_qmlmodule(org.kde.kitemmodels 1.0)
ecm_find_qmlmodule(org.kde.prison 1.0)
ecm_find_qmlmodule(org.kde.prison.scanner 1.0)
ecm_find_qmlmodule(org.kde.kosmindoormap 1.0)
ecm_find_qmlmodule(org.kde.kopeninghours 1.0)
if (NOT ANDROID)
......
......@@ -18,6 +18,8 @@ QtObject {
* Scan mode will automatically be disabled when the page is left or moves down in the page stack.
*/
property var page
/** Enable full brightness. */
property bool fullBrightness: true
function toggle() {
controller.enabled = !controller.enabled;
......@@ -25,7 +27,9 @@ QtObject {
onEnabledChanged: function() {
console.log("switching barcode scan mode", controller.enabled);
Solid.BrightnessManager.toggleBrightness();
if (controller.fullBrightness) {
Solid.BrightnessManager.toggleBrightness();
}
Solid.LockManager.toggleInhibitScreenLock(i18n("In barcode scanning mode"));
}
......
/*
SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15 as QQC2
import QtMultimedia 5.15
import org.kde.kirigami 2.17 as Kirigami
import org.kde.prison.scanner 1.0 as Prison
import org.kde.itinerary 1.0
import "." as App
Kirigami.Page {
id: root
title: i18n("Scan Barcode")
leftPadding: 0
rightPadding: 0
topPadding: 0
bottomPadding: 0
VideoOutput {
id: viewFinder
anchors.fill: parent
source: camera
filters: [scanner]
autoOrientation: true
fillMode: VideoOutput.PreserveAspectCrop
}
Prison.VideoScanner {
id: scanner
formats: Prison.Format.QRCode | Prison.Format.Aztec | Prison.Format.DataMatrix | Prison.Format.PDF417
onResultContentChanged: {
if (result.hasText && ApplicationController.importText(result.text)) {
applicationWindow().pageStack.goBack();
}
if (result.hasBinaryData && ApplicationController.importData(result.binaryData)) {
applicationWindow().pageStack.goBack();
}
}
}
Camera {
id: camera
focus {
focusMode: Camera.FocusContinuous
focusPointMode: Camera.FocusPointCenter
}
}
Rectangle {
border {
color: Kirigami.Theme.focusColor
width: 2
}
color: Qt.rgba(Kirigami.Theme.focusColor.r, Kirigami.Theme.focusColor.g, Kirigami.Theme.focusColor.b, 0.2);
radius: Kirigami.Units.smallSpacing
x: viewFinder.mapRectToItem(scanner.result.boundingRect).x
y: viewFinder.mapRectToItem(scanner.result.boundingRect).y
width: viewFinder.mapRectToItem(scanner.result.boundingRect).width
height: viewFinder.mapRectToItem(scanner.result.boundingRect).height
}
BarcodeScanModeController {
page: root
fullBrightness: false
enabled: camera.errorCode != Camera.NoError
}
Kirigami.PlaceholderMessage {
anchors.fill: parent
text: i18n("No camera available.")
visible: camera.errorCode != Camera.NoError
}
}
......@@ -375,21 +375,21 @@ void ApplicationController::importLocalFile(const QUrl &url)
importData(f.readAll(), f.fileName());
}
void ApplicationController::importData(const QByteArray &data, const QString &fileName)
bool ApplicationController::importData(const QByteArray &data, const QString &fileName)
{
qCDebug(Log);
if (data.size() < 4) {
return;
return false;
}
if (FileHelper::hasZipHeader(data)) {
#ifndef NEW_PKPASS_IMPORT
if (!m_pkPassMgr->importPassFromData(data).isEmpty()) {
return;
return true;
}
#endif
if (importBundle(data)) {
return;
return true;
}
}
......@@ -428,24 +428,30 @@ void ApplicationController::importData(const QByteArray &data, const QString &fi
importNode(engine.rootDocumentNode());
Q_EMIT infoMessage(i18np("One reservation imported.", "%1 reservations imported.", resIds.size()));
return;
return true;
}
// look for time-less passes/program memberships/etc
if (m_passMgr->import(extractorResult) || importGenericPkPass(engine.rootDocumentNode())) {
Q_EMIT infoMessage(i18n("Pass imported."));
return;
return true;
}
// look for health certificate barcodes instead
// if we don't find anything, try to import as health certificate directly
if (importHealthCertificateRecursive(engine.rootDocumentNode()) || m_healthCertMgr->importCertificate(data)) {
Q_EMIT infoMessage(i18n("Health certificate imported."));
return;
return true;
}
// nothing found
Q_EMIT infoMessage(i18n("Nothing imported."));
return false;
}
bool ApplicationController::importText(const QString& text)
{
return importData(text.toUtf8());
}
void ApplicationController::importNode(const KItinerary::ExtractorDocumentNode &node)
......
......@@ -59,7 +59,8 @@ public:
void importFromIntent(const KAndroidExtras::Intent &intent);
Q_INVOKABLE void importFromClipboard();
Q_INVOKABLE void importFromUrl(const QUrl &url);
void importData(const QByteArray &data, const QString &fileName = {});
Q_INVOKABLE bool importData(const QByteArray &data, const QString &fileName = {});
Q_INVOKABLE bool importText(const QString &text);
Q_INVOKABLE void checkCalendar();
......
......@@ -48,6 +48,11 @@ Kirigami.ApplicationWindow {
iconName: "document-open"
onTriggered: importDialog.open()
},
Kirigami.Action {
text: i18n("Scan Barcode...")
iconName: "view-barcode-qr"
onTriggered: pageStack.layers.push(scanBarcodeComponent)
},
Kirigami.Action {
text: i18n("Paste")
iconName: "edit-paste"
......@@ -192,6 +197,10 @@ Kirigami.ApplicationWindow {
id: mainPageComponent
App.TimelinePage {}
}
Component {
id: scanBarcodeComponent
App.BarcodeScannerPage {}
}
Component {
id: settingsComponent
App.SettingsPage {}
......
......@@ -11,6 +11,7 @@
<file>AlternativeJourneyPage.qml</file>
<file>BarcodeContainer.qml</file>
<file>BarcodeScanModeController.qml</file>
<file>BarcodeScannerPage.qml</file>
<file>BoardingPass.qml</file>
<file>BusDelegate.qml</file>
<file>BusPage.qml</file>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment