From 64f93fb508659cabd24bced2256c992bacd238d2 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Mon, 13 Aug 2018 16:16:09 +0300 Subject: [PATCH 01/13] Have been added the states for changed screen depending on a user has camera permission or not. --- .../resources/QRScanningView.qml | 152 ++++++++++++------ 1 file changed, 102 insertions(+), 50 deletions(-) diff --git a/GraftMobileClient/resources/QRScanningView.qml b/GraftMobileClient/resources/QRScanningView.qml index 7c25cff0..ae0b53bf 100644 --- a/GraftMobileClient/resources/QRScanningView.qml +++ b/GraftMobileClient/resources/QRScanningView.qml @@ -3,6 +3,7 @@ import QtMultimedia 5.9 import QtQuick.Controls 2.2 import QtGraphicalEffects 1.0 import QZXing 2.3 +import com.device.platform 1.0 Item { property string lastTag: "" @@ -17,73 +18,124 @@ Item { } } - Camera { - id: camera - focus { - focusMode: Camera.FocusContinuous - focusPointMode: Camera.FocusPointCustom - customFocusPoint: Qt.point(0.5, 0.5) // Focus relative to the frame center + Component.onCompleted: { + if (Detector.isMobile()) { + state = camera.cameraState === Camera.UnloadedState || + camera.cameraStatus === Camera.ActiveStatus ? "messageScreen" : "scanScreen" + } else { + state = "scanScreen" } } - VideoOutput { - id: videoOutput + Item { + id: scanScreen anchors.fill: parent - source: camera - autoOrientation: true - focus: visible - fillMode: VideoOutput.PreserveAspectCrop - filters: [ zxingFilter ] - } - Rectangle { - anchors.fill: parent - id: captureZone - color: "transparent" + Camera { + id: camera + focus { + focusMode: Camera.FocusContinuous + focusPointMode: Camera.FocusPointCustom + customFocusPoint: Qt.point(0.5, 0.5) // Focus relative to the frame center + } + onCameraStateChanged: { + if (cameraState === Camera.UnloadedState) { + camera.start() + } + } + } - Rectangle { - width: parent.width * 0.75 - height: width - anchors.centerIn: parent - color: "green" - opacity: 0.7 + VideoOutput { + id: videoOutput + anchors.fill: parent + source: camera + autoOrientation: true + focus: visible + fillMode: VideoOutput.PreserveAspectCrop + filters: [ zxingFilter ] } - } - Rectangle { - anchors.fill: parent - color: "black" - opacity: 0.5 - } + Rectangle { + anchors.fill: parent + id: captureZone + color: "transparent" - OpacityMask { - anchors.fill: parent - source: videoOutput - maskSource: captureZone - } + Rectangle { + width: parent.width * 0.75 + height: width + anchors.centerIn: parent + color: "green" + opacity: 0.7 + } + } - QZXingFilter { - id: zxingFilter - captureRect: { - var rect = Qt.rect(0, 0, 1, 1) - var normalizedRect = videoOutput.mapNormalizedRectToItem(rect) - return videoOutput.mapRectToSource(normalizedRect) + Rectangle { + anchors.fill: parent + color: "black" + opacity: 0.5 } - decoder { - enabledDecoders: QZXing.DecoderFormat_QR_CODE - tryHarder: false - onTagFound: { - if (lastTag != tag) { - lastTag = tag - console.log(tag + " | " + " | " + decoder.charSet()) - camera.stop() - qrCodeDetected(tag) + OpacityMask { + anchors.fill: parent + source: videoOutput + maskSource: captureZone + } + + QZXingFilter { + id: zxingFilter + captureRect: { + var rect = Qt.rect(0, 0, 1, 1) + var normalizedRect = videoOutput.mapNormalizedRectToItem(rect) + return videoOutput.mapRectToSource(normalizedRect) + } + + decoder { + enabledDecoders: QZXing.DecoderFormat_QR_CODE + tryHarder: false + onTagFound: { + if (lastTag != tag) { + lastTag = tag + console.log(tag + " | " + " | " + decoder.charSet()) + camera.stop() + qrCodeDetected(tag) + } } } } } + Item { + id: messageScreen + implicitHeight: 110 + implicitWidth: parent.width - 60 + anchors.centerIn: parent + + Label { + anchors.fill: parent + wrapMode: Label.WordWrap + horizontalAlignment: Label.AlignHCenter + verticalAlignment: Label.AlignVCenter + font.pixelSize: 16 + color: "#A8A8A8" + text: qsTr("You haven't permission for the camera. Please, turn on camera permission " + + "in settings of the application.") + } + } + + states: [ + State { + name: "scanScreen" + PropertyChanges { target: scanScreen; visible: true } + PropertyChanges { target: messageScreen; visible: false } + }, + + State { + name: "messageScreen" + PropertyChanges { target: scanScreen; visible: false } + PropertyChanges { target: messageScreen; visible: true } + } + ] + function resetView() { camera.start() lastTag = "" From 1f4c6bfd51ffc46be3b0e80f6e05196e802eb818 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Wed, 15 Aug 2018 15:43:52 +0300 Subject: [PATCH 02/13] Have been added the camera filter for check in iOS is camera has or don't have permission, also add one scan screen for iOS and another for Android. --- GraftMobileClient/GraftMobileClient.pro | 6 +- GraftMobileClient/camerafilter.cpp | 28 ++++ GraftMobileClient/camerafilter.h | 28 ++++ GraftMobileClient/core/config.h | 9 +- .../resources/LicenseAgreementScreen.qml | 1 - .../resources/SelectImageButton.qml | 2 +- .../resources/SelectImageDialog.qml | 2 +- .../android/wallet/QRScanningView.qml | 139 +++++++++++++++++ GraftMobileClient/resources/android_qml.qrc | 1 + GraftMobileClient/resources/general_qml.qrc | 1 - .../resources/ios/wallet/QRScanningView.qml | 144 ++++++++++++++++++ GraftMobileClient/resources/ios_qml.qrc | 1 + 12 files changed, 353 insertions(+), 9 deletions(-) create mode 100644 GraftMobileClient/camerafilter.cpp create mode 100644 GraftMobileClient/camerafilter.h create mode 100644 GraftMobileClient/resources/android/wallet/QRScanningView.qml create mode 100644 GraftMobileClient/resources/ios/wallet/QRScanningView.qml diff --git a/GraftMobileClient/GraftMobileClient.pro b/GraftMobileClient/GraftMobileClient.pro index 01885e44..b9906000 100644 --- a/GraftMobileClient/GraftMobileClient.pro +++ b/GraftMobileClient/GraftMobileClient.pro @@ -84,7 +84,8 @@ SOURCES += main.cpp \ core/accountmodelserializator.cpp \ core/accountmanager.cpp \ core/qrcodegenerator.cpp \ - devicedetector.cpp + devicedetector.cpp \ + camerafilter.cpp HEADERS += \ core/config.h \ @@ -109,7 +110,8 @@ HEADERS += \ core/accountmanager.h \ core/graftclienttools.h \ core/qrcodegenerator.h \ - devicedetector.h + devicedetector.h \ + camerafilter.h include(resources/resources.pri) diff --git a/GraftMobileClient/camerafilter.cpp b/GraftMobileClient/camerafilter.cpp new file mode 100644 index 00000000..516039a9 --- /dev/null +++ b/GraftMobileClient/camerafilter.cpp @@ -0,0 +1,28 @@ +#include "camerafilter.h" +#include + +CameraFilter::CameraFilter(QObject *parent) : QAbstractVideoFilter(parent) +{ + QTimer::singleShot(2000, this, [this]() { + this->hasPermission(false); + }); +} + +QVideoFilterRunnable *CameraFilter::createFilterRunnable() +{ + return new CameraRunnable(this); +} + +CameraRunnable::CameraRunnable(CameraFilter *filter) : mFilter(filter) +{ +} + +QVideoFrame CameraRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, + QVideoFilterRunnable::RunFlags flags) +{ + Q_UNUSED(surfaceFormat); + Q_UNUSED(flags); + + emit mFilter->hasPermission(!input->size().isEmpty()); + return *input; +} diff --git a/GraftMobileClient/camerafilter.h b/GraftMobileClient/camerafilter.h new file mode 100644 index 00000000..fe9bb612 --- /dev/null +++ b/GraftMobileClient/camerafilter.h @@ -0,0 +1,28 @@ +#ifndef CAMERAFILTER_H +#define CAMERAFILTER_H + +#include + +class CameraFilter : public QAbstractVideoFilter +{ + Q_OBJECT +public: + CameraFilter(QObject *parent = nullptr); + QVideoFilterRunnable *createFilterRunnable() override; + +signals: + void hasPermission(bool result); +}; + +class CameraRunnable : public QVideoFilterRunnable +{ +public: + CameraRunnable(CameraFilter *filter); + QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, + RunFlags flags); + +private: + CameraFilter *mFilter; +}; + +#endif // CAMERAFILTER_H diff --git a/GraftMobileClient/core/config.h b/GraftMobileClient/core/config.h index 55cd1d41..9182d7f1 100644 --- a/GraftMobileClient/core/config.h +++ b/GraftMobileClient/core/config.h @@ -5,7 +5,8 @@ static const QString scUrl("%1/dapi"); -namespace MainnetConfiguration { +namespace MainnetConfiguration +{ static const QString scConfigTitle("Mainnet"); static const QStringList scHttpSeedSupernodes{"mainnet-seed.graft.network:18900" @@ -19,7 +20,8 @@ static const QStringList scHttpsSeedSupernodes{"mainnet-seed.graft.network:18943 static const QString scDAPIVersion("1.0G"); } -namespace TestnetConfiguration { +namespace TestnetConfiguration +{ static const QString scConfigTitle("Public Testnet"); static const QStringList scHttpSeedSupernodes{"testnet-pub-seed.graft.network:28900" @@ -33,7 +35,8 @@ static const QStringList scHttpsSeedSupernodes{"testnet-pub-seed.graft.network:2 static const QString scDAPIVersion("1.0F"); } -namespace ExperimentalTestnetConfiguration { +namespace ExperimentalTestnetConfiguration +{ static const QString scConfigTitle("Public RTA Testnet"); static const QStringList scHttpSeedSupernodes{"testnet-rta-seed.graft.network:28900" diff --git a/GraftMobileClient/resources/LicenseAgreementScreen.qml b/GraftMobileClient/resources/LicenseAgreementScreen.qml index cdf69896..ee326e63 100644 --- a/GraftMobileClient/resources/LicenseAgreementScreen.qml +++ b/GraftMobileClient/resources/LicenseAgreementScreen.qml @@ -126,7 +126,6 @@ BaseScreen { "SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.") } } - } WideActionButton { diff --git a/GraftMobileClient/resources/SelectImageButton.qml b/GraftMobileClient/resources/SelectImageButton.qml index 956a30eb..2c455144 100644 --- a/GraftMobileClient/resources/SelectImageButton.qml +++ b/GraftMobileClient/resources/SelectImageButton.qml @@ -1,6 +1,6 @@ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 import QtQuick.Layouts 1.3 Button { diff --git a/GraftMobileClient/resources/SelectImageDialog.qml b/GraftMobileClient/resources/SelectImageDialog.qml index bc2f0903..1961d926 100644 --- a/GraftMobileClient/resources/SelectImageDialog.qml +++ b/GraftMobileClient/resources/SelectImageDialog.qml @@ -1,6 +1,6 @@ import QtQuick 2.9 -import QtQuick.Controls.Material 2.2 import QtQuick.Controls 2.2 +import QtQuick.Controls.Material 2.2 import QtQuick.Layouts 1.3 Popup { diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml new file mode 100644 index 00000000..5420b279 --- /dev/null +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -0,0 +1,139 @@ +import QtQuick 2.9 +import QtMultimedia 5.9 +import QtQuick.Controls 2.2 +import QtGraphicalEffects 1.0 +import QZXing 2.3 + +Item { + property string lastTag: "" + + signal qrCodeDetected(string message) + + onVisibleChanged: { + if (visible) { + camera.start() + } else { + camera.stop() + } + } + + Component.onCompleted: { + state = camera.cameraStatus === Camera.ActiveStatus || + camera.cameraState === Camera.UnloadedState ? "messageScreen" : "scanScreen" + } + + Item { + id: scanScreen + anchors.fill: parent + visible: false + + Camera { + id: camera + focus { + focusMode: Camera.FocusContinuous + focusPointMode: Camera.FocusPointCustom + customFocusPoint: Qt.point(0.5, 0.5) // Focus relative to the frame center + } + onCameraStateChanged: { + if (cameraState === Camera.UnloadedState) { + camera.start() + } + } + } + + VideoOutput { + id: videoOutput + anchors.fill: parent + source: camera + autoOrientation: true + focus: visible + fillMode: VideoOutput.PreserveAspectCrop + filters: [ zxingFilter ] + } + + Rectangle { + anchors.fill: parent + id: captureZone + color: "transparent" + + Rectangle { + width: parent.width * 0.75 + height: width + anchors.centerIn: parent + color: "green" + opacity: 0.7 + } + } + + Rectangle { + anchors.fill: parent + color: "black" + opacity: 0.5 + } + + OpacityMask { + anchors.fill: parent + source: videoOutput + maskSource: captureZone + } + + QZXingFilter { + id: zxingFilter + captureRect: { + var rect = Qt.rect(0, 0, 1, 1) + var normalizedRect = videoOutput.mapNormalizedRectToItem(rect) + return videoOutput.mapRectToSource(normalizedRect) + } + + decoder { + enabledDecoders: QZXing.DecoderFormat_QR_CODE + tryHarder: false + onTagFound: { + if (lastTag != tag) { + lastTag = tag + console.log(tag + " | " + " | " + decoder.charSet()) + camera.stop() + qrCodeDetected(tag) + } + } + } + } + } + + Item { + id: messageScreen + implicitHeight: 110 + implicitWidth: parent.width - 60 + anchors.centerIn: parent + visible: false + + Label { + anchors.fill: parent + wrapMode: Label.WordWrap + horizontalAlignment: Label.AlignHCenter + font.pixelSize: 16 + color: "#A8A8A8" + text: qsTr("You haven't permission for the camera. Please, turn on camera permission " + + "in settings of the application.") + } + } + + states: [ + State { + name: "scanScreen" + PropertyChanges { target: scanScreen; visible: true } + PropertyChanges { target: messageScreen; visible: false } + }, + + State { + name: "messageScreen" + PropertyChanges { target: scanScreen; visible: false } + PropertyChanges { target: messageScreen; visible: true } + } + ] + + function resetView() { + camera.start() + lastTag = "" + } +} diff --git a/GraftMobileClient/resources/android_qml.qrc b/GraftMobileClient/resources/android_qml.qrc index 7c2c4ff4..36aeb901 100644 --- a/GraftMobileClient/resources/android_qml.qrc +++ b/GraftMobileClient/resources/android_qml.qrc @@ -23,5 +23,6 @@ android/wallet/BalanceScreen.qml android/wallet/PaymentConfirmationScreen.qml android/wallet/SettingsScreen.qml + android/wallet/QRScanningView.qml diff --git a/GraftMobileClient/resources/general_qml.qrc b/GraftMobileClient/resources/general_qml.qrc index 2c7a9cc1..61bf869c 100644 --- a/GraftMobileClient/resources/general_qml.qrc +++ b/GraftMobileClient/resources/general_qml.qrc @@ -1,7 +1,6 @@ qtquickcontrols2.conf - QRScanningView.qml BaseHeader.qml CartItem.qml GraftApplicationWindow.qml diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml new file mode 100644 index 00000000..1c6b25a2 --- /dev/null +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -0,0 +1,144 @@ +import QtQuick 2.9 +import QtMultimedia 5.9 +import QtQuick.Controls 2.2 +import QtGraphicalEffects 1.0 +import QZXing 2.3 +import com.device.platform 1.0 +import org.cameraPermissionFilter 1.0 + +Item { + property string lastTag: "" + property bool whichState: false + + signal qrCodeDetected(string message) + + onVisibleChanged: { + if (visible) { + camera.start() + } else { + camera.stop() + } + } + + state: Detector.isDesktop() ? "scanScreen" : "messageScreen" + + Item { + id: scanScreen + anchors.fill: parent + visible: false + + Camera { + id: camera + focus { + focusMode: Camera.FocusContinuous + focusPointMode: Camera.FocusPointCustom + customFocusPoint: Qt.point(0.5, 0.5) // Focus relative to the frame center + } + } + + VideoOutput { + id: videoOutput + anchors.fill: parent + source: camera + autoOrientation: true + focus: visible + fillMode: VideoOutput.PreserveAspectCrop + filters: [ filter, zxingFilter ] + } + + CameraFilter { + id: filter + onHasPermission: { + whichState = result + } + } + + Rectangle { + anchors.fill: parent + id: captureZone + color: "transparent" + + Rectangle { + width: parent.width * 0.75 + height: width + anchors.centerIn: parent + color: "green" + opacity: 0.7 + } + } + + Rectangle { + anchors.fill: parent + color: "black" + opacity: 0.5 + } + + OpacityMask { + anchors.fill: parent + source: videoOutput + maskSource: captureZone + } + + QZXingFilter { + id: zxingFilter + captureRect: { + var rect = Qt.rect(0, 0, 1, 1) + var normalizedRect = videoOutput.mapNormalizedRectToItem(rect) + return videoOutput.mapRectToSource(normalizedRect) + } + + decoder { + enabledDecoders: QZXing.DecoderFormat_QR_CODE + tryHarder: false + onTagFound: { + if (lastTag != tag) { + lastTag = tag + console.log(tag + " | " + " | " + decoder.charSet()) + camera.stop() + qrCodeDetected(tag) + } + } + } + } + } + + Item { + id: messageScreen + implicitHeight: 110 + implicitWidth: parent.width - 60 + anchors.centerIn: parent + visible: false + + Label { + anchors.fill: parent + wrapMode: Label.WordWrap + horizontalAlignment: Label.AlignHCenter + verticalAlignment: Label.AlignVCenter + font.pixelSize: 16 + color: "#A8A8A8" + text: qsTr("You haven't permission for the camera. Please, turn on camera permission " + + "in settings of the application.") + } + } + + states: [ + State { + name: "scanScreen" + PropertyChanges { target: scanScreen; visible: true } + PropertyChanges { target: messageScreen; visible: false } + when: whichState + }, + + State { + name: "messageScreen" + PropertyChanges { target: scanScreen; visible: false } + PropertyChanges { target: messageScreen; visible: true } + when: Detector.isMobile() + } + ] + + function resetView() { + camera.start() + lastTag = "" + } +} diff --git a/GraftMobileClient/resources/ios_qml.qrc b/GraftMobileClient/resources/ios_qml.qrc index a00ce5bf..1c055aad 100644 --- a/GraftMobileClient/resources/ios_qml.qrc +++ b/GraftMobileClient/resources/ios_qml.qrc @@ -21,5 +21,6 @@ ios/wallet/BalanceScreen.qml ios/wallet/PaymentConfirmationScreen.qml ios/wallet/SettingsScreen.qml + ios/wallet/QRScanningView.qml From 46f96721935a99330aad55f2f0385d9817757e2c Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Wed, 15 Aug 2018 16:13:35 +0300 Subject: [PATCH 03/13] Have been register camera filter type for QML. --- GraftMobileClient/core/graftbaseclient.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GraftMobileClient/core/graftbaseclient.cpp b/GraftMobileClient/core/graftbaseclient.cpp index edc590d5..df40bc09 100644 --- a/GraftMobileClient/core/graftbaseclient.cpp +++ b/GraftMobileClient/core/graftbaseclient.cpp @@ -8,6 +8,7 @@ #include "accountmanager.h" #include "currencymodel.h" #include "currencyitem.h" +#include "camerafilter.h" #include "accountmodel.h" #include "config.h" @@ -199,6 +200,8 @@ void GraftBaseClient::registerTypes(QQmlEngine *engine) qmlRegisterUncreatableType("org.graft", 1, 0, "GraftClientTools", "You cannot create an instance of GraftClientTools type."); + + qmlRegisterType("org.cameraPermissionFilter", 1, 0, "CameraFilter"); } QString GraftBaseClient::qrCodeImage() const From d02e5f09cbb9f8b9e5e037be279c4174cd328007 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Wed, 15 Aug 2018 16:23:24 +0300 Subject: [PATCH 04/13] Have been added import for used component --- GraftMobileClient/resources/SendCoinScreen.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/GraftMobileClient/resources/SendCoinScreen.qml b/GraftMobileClient/resources/SendCoinScreen.qml index b232cc16..b24d78ac 100644 --- a/GraftMobileClient/resources/SendCoinScreen.qml +++ b/GraftMobileClient/resources/SendCoinScreen.qml @@ -5,6 +5,7 @@ import QtQuick.Controls 2.2 import com.device.platform 1.0 import org.graft 1.0 import "components" +import "wallet" BaseScreen { id: sendCoinScreen From e09b9a682062bcac3e793ee893a5dd34809d5e90 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Thu, 16 Aug 2018 15:15:34 +0300 Subject: [PATCH 05/13] Have been created permission delegate for iOS on Object C which detect camera permission for check on the scanning screen. --- GraftMobileClient/GraftMobileClient.pro | 2 ++ GraftMobileClient/camerafilter.cpp | 18 ++++++----- GraftMobileClient/camerafilter.h | 4 +-- GraftMobileClient/permissiondelegate.h | 11 +++++++ GraftMobileClient/permissiondelegate.mm | 19 +++++++++++ .../android/wallet/QRScanningView.qml | 10 +++--- .../resources/ios/wallet/QRScanningView.qml | 32 +++++++++++-------- 7 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 GraftMobileClient/permissiondelegate.h create mode 100644 GraftMobileClient/permissiondelegate.mm diff --git a/GraftMobileClient/GraftMobileClient.pro b/GraftMobileClient/GraftMobileClient.pro index b9906000..037c1212 100644 --- a/GraftMobileClient/GraftMobileClient.pro +++ b/GraftMobileClient/GraftMobileClient.pro @@ -21,6 +21,8 @@ TARGET = GraftWallet ios { include(ios/ios.pri) +SOURCES += permissiondelegate.mm +HEADERS += permissiondelegate.h } android { diff --git a/GraftMobileClient/camerafilter.cpp b/GraftMobileClient/camerafilter.cpp index 516039a9..dbd52934 100644 --- a/GraftMobileClient/camerafilter.cpp +++ b/GraftMobileClient/camerafilter.cpp @@ -1,12 +1,8 @@ #include "camerafilter.h" -#include -CameraFilter::CameraFilter(QObject *parent) : QAbstractVideoFilter(parent) -{ - QTimer::singleShot(2000, this, [this]() { - this->hasPermission(false); - }); -} +#ifdef Q_OS_IOS +#include "permissiondelegate.h" +#endif QVideoFilterRunnable *CameraFilter::createFilterRunnable() { @@ -23,6 +19,12 @@ QVideoFrame CameraRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &s Q_UNUSED(surfaceFormat); Q_UNUSED(flags); - emit mFilter->hasPermission(!input->size().isEmpty()); +#ifdef Q_OS_IOS + if (PermissionDelegate::isCameraAuthorised()) + { + emit mFilter->hasPermission(true); + } +#endif + return *input; } diff --git a/GraftMobileClient/camerafilter.h b/GraftMobileClient/camerafilter.h index fe9bb612..fa1ac211 100644 --- a/GraftMobileClient/camerafilter.h +++ b/GraftMobileClient/camerafilter.h @@ -7,7 +7,6 @@ class CameraFilter : public QAbstractVideoFilter { Q_OBJECT public: - CameraFilter(QObject *parent = nullptr); QVideoFilterRunnable *createFilterRunnable() override; signals: @@ -18,8 +17,7 @@ class CameraRunnable : public QVideoFilterRunnable { public: CameraRunnable(CameraFilter *filter); - QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, - RunFlags flags); + QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags); private: CameraFilter *mFilter; diff --git a/GraftMobileClient/permissiondelegate.h b/GraftMobileClient/permissiondelegate.h new file mode 100644 index 00000000..8d4476ca --- /dev/null +++ b/GraftMobileClient/permissiondelegate.h @@ -0,0 +1,11 @@ +#ifndef PERMISSIONDELEGATE_H +#define PERMISSIONDELEGATE_H + +class PermissionDelegate +{ +public: + explicit PermissionDelegate(); + + static bool isCameraAuthorised(); +}; +#endif // PERMISSIONDELEGATE_H diff --git a/GraftMobileClient/permissiondelegate.mm b/GraftMobileClient/permissiondelegate.mm new file mode 100644 index 00000000..d6117826 --- /dev/null +++ b/GraftMobileClient/permissiondelegate.mm @@ -0,0 +1,19 @@ +#include "permissiondelegate.h" + +#include +#include + +PermissionDelegate::PermissionDelegate() +{ +} + +bool PermissionDelegate::isCameraAuthorised() +{ + NSString *mediaType = AVMediaTypeVideo; + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; + if (authStatus == AVAuthorizationStatusAuthorized) + { + return true; + } + return false; +} diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml index 5420b279..717d9ae8 100644 --- a/GraftMobileClient/resources/android/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -19,7 +19,7 @@ Item { Component.onCompleted: { state = camera.cameraStatus === Camera.ActiveStatus || - camera.cameraState === Camera.UnloadedState ? "messageScreen" : "scanScreen" + camera.cameraState === Camera.UnloadedState ? "messagesScreen" : "scanScreen" } Item { @@ -101,7 +101,7 @@ Item { } Item { - id: messageScreen + id: messagesScreen implicitHeight: 110 implicitWidth: parent.width - 60 anchors.centerIn: parent @@ -122,13 +122,13 @@ Item { State { name: "scanScreen" PropertyChanges { target: scanScreen; visible: true } - PropertyChanges { target: messageScreen; visible: false } + PropertyChanges { target: messagesScreen; visible: false } }, State { - name: "messageScreen" + name: "messagesScreen" PropertyChanges { target: scanScreen; visible: false } - PropertyChanges { target: messageScreen; visible: true } + PropertyChanges { target: messagesScreen; visible: true } } ] diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml index 1c6b25a2..8d50b51e 100644 --- a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -8,7 +8,7 @@ import org.cameraPermissionFilter 1.0 Item { property string lastTag: "" - property bool whichState: false + property bool cameraPermissionState: false signal qrCodeDetected(string message) @@ -20,7 +20,7 @@ Item { } } - state: Detector.isDesktop() ? "scanScreen" : "messageScreen" + state: "messagesScreen" Item { id: scanScreen @@ -48,9 +48,7 @@ Item { CameraFilter { id: filter - onHasPermission: { - whichState = result - } + onHasPermission: cameraPermissionState = result } Rectangle { @@ -103,7 +101,7 @@ Item { } Item { - id: messageScreen + id: messagesScreen implicitHeight: 110 implicitWidth: parent.width - 60 anchors.centerIn: parent @@ -116,8 +114,10 @@ Item { verticalAlignment: Label.AlignVCenter font.pixelSize: 16 color: "#A8A8A8" - text: qsTr("You haven't permission for the camera. Please, turn on camera permission " + - "in settings of the application.") + text: camera.deviceId !== '' ? qsTr("You haven't permission for the camera. Please, " + + "turn on camera permission in settings of the application.") : qsTr("The " + + "application can't find camera on this device. To use QR-code scanning option, " + + "please, connect camera to your device.") } } @@ -125,18 +125,24 @@ Item { State { name: "scanScreen" PropertyChanges { target: scanScreen; visible: true } - PropertyChanges { target: messageScreen; visible: false } - when: whichState + PropertyChanges { target: messagesScreen; visible: false } + when: scanning() }, State { - name: "messageScreen" + name: "messagesScreen" PropertyChanges { target: scanScreen; visible: false } - PropertyChanges { target: messageScreen; visible: true } - when: Detector.isMobile() + PropertyChanges { target: messagesScreen; visible: true } } ] + function scanning() { + if (Detector.isDesktop()) { + return camera.deviceId !== '' + } + return cameraPermissionState + } + function resetView() { camera.start() lastTag = "" From f403909f2c6818f118854fba9fb41b310c9cd7fc Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Thu, 16 Aug 2018 15:22:42 +0300 Subject: [PATCH 06/13] Deleted Qr-code scanning viewin general resourses. --- .../resources/QRScanningView.qml | 143 ------------------ 1 file changed, 143 deletions(-) delete mode 100644 GraftMobileClient/resources/QRScanningView.qml diff --git a/GraftMobileClient/resources/QRScanningView.qml b/GraftMobileClient/resources/QRScanningView.qml deleted file mode 100644 index ae0b53bf..00000000 --- a/GraftMobileClient/resources/QRScanningView.qml +++ /dev/null @@ -1,143 +0,0 @@ -import QtQuick 2.9 -import QtMultimedia 5.9 -import QtQuick.Controls 2.2 -import QtGraphicalEffects 1.0 -import QZXing 2.3 -import com.device.platform 1.0 - -Item { - property string lastTag: "" - - signal qrCodeDetected(string message) - - onVisibleChanged: { - if (visible) { - camera.start() - } else { - camera.stop() - } - } - - Component.onCompleted: { - if (Detector.isMobile()) { - state = camera.cameraState === Camera.UnloadedState || - camera.cameraStatus === Camera.ActiveStatus ? "messageScreen" : "scanScreen" - } else { - state = "scanScreen" - } - } - - Item { - id: scanScreen - anchors.fill: parent - - Camera { - id: camera - focus { - focusMode: Camera.FocusContinuous - focusPointMode: Camera.FocusPointCustom - customFocusPoint: Qt.point(0.5, 0.5) // Focus relative to the frame center - } - onCameraStateChanged: { - if (cameraState === Camera.UnloadedState) { - camera.start() - } - } - } - - VideoOutput { - id: videoOutput - anchors.fill: parent - source: camera - autoOrientation: true - focus: visible - fillMode: VideoOutput.PreserveAspectCrop - filters: [ zxingFilter ] - } - - Rectangle { - anchors.fill: parent - id: captureZone - color: "transparent" - - Rectangle { - width: parent.width * 0.75 - height: width - anchors.centerIn: parent - color: "green" - opacity: 0.7 - } - } - - Rectangle { - anchors.fill: parent - color: "black" - opacity: 0.5 - } - - OpacityMask { - anchors.fill: parent - source: videoOutput - maskSource: captureZone - } - - QZXingFilter { - id: zxingFilter - captureRect: { - var rect = Qt.rect(0, 0, 1, 1) - var normalizedRect = videoOutput.mapNormalizedRectToItem(rect) - return videoOutput.mapRectToSource(normalizedRect) - } - - decoder { - enabledDecoders: QZXing.DecoderFormat_QR_CODE - tryHarder: false - onTagFound: { - if (lastTag != tag) { - lastTag = tag - console.log(tag + " | " + " | " + decoder.charSet()) - camera.stop() - qrCodeDetected(tag) - } - } - } - } - } - - Item { - id: messageScreen - implicitHeight: 110 - implicitWidth: parent.width - 60 - anchors.centerIn: parent - - Label { - anchors.fill: parent - wrapMode: Label.WordWrap - horizontalAlignment: Label.AlignHCenter - verticalAlignment: Label.AlignVCenter - font.pixelSize: 16 - color: "#A8A8A8" - text: qsTr("You haven't permission for the camera. Please, turn on camera permission " + - "in settings of the application.") - } - } - - states: [ - State { - name: "scanScreen" - PropertyChanges { target: scanScreen; visible: true } - PropertyChanges { target: messageScreen; visible: false } - }, - - State { - name: "messageScreen" - PropertyChanges { target: scanScreen; visible: false } - PropertyChanges { target: messageScreen; visible: true } - } - ] - - function resetView() { - camera.start() - lastTag = "" - } -} From f7e250171b5e320701454a3ff05f72a22cf8cb08 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Fri, 17 Aug 2018 17:12:15 +0300 Subject: [PATCH 07/13] Have been deleted unusable camera filter and created class which have timer for check camera permission on iOS. --- GraftMobileClient/GraftMobileClient.pro | 8 ++--- GraftMobileClient/core/graftbaseclient.cpp | 5 +-- GraftMobileClient/ios/ios.pri | 8 +++++ .../ios/wallet/ioscamerapermission.cpp | 34 +++++++++++++++++++ .../ios/wallet/ioscamerapermission.h | 23 +++++++++++++ .../{ => ios/wallet}/permissiondelegate.h | 0 .../{ => ios/wallet}/permissiondelegate.mm | 0 GraftMobileClient/main.cpp | 12 +++++++ .../resources/SendCoinScreen.qml | 3 ++ .../android/wallet/QRScanningView.qml | 2 +- .../resources/ios/wallet/BalanceScreen.qml | 2 +- .../resources/ios/wallet/QRScanningView.qml | 28 +++++++-------- .../resources/wallet/QRScanningScreen.qml | 13 +++++++ 13 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 GraftMobileClient/ios/wallet/ioscamerapermission.cpp create mode 100644 GraftMobileClient/ios/wallet/ioscamerapermission.h rename GraftMobileClient/{ => ios/wallet}/permissiondelegate.h (100%) rename GraftMobileClient/{ => ios/wallet}/permissiondelegate.mm (100%) diff --git a/GraftMobileClient/GraftMobileClient.pro b/GraftMobileClient/GraftMobileClient.pro index 037c1212..01885e44 100644 --- a/GraftMobileClient/GraftMobileClient.pro +++ b/GraftMobileClient/GraftMobileClient.pro @@ -21,8 +21,6 @@ TARGET = GraftWallet ios { include(ios/ios.pri) -SOURCES += permissiondelegate.mm -HEADERS += permissiondelegate.h } android { @@ -86,8 +84,7 @@ SOURCES += main.cpp \ core/accountmodelserializator.cpp \ core/accountmanager.cpp \ core/qrcodegenerator.cpp \ - devicedetector.cpp \ - camerafilter.cpp + devicedetector.cpp HEADERS += \ core/config.h \ @@ -112,8 +109,7 @@ HEADERS += \ core/accountmanager.h \ core/graftclienttools.h \ core/qrcodegenerator.h \ - devicedetector.h \ - camerafilter.h + devicedetector.h include(resources/resources.pri) diff --git a/GraftMobileClient/core/graftbaseclient.cpp b/GraftMobileClient/core/graftbaseclient.cpp index df40bc09..3d0b986a 100644 --- a/GraftMobileClient/core/graftbaseclient.cpp +++ b/GraftMobileClient/core/graftbaseclient.cpp @@ -1,4 +1,4 @@ -#include "accountmodelserializator.h" +#include "accountmodelserializator.h" #include "barcodeimageprovider.h" #include "api/graftgenericapi.h" #include "quickexchangemodel.h" @@ -8,7 +8,6 @@ #include "accountmanager.h" #include "currencymodel.h" #include "currencyitem.h" -#include "camerafilter.h" #include "accountmodel.h" #include "config.h" @@ -200,8 +199,6 @@ void GraftBaseClient::registerTypes(QQmlEngine *engine) qmlRegisterUncreatableType("org.graft", 1, 0, "GraftClientTools", "You cannot create an instance of GraftClientTools type."); - - qmlRegisterType("org.cameraPermissionFilter", 1, 0, "CameraFilter"); } QString GraftBaseClient::qrCodeImage() const diff --git a/GraftMobileClient/ios/ios.pri b/GraftMobileClient/ios/ios.pri index 4e2a5ed7..8a3e1ea4 100644 --- a/GraftMobileClient/ios/ios.pri +++ b/GraftMobileClient/ios/ios.pri @@ -20,5 +20,13 @@ contains(DEFINES, WALLET_BUILD) { DISTFILES += \ $$PWD/wallet/Info.plist + + HEADERS += \ + $$PWD/wallet/permissiondelegate.h \ + $$PWD/wallet/ioscamerapermission.h + + SOURCES += \ + $$PWD/wallet/permissiondelegate.mm \ + $$PWD/wallet/ioscamerapermission.cpp } diff --git a/GraftMobileClient/ios/wallet/ioscamerapermission.cpp b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp new file mode 100644 index 00000000..d10c14a8 --- /dev/null +++ b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp @@ -0,0 +1,34 @@ +#include "ioscamerapermission.h" + +#include + +#include "permissiondelegate.h" + +IOSCameraPermission::IOSCameraPermission(QObject *parent) + : QObject(parent) + ,mTimer(-1) +{ +} + +bool IOSCameraPermission::hasPermission() +{ + mTimer = startTimer(50); + return PermissionDelegate::isCameraAuthorised(); +} + +void IOSCameraPermission::stopTimer() +{ + killTimer(mTimer); +} + +void IOSCameraPermission::timerEvent(QTimerEvent *event) +{ + if (event->timerId() == mTimer) + { + if (PermissionDelegate::isCameraAuthorised()) + { + emit hasCameraPermission(true); + } + } +} + diff --git a/GraftMobileClient/ios/wallet/ioscamerapermission.h b/GraftMobileClient/ios/wallet/ioscamerapermission.h new file mode 100644 index 00000000..efb3460c --- /dev/null +++ b/GraftMobileClient/ios/wallet/ioscamerapermission.h @@ -0,0 +1,23 @@ +#ifndef IOSCAMERAPERMISSION_H +#define IOSCAMERAPERMISSION_H + +#include + +class IOSCameraPermission : public QObject +{ + Q_OBJECT +public: + explicit IOSCameraPermission(QObject *parent = nullptr); + + Q_INVOKABLE bool hasPermission(); + Q_INVOKABLE void stopTimer(); + +signals: + void hasCameraPermission(bool result); + +private: + void timerEvent(QTimerEvent *event) override; + int mTimer; +}; + +#endif // IOSCAMERAPERMISSION_H diff --git a/GraftMobileClient/permissiondelegate.h b/GraftMobileClient/ios/wallet/permissiondelegate.h similarity index 100% rename from GraftMobileClient/permissiondelegate.h rename to GraftMobileClient/ios/wallet/permissiondelegate.h diff --git a/GraftMobileClient/permissiondelegate.mm b/GraftMobileClient/ios/wallet/permissiondelegate.mm similarity index 100% rename from GraftMobileClient/permissiondelegate.mm rename to GraftMobileClient/ios/wallet/permissiondelegate.mm diff --git a/GraftMobileClient/main.cpp b/GraftMobileClient/main.cpp index d747f954..537f7e38 100644 --- a/GraftMobileClient/main.cpp +++ b/GraftMobileClient/main.cpp @@ -41,6 +41,12 @@ static_assert(false, "QTBUG-65820 in Android Debug builds"); #include #endif +#ifdef WALLET_BUILD +#if defined(Q_OS_IOS) +#include "ios/wallet/ioscamerapermission.h" +#endif +#endif + #ifdef POS_BUILD #if defined(Q_OS_ANDROID) || defined (Q_OS_IOS) #include "imagepicker.h" @@ -109,6 +115,12 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty(QStringLiteral("PaymentProductModel"), client.paymentProductModel()); engine.rootContext()->setContextProperty(QStringLiteral("GraftClient"), &client); + +#if defined(Q_OS_IOS) + IOSCameraPermission cameraPermission; + engine.rootContext()->setContextProperty(QStringLiteral("IOSCameraPermission"), &cameraPermission); +#endif + engine.load(QUrl(QLatin1String("qrc:/wallet/main.qml"))); #endif if (engine.rootObjects().isEmpty()) diff --git a/GraftMobileClient/resources/SendCoinScreen.qml b/GraftMobileClient/resources/SendCoinScreen.qml index b24d78ac..63f31b92 100644 --- a/GraftMobileClient/resources/SendCoinScreen.qml +++ b/GraftMobileClient/resources/SendCoinScreen.qml @@ -142,6 +142,9 @@ BaseScreen { function changeBehaviorButton() { stackLayout.currentIndex = 0 + if (Detector.isPlatform(Platform.IOS)) { + IOSCameraPermission.stopTimer() + } } function checkingData() { diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml index 717d9ae8..6bcd7b1f 100644 --- a/GraftMobileClient/resources/android/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -89,7 +89,7 @@ Item { enabledDecoders: QZXing.DecoderFormat_QR_CODE tryHarder: false onTagFound: { - if (lastTag != tag) { + if (lastTag !== tag) { lastTag = tag console.log(tag + " | " + " | " + decoder.charSet()) camera.stop() diff --git a/GraftMobileClient/resources/ios/wallet/BalanceScreen.qml b/GraftMobileClient/resources/ios/wallet/BalanceScreen.qml index a65a9e51..ead3bf1a 100644 --- a/GraftMobileClient/resources/ios/wallet/BalanceScreen.qml +++ b/GraftMobileClient/resources/ios/wallet/BalanceScreen.qml @@ -1,8 +1,8 @@ import QtQuick 2.9 import QtQuick.Layouts 1.3 +import org.graft 1.0 import "../" import "../components" -import org.graft 1.0 BaseBalanceScreen { diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml index 8d50b51e..5d16d5bd 100644 --- a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -4,11 +4,9 @@ import QtQuick.Controls 2.2 import QtGraphicalEffects 1.0 import QZXing 2.3 import com.device.platform 1.0 -import org.cameraPermissionFilter 1.0 Item { property string lastTag: "" - property bool cameraPermissionState: false signal qrCodeDetected(string message) @@ -20,6 +18,11 @@ Item { } } + Connections { + target: IOSCameraPermission + onHasCameraPermission: state = "scanScreen" + } + state: "messagesScreen" Item { @@ -43,12 +46,7 @@ Item { autoOrientation: true focus: visible fillMode: VideoOutput.PreserveAspectCrop - filters: [ filter, zxingFilter ] - } - - CameraFilter { - id: filter - onHasPermission: cameraPermissionState = result + filters: [ zxingFilter ] } Rectangle { @@ -89,7 +87,7 @@ Item { enabledDecoders: QZXing.DecoderFormat_QR_CODE tryHarder: false onTagFound: { - if (lastTag != tag) { + if (lastTag !== tag) { lastTag = tag console.log(tag + " | " + " | " + decoder.charSet()) camera.stop() @@ -114,10 +112,10 @@ Item { verticalAlignment: Label.AlignVCenter font.pixelSize: 16 color: "#A8A8A8" - text: camera.deviceId !== '' ? qsTr("You haven't permission for the camera. Please, " + - "turn on camera permission in settings of the application.") : qsTr("The " + - "application can't find camera on this device. To use QR-code scanning option, " + - "please, connect camera to your device.") + text: QtMultimedia.availableCameras.length > 0 ? qsTr("You haven't permission " + + "for the camera. Please, turn on camera permission in settings of the " + + "application.") : qsTr("The application can't find camera on this device. To " + + "use QR-code scanning option, please, connect camera to your device.") } } @@ -138,9 +136,9 @@ Item { function scanning() { if (Detector.isDesktop()) { - return camera.deviceId !== '' + return QtMultimedia.availableCameras.length > 0 } - return cameraPermissionState + return IOSCameraPermission.hasPermission() } function resetView() { diff --git a/GraftMobileClient/resources/wallet/QRScanningScreen.qml b/GraftMobileClient/resources/wallet/QRScanningScreen.qml index 835b0c09..a7165905 100644 --- a/GraftMobileClient/resources/wallet/QRScanningScreen.qml +++ b/GraftMobileClient/resources/wallet/QRScanningScreen.qml @@ -1,5 +1,6 @@ import QtQuick 2.9 import QtQuick.Dialogs 1.2 +import com.device.platform 1.0 import "../components" import "../" @@ -7,6 +8,12 @@ BaseScreen { id: qrScanning title: qsTr("Pay") + Component.onCompleted: { + if (Detector.isPlatform(Platform.IOS)) { + qrScanning.specialBackMode = pop + } + } + Connections { target: GraftClient @@ -20,6 +27,7 @@ BaseScreen { } } + Connections { target: qrScanning onAttentionAccepted: qRScanningView.resetView() @@ -30,4 +38,9 @@ BaseScreen { anchors.fill: parent onQrCodeDetected: GraftClient.getPOSData(message) } + + function pop() { + IOSCameraPermission.stopTimer() + goBack() + } } From 084aa26a0d32a2336e4471c4bb6d62406e5e92fa Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Fri, 17 Aug 2018 17:26:38 +0300 Subject: [PATCH 08/13] Deleted unusable clas and also fixed connect signal on desktop on scanning view. --- GraftMobileClient/camerafilter.cpp | 30 ------------------- GraftMobileClient/camerafilter.h | 26 ---------------- .../resources/ios/wallet/QRScanningView.qml | 2 +- 3 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 GraftMobileClient/camerafilter.cpp delete mode 100644 GraftMobileClient/camerafilter.h diff --git a/GraftMobileClient/camerafilter.cpp b/GraftMobileClient/camerafilter.cpp deleted file mode 100644 index dbd52934..00000000 --- a/GraftMobileClient/camerafilter.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "camerafilter.h" - -#ifdef Q_OS_IOS -#include "permissiondelegate.h" -#endif - -QVideoFilterRunnable *CameraFilter::createFilterRunnable() -{ - return new CameraRunnable(this); -} - -CameraRunnable::CameraRunnable(CameraFilter *filter) : mFilter(filter) -{ -} - -QVideoFrame CameraRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, - QVideoFilterRunnable::RunFlags flags) -{ - Q_UNUSED(surfaceFormat); - Q_UNUSED(flags); - -#ifdef Q_OS_IOS - if (PermissionDelegate::isCameraAuthorised()) - { - emit mFilter->hasPermission(true); - } -#endif - - return *input; -} diff --git a/GraftMobileClient/camerafilter.h b/GraftMobileClient/camerafilter.h deleted file mode 100644 index fa1ac211..00000000 --- a/GraftMobileClient/camerafilter.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CAMERAFILTER_H -#define CAMERAFILTER_H - -#include - -class CameraFilter : public QAbstractVideoFilter -{ - Q_OBJECT -public: - QVideoFilterRunnable *createFilterRunnable() override; - -signals: - void hasPermission(bool result); -}; - -class CameraRunnable : public QVideoFilterRunnable -{ -public: - CameraRunnable(CameraFilter *filter); - QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags); - -private: - CameraFilter *mFilter; -}; - -#endif // CAMERAFILTER_H diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml index 5d16d5bd..34adc055 100644 --- a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -19,7 +19,7 @@ Item { } Connections { - target: IOSCameraPermission + target: Detector.isPlatform(Platform.Desktop) ? null : IOSCameraPermission onHasCameraPermission: state = "scanScreen" } From d7bfd336309883c567b93f93ef7cc2f73e8ee74a Mon Sep 17 00:00:00 2001 From: Tetiana Gissovska Date: Fri, 17 Aug 2018 21:01:12 +0300 Subject: [PATCH 09/13] Update graftbaseclient.cpp --- GraftMobileClient/core/graftbaseclient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GraftMobileClient/core/graftbaseclient.cpp b/GraftMobileClient/core/graftbaseclient.cpp index 3d0b986a..edc590d5 100644 --- a/GraftMobileClient/core/graftbaseclient.cpp +++ b/GraftMobileClient/core/graftbaseclient.cpp @@ -1,4 +1,4 @@ -#include "accountmodelserializator.h" +#include "accountmodelserializator.h" #include "barcodeimageprovider.h" #include "api/graftgenericapi.h" #include "quickexchangemodel.h" From 7c4d44787f231b2148e780d242c37ea1761ef021 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Fri, 17 Aug 2018 21:48:04 +0300 Subject: [PATCH 10/13] Have been fixed iOS and MacOS show scnning screen for pay and send. --- .../ios/wallet/ioscamerapermission.cpp | 18 ++++++------- .../ios/wallet/ioscamerapermission.h | 4 ++- .../ios/wallet/permissiondelegate.h | 2 -- .../ios/wallet/permissiondelegate.mm | 10 +------- .../android/wallet/QRScanningView.qml | 25 ++++++++++++++++--- .../resources/ios/wallet/QRScanningView.qml | 4 +++ .../resources/wallet/QRScanningScreen.qml | 13 +++++----- 7 files changed, 45 insertions(+), 31 deletions(-) diff --git a/GraftMobileClient/ios/wallet/ioscamerapermission.cpp b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp index d10c14a8..75c28d29 100644 --- a/GraftMobileClient/ios/wallet/ioscamerapermission.cpp +++ b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp @@ -1,9 +1,8 @@ #include "ioscamerapermission.h" +#include "permissiondelegate.h" #include -#include "permissiondelegate.h" - IOSCameraPermission::IOSCameraPermission(QObject *parent) : QObject(parent) ,mTimer(-1) @@ -12,8 +11,12 @@ IOSCameraPermission::IOSCameraPermission(QObject *parent) bool IOSCameraPermission::hasPermission() { - mTimer = startTimer(50); - return PermissionDelegate::isCameraAuthorised(); + if (!PermissionDelegate::isCameraAuthorised()) + { + mTimer = startTimer(50); + return false; + } + return true; } void IOSCameraPermission::stopTimer() @@ -23,12 +26,9 @@ void IOSCameraPermission::stopTimer() void IOSCameraPermission::timerEvent(QTimerEvent *event) { - if (event->timerId() == mTimer) + if ((event->timerId() == mTimer) && PermissionDelegate::isCameraAuthorised()) { - if (PermissionDelegate::isCameraAuthorised()) - { - emit hasCameraPermission(true); - } + emit hasCameraPermission(true); } } diff --git a/GraftMobileClient/ios/wallet/ioscamerapermission.h b/GraftMobileClient/ios/wallet/ioscamerapermission.h index efb3460c..8297ff0f 100644 --- a/GraftMobileClient/ios/wallet/ioscamerapermission.h +++ b/GraftMobileClient/ios/wallet/ioscamerapermission.h @@ -15,8 +15,10 @@ class IOSCameraPermission : public QObject signals: void hasCameraPermission(bool result); -private: +protected: void timerEvent(QTimerEvent *event) override; + +private: int mTimer; }; diff --git a/GraftMobileClient/ios/wallet/permissiondelegate.h b/GraftMobileClient/ios/wallet/permissiondelegate.h index 8d4476ca..9a8d7a50 100644 --- a/GraftMobileClient/ios/wallet/permissiondelegate.h +++ b/GraftMobileClient/ios/wallet/permissiondelegate.h @@ -4,8 +4,6 @@ class PermissionDelegate { public: - explicit PermissionDelegate(); - static bool isCameraAuthorised(); }; #endif // PERMISSIONDELEGATE_H diff --git a/GraftMobileClient/ios/wallet/permissiondelegate.mm b/GraftMobileClient/ios/wallet/permissiondelegate.mm index d6117826..1c7fffac 100644 --- a/GraftMobileClient/ios/wallet/permissiondelegate.mm +++ b/GraftMobileClient/ios/wallet/permissiondelegate.mm @@ -3,17 +3,9 @@ #include #include -PermissionDelegate::PermissionDelegate() -{ -} - bool PermissionDelegate::isCameraAuthorised() { NSString *mediaType = AVMediaTypeVideo; AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; - if (authStatus == AVAuthorizationStatusAuthorized) - { - return true; - } - return false; + return authStatus == AVAuthorizationStatusAuthorized; } diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml index 6bcd7b1f..68a22718 100644 --- a/GraftMobileClient/resources/android/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -17,10 +17,10 @@ Item { } } - Component.onCompleted: { - state = camera.cameraStatus === Camera.ActiveStatus || - camera.cameraState === Camera.UnloadedState ? "messagesScreen" : "scanScreen" - } +// Component.onCompleted: { +// state = camera.cameraStatus === Camera.ActiveStatus || +// camera.cameraState === Camera.UnloadedState ? "messagesScreen" : "scanScreen" +// } Item { id: scanScreen @@ -118,20 +118,37 @@ Item { } } + state: "messagesScreen" + states: [ State { name: "scanScreen" PropertyChanges { target: scanScreen; visible: true } PropertyChanges { target: messagesScreen; visible: false } +// when: scanning() }, State { name: "messagesScreen" PropertyChanges { target: scanScreen; visible: false } PropertyChanges { target: messagesScreen; visible: true } + when: scanning() } ] + function scanning() { +// console.log(camera.cameraStatus === Camera.ActiveStatus || +// camera.cameraState === Camera.UnloadedState, "<--") + + if (camera.cameraStatus === Camera.ActiveStatus || camera.cameraState === Camera.UnloadedState) { + return true + } + return false + +// return camera.cameraStatus === Camera.ActiveStatus || +// camera.cameraState === Camera.UnloadedState ? false : true + } + function resetView() { camera.start() lastTag = "" diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml index 34adc055..01927996 100644 --- a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -141,6 +141,10 @@ Item { return IOSCameraPermission.hasPermission() } + function stopScanningView() { + IOSCameraPermission.stopTimer() + } + function resetView() { camera.start() lastTag = "" diff --git a/GraftMobileClient/resources/wallet/QRScanningScreen.qml b/GraftMobileClient/resources/wallet/QRScanningScreen.qml index a7165905..be5a8fd2 100644 --- a/GraftMobileClient/resources/wallet/QRScanningScreen.qml +++ b/GraftMobileClient/resources/wallet/QRScanningScreen.qml @@ -8,11 +8,12 @@ BaseScreen { id: qrScanning title: qsTr("Pay") - Component.onCompleted: { - if (Detector.isPlatform(Platform.IOS)) { - qrScanning.specialBackMode = pop - } - } + specialBackMode: Detector.isPlatform(Platform.IOS) ? pop : null +// Component.onCompleted: { +// if (Detector.isPlatform(Platform.IOS)) { +// qrScanning.specialBackMode = pop +// } +// } Connections { target: GraftClient @@ -40,7 +41,7 @@ BaseScreen { } function pop() { - IOSCameraPermission.stopTimer() + qRScanningView.stopScanningView() goBack() } } From 04d4288808b1fc8393f33b4334b17810e82090b3 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Sat, 18 Aug 2018 02:19:42 +0300 Subject: [PATCH 11/13] Have been simpling object C call for camera permission [iOS], refactoring change states [Android], and fixed call stopped timer. --- .../ios/wallet/permissiondelegate.mm | 3 +-- .../resources/SendCoinScreen.qml | 5 ++--- .../android/wallet/QRScanningView.qml | 20 ++----------------- .../resources/ios/wallet/QRScanningView.qml | 3 +-- .../resources/wallet/QRScanningScreen.qml | 8 +------- 5 files changed, 7 insertions(+), 32 deletions(-) diff --git a/GraftMobileClient/ios/wallet/permissiondelegate.mm b/GraftMobileClient/ios/wallet/permissiondelegate.mm index 1c7fffac..d6f88ccb 100644 --- a/GraftMobileClient/ios/wallet/permissiondelegate.mm +++ b/GraftMobileClient/ios/wallet/permissiondelegate.mm @@ -6,6 +6,5 @@ bool PermissionDelegate::isCameraAuthorised() { NSString *mediaType = AVMediaTypeVideo; - AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; - return authStatus == AVAuthorizationStatusAuthorized; + return [AVCaptureDevice authorizationStatusForMediaType:mediaType] == AVAuthorizationStatusAuthorized; } diff --git a/GraftMobileClient/resources/SendCoinScreen.qml b/GraftMobileClient/resources/SendCoinScreen.qml index 63f31b92..c986cdda 100644 --- a/GraftMobileClient/resources/SendCoinScreen.qml +++ b/GraftMobileClient/resources/SendCoinScreen.qml @@ -127,6 +127,7 @@ BaseScreen { } QRScanningView { + id: qRScanningView onQrCodeDetected: { receiversAddress.text = message changeBehaviorButton() @@ -142,9 +143,7 @@ BaseScreen { function changeBehaviorButton() { stackLayout.currentIndex = 0 - if (Detector.isPlatform(Platform.IOS)) { - IOSCameraPermission.stopTimer() - } + qRScanningView.stopScanningView() } function checkingData() { diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml index 68a22718..c124d66a 100644 --- a/GraftMobileClient/resources/android/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -9,6 +9,7 @@ Item { signal qrCodeDetected(string message) + state: "scanScreen" onVisibleChanged: { if (visible) { camera.start() @@ -17,11 +18,6 @@ Item { } } -// Component.onCompleted: { -// state = camera.cameraStatus === Camera.ActiveStatus || -// camera.cameraState === Camera.UnloadedState ? "messagesScreen" : "scanScreen" -// } - Item { id: scanScreen anchors.fill: parent @@ -118,14 +114,11 @@ Item { } } - state: "messagesScreen" - states: [ State { name: "scanScreen" PropertyChanges { target: scanScreen; visible: true } PropertyChanges { target: messagesScreen; visible: false } -// when: scanning() }, State { @@ -137,16 +130,7 @@ Item { ] function scanning() { -// console.log(camera.cameraStatus === Camera.ActiveStatus || -// camera.cameraState === Camera.UnloadedState, "<--") - - if (camera.cameraStatus === Camera.ActiveStatus || camera.cameraState === Camera.UnloadedState) { - return true - } - return false - -// return camera.cameraStatus === Camera.ActiveStatus || -// camera.cameraState === Camera.UnloadedState ? false : true + return ((camera.cameraStatus === Camera.ActiveStatus) || (camera.cameraState === Camera.UnloadedState)) } function resetView() { diff --git a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml index 01927996..1c7ca405 100644 --- a/GraftMobileClient/resources/ios/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/ios/wallet/QRScanningView.qml @@ -10,6 +10,7 @@ Item { signal qrCodeDetected(string message) + state: "messagesScreen" onVisibleChanged: { if (visible) { camera.start() @@ -23,8 +24,6 @@ Item { onHasCameraPermission: state = "scanScreen" } - state: "messagesScreen" - Item { id: scanScreen anchors.fill: parent diff --git a/GraftMobileClient/resources/wallet/QRScanningScreen.qml b/GraftMobileClient/resources/wallet/QRScanningScreen.qml index be5a8fd2..4147ccd9 100644 --- a/GraftMobileClient/resources/wallet/QRScanningScreen.qml +++ b/GraftMobileClient/resources/wallet/QRScanningScreen.qml @@ -8,12 +8,7 @@ BaseScreen { id: qrScanning title: qsTr("Pay") - specialBackMode: Detector.isPlatform(Platform.IOS) ? pop : null -// Component.onCompleted: { -// if (Detector.isPlatform(Platform.IOS)) { -// qrScanning.specialBackMode = pop -// } -// } + specialBackMode: Detector.isPlatform(Platform.IOS) ? pop : goBack Connections { target: GraftClient @@ -28,7 +23,6 @@ BaseScreen { } } - Connections { target: qrScanning onAttentionAccepted: qRScanningView.resetView() From 4c1a034b07df0b23d56a21e07ee3e1279904e2a1 Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Mon, 20 Aug 2018 02:07:22 +0300 Subject: [PATCH 12/13] Have been fixed condition for show scanning or message screen on Android. --- .../resources/android/wallet/QRScanningView.qml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/GraftMobileClient/resources/android/wallet/QRScanningView.qml b/GraftMobileClient/resources/android/wallet/QRScanningView.qml index c124d66a..be4b5e6b 100644 --- a/GraftMobileClient/resources/android/wallet/QRScanningView.qml +++ b/GraftMobileClient/resources/android/wallet/QRScanningView.qml @@ -125,14 +125,10 @@ Item { name: "messagesScreen" PropertyChanges { target: scanScreen; visible: false } PropertyChanges { target: messagesScreen; visible: true } - when: scanning() + when: camera.cameraStatus === 0 && camera.cameraState === 0 } ] - function scanning() { - return ((camera.cameraStatus === Camera.ActiveStatus) || (camera.cameraState === Camera.UnloadedState)) - } - function resetView() { camera.start() lastTag = "" From 257c4b0dbebaf0ca5172541426a1571472c2ccdc Mon Sep 17 00:00:00 2001 From: "tetiana.gissovska" Date: Wed, 5 Sep 2018 10:07:12 +0300 Subject: [PATCH 13/13] Have been added call method which kills timer, when the user permission granted. --- GraftMobileClient/ios/wallet/ioscamerapermission.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/GraftMobileClient/ios/wallet/ioscamerapermission.cpp b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp index 75c28d29..f3d98a98 100644 --- a/GraftMobileClient/ios/wallet/ioscamerapermission.cpp +++ b/GraftMobileClient/ios/wallet/ioscamerapermission.cpp @@ -29,6 +29,7 @@ void IOSCameraPermission::timerEvent(QTimerEvent *event) if ((event->timerId() == mTimer) && PermissionDelegate::isCameraAuthorised()) { emit hasCameraPermission(true); + stopTimer(); } }