1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

Qt: ask for camera permissions

This commit is contained in:
Megamouse 2023-11-04 22:14:03 +01:00
parent 4a4762654b
commit 3420cb0365
2 changed files with 50 additions and 0 deletions

View File

@ -8,6 +8,10 @@
#include <QMessageBox>
#include <QPushButton>
#if QT_CONFIG(permissions)
#include <QPermissions>
#endif
LOG_CHANNEL(camera_log, "Camera");
template <>
@ -226,6 +230,27 @@ void camera_settings_dialog::handle_settings_change(int index)
return;
}
#if QT_CONFIG(permissions)
QCameraPermission permission;
switch (qApp->checkPermission(permission))
{
case Qt::PermissionStatus::Undetermined:
camera_log.notice("Requesting camera permission");
qApp->requestPermission(permission, this, [this, index]()
{
handle_settings_change(index);
});
return;
case Qt::PermissionStatus::Denied:
camera_log.error("RPCS3 has no permissions to access cameras on this device.");
QMessageBox::warning(this, tr("Camera permissions denied!"), tr("RPCS3 has no permissions to access cameras on this device."));
return;
case Qt::PermissionStatus::Granted:
camera_log.notice("Camera permission granted");
break;
}
#endif
if (index >= 0 && ui->combo_settings->itemData(index).canConvert<QCameraFormat>() && ui->combo_camera->currentData().canConvert<QCameraDevice>())
{
const QCameraFormat setting = ui->combo_settings->itemData(index).value<QCameraFormat>();

View File

@ -6,6 +6,11 @@
#include <QMediaDevices>
#if QT_CONFIG(permissions)
#include <QGuiApplication>
#include <QPermissions>
#endif
LOG_CHANNEL(camera_log, "Camera");
qt_camera_handler::qt_camera_handler() : camera_handler_base()
@ -180,6 +185,26 @@ void qt_camera_handler::start_camera()
return;
}
#if QT_CONFIG(permissions)
QCameraPermission permission;
switch (qApp->checkPermission(permission))
{
case Qt::PermissionStatus::Undetermined:
camera_log.notice("Requesting camera permission");
qApp->requestPermission(permission, [this]()
{
start_camera();
});
return;
case Qt::PermissionStatus::Denied:
camera_log.error("RPCS3 has no permissions to access cameras on this device.");
return;
case Qt::PermissionStatus::Granted:
camera_log.notice("Camera permission granted");
break;
}
#endif
// Start camera. We will start receiving frames now.
m_camera->start();
}