From c49f54007868b5546248f2b1fe31537519858699 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Thu, 30 Nov 2023 12:32:09 +0100 Subject: [PATCH 1/2] Request location permission in context --- app/qml/main.qml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/app/qml/main.qml b/app/qml/main.qml index 6b3f43444..2d38c9185 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -233,6 +233,25 @@ ApplicationWindow { } } + LocationPermission { + id: locationPermission + accuracy: LocationPermission.Precise + + function requestPermissionAsync() { + if ( locationPermission.status === Qt.Granted ) { + return true; + } + else if ( locationPermission.status === Qt.Undetermined ) { + locationPermission.request() + } + else if ( locationPermission.status === Qt.Denied ) { + __inputUtils.log("Permissions", "Location permission is denied") + showMessage( qsTr( "Location permission is required to show your location on map. Please enable it in system settings." ) ); + } + return false; + } + } + MainPanel { id: mainPanel @@ -250,11 +269,17 @@ ApplicationWindow { mapThemesPanel.visible = true stateManager.state = "misc" } - onMyLocationClicked: map.centerToPosition() + onMyLocationClicked: { + if ( locationPermission.requestPermissionAsync() ) { + map.centerToPosition() + } + } onMyLocationHold: { + if ( locationPermission.requestPermissionAsync() ) { __appSettings.autoCenterMapChecked = !__appSettings.autoCenterMapChecked showMessage( __appSettings.autoCenterMapChecked ? qsTr("GPS auto-center mode on") : qsTr("GPS auto-center mode off") ) + } } onOpenSettingsClicked: settingsPanel.visible = true onZoomToProject: { @@ -809,6 +834,14 @@ ApplicationWindow { function onLoadingFinished() { projectLoadingScreen.visible = false + + // check location permission + if ( locationPermission.status === Qt.Undetermined ) { + locationPermission.request(); + } + else if ( locationPermission.status === Qt.Denied ) { + __inputUtils.log("Permissions", "Location permission is denied") + } } function onLoadingErrorFound() { From 057ce52c179640114ef7a111d384279495233046 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Thu, 30 Nov 2023 12:32:31 +0100 Subject: [PATCH 2/2] Request bluetooth permission in context --- .../providers/bluetoothpositionprovider.cpp | 17 ++++++- app/qml/misc/AddPositionProviderPage.qml | 45 ++++++++++++++----- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app/position/providers/bluetoothpositionprovider.cpp b/app/position/providers/bluetoothpositionprovider.cpp index a11150433..5162dc904 100644 --- a/app/position/providers/bluetoothpositionprovider.cpp +++ b/app/position/providers/bluetoothpositionprovider.cpp @@ -11,6 +11,7 @@ #include "coreutils.h" #include "androidutils.h" #include "inpututils.h" +#include NmeaParser::NmeaParser() : QgsNmeaConnection( new QBluetoothSocket() ) { @@ -134,8 +135,22 @@ void BluetoothPositionProvider::startReconnectionTime() void BluetoothPositionProvider::handleLostConnection() { // we want to reconnect, but only to devices that are paired + QBluetoothPermission btPermission; + Qt::PermissionStatus permissionStatus; - if ( mReceiverDevice->pairingStatus( mTargetAddress ) == QBluetoothLocalDevice::Unpaired ) + if ( qApp && ( permissionStatus = qApp->checkPermission( btPermission ) ) != Qt::PermissionStatus::Granted ) + { + if ( permissionStatus == Qt::PermissionStatus::Undetermined ) + { + qApp->requestPermission( btPermission, []() {} ); + startReconnectionTime(); + } + else + { + setState( tr( "Bluetooth permission disabled" ), State::NoConnection ); // permanent error + } + } + else if ( mReceiverDevice->pairingStatus( mTargetAddress ) == QBluetoothLocalDevice::Unpaired ) { setState( tr( "Could not connect to device, not paired" ), State::NoConnection ); } diff --git a/app/qml/misc/AddPositionProviderPage.qml b/app/qml/misc/AddPositionProviderPage.qml index bc7fc2df3..3419e5f0a 100644 --- a/app/qml/misc/AddPositionProviderPage.qml +++ b/app/qml/misc/AddPositionProviderPage.qml @@ -7,6 +7,7 @@ * * ***************************************************************************/ +import QtCore import QtQuick import QtQuick.Controls import Qt5Compat.GraphicalEffects @@ -39,6 +40,14 @@ Page { withBackButton: true } + BluetoothPermission { + id: btPermission + + communicationModes: BluetoothPermission.Access + + onStatusChanged: btModel.initiateBtDiscovery() + } + focus: true Keys.onReleased: function( event ) { @@ -57,21 +66,35 @@ Page { model: BluetoothDiscoveryModel { id: btModel discovering: false - } - Component.onCompleted: { - // Is bluetooth turned on? - // For Android we need to opt to enable Bluetooth and listen on response in the connections component. - if ( __inputUtils.isBluetoothTurnedOn() ) - { - btModel.discovering = true - } - else - { - __inputUtils.turnBluetoothOn() + function initiateBtDiscovery() { + // Is bluetooth permission granted and is bluetooth turned on? + // For Android we need to opt to enable Bluetooth and listen on response in the connections component. + + if ( btPermission.status === Qt.Granted ) + { + if ( __inputUtils.isBluetoothTurnedOn() ) + { + btModel.discovering = true + } + else + { + __inputUtils.turnBluetoothOn() + } + } + else if ( btPermission.status === Qt.Denied ) + { + __inputUtils.showNotification( qsTr( "Bluetooth permission is required in order to connect to external receivers. Please enable it in system settings" ) ) + } + else + { + btPermission.request() + } } } + Component.onCompleted: btModel.initiateBtDiscovery() + Connections { target: __androidUtils