diff --git a/contrib/depends/packages/qt.mk b/contrib/depends/packages/qt.mk index 9dfbe47..7de62ca 100644 --- a/contrib/depends/packages/qt.mk +++ b/contrib/depends/packages/qt.mk @@ -68,6 +68,7 @@ $(package)_config_opts += -DINPUT_libudev=no $(package)_config_opts += -DINPUT_mtdev=no $(package)_config_opts += -DINPUT_openssl=linked $(package)_config_opts += -DINPUT_openvg=no +$(package)_config_opts += -DINPUT_permissions=yes $(package)_config_opts += -DINPUT_reduce_relocations=no $(package)_config_opts += -DINPUT_schannel=no $(package)_config_opts += -DINPUT_sctp=no diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca16460..2d2b3f1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -299,6 +299,10 @@ if (WITH_SCANNER) ) endif() +if(STATIC AND APPLE) + target_link_libraries(feather Qt6::QDarwinCameraPermissionPlugin) +endif() + if(STATIC AND UNIX AND NOT APPLE) target_link_libraries(feather Qt6::QComposePlatformInputContextPlugin) endif() diff --git a/src/main.cpp b/src/main.cpp index d0a1a38..5f45f40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,10 @@ Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin) // Needed for dead keys on Linux #endif +#if defined(Q_OS_MAC) && defined(STATIC) +Q_IMPORT_PLUGIN(QDarwinCameraPermissionPlugin) +#endif + #if defined(Q_OS_LINUX) && defined(STACK_TRACE) void signal_handler(int signum) { ::signal(signum, SIG_DFL); diff --git a/src/qrcode/scanner/QrCodeScanWidget.cpp b/src/qrcode/scanner/QrCodeScanWidget.cpp index 802944d..b1dfc35 100644 --- a/src/qrcode/scanner/QrCodeScanWidget.cpp +++ b/src/qrcode/scanner/QrCodeScanWidget.cpp @@ -4,6 +4,7 @@ #include "QrCodeScanWidget.h" #include "ui_QrCodeScanWidget.h" +#include #include #include @@ -68,7 +69,13 @@ void QrCodeScanWidget::startCapture(bool scan_ur) { m_scan_ur = scan_ur; ui->progressBar_UR->setVisible(m_scan_ur); ui->progressBar_UR->setFormat("Progress: %v%"); - + + if (!getPermission()) { + ui->frame_error->setText("No permission to start camera."); + ui->frame_error->show(); + return; + } + if (ui->combo_camera->count() < 1) { ui->frame_error->setText("No cameras found. Attach a camera and press 'Refresh'."); ui->frame_error->show(); @@ -82,6 +89,20 @@ void QrCodeScanWidget::startCapture(bool scan_ur) { } } +bool QrCodeScanWidget::getPermission() { + QCameraPermission cameraPermission; + switch (qApp->checkPermission(cameraPermission)) { + case Qt::PermissionStatus::Undetermined: + qApp->requestPermission(cameraPermission, this, + &QrCodeScanWidget::getPermission); + return false; + case Qt::PermissionStatus::Denied: + return false; + case Qt::PermissionStatus::Granted: + return true; + } +} + void QrCodeScanWidget::reset() { this->decodedString = ""; m_done = false; diff --git a/src/qrcode/scanner/QrCodeScanWidget.h b/src/qrcode/scanner/QrCodeScanWidget.h index 700c316..8cefd08 100644 --- a/src/qrcode/scanner/QrCodeScanWidget.h +++ b/src/qrcode/scanner/QrCodeScanWidget.h @@ -49,6 +49,7 @@ private: void refreshCameraList(); QImage videoFrameToImage(const QVideoFrame &videoFrame); void handleFrameCaptured(const QVideoFrame &videoFrame); + bool getPermission(); QScopedPointer ui;