window-permissions.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <QLabel>
  15. #include "moc_window-permissions.cpp"
  16. #include "obs-app.hpp"
  17. OBSPermissions::OBSPermissions(QWidget *parent, MacPermissionStatus capture,
  18. MacPermissionStatus video,
  19. MacPermissionStatus audio,
  20. MacPermissionStatus accessibility)
  21. : QDialog(parent),
  22. ui(new Ui::OBSPermissions)
  23. {
  24. ui->setupUi(this);
  25. SetStatus(ui->capturePermissionButton, capture,
  26. QTStr("MacPermissions.Item.ScreenRecording"));
  27. SetStatus(ui->videoPermissionButton, video,
  28. QTStr("MacPermissions.Item.Camera"));
  29. SetStatus(ui->audioPermissionButton, audio,
  30. QTStr("MacPermissions.Item.Microphone"));
  31. SetStatus(ui->accessibilityPermissionButton, accessibility,
  32. QTStr("MacPermissions.Item.Accessibility"));
  33. }
  34. void OBSPermissions::SetStatus(QPushButton *btn, MacPermissionStatus status,
  35. const QString &preference)
  36. {
  37. if (status == kPermissionAuthorized) {
  38. btn->setText(QTStr("MacPermissions.AccessGranted"));
  39. } else if (status == kPermissionNotDetermined) {
  40. btn->setText(QTStr("MacPermissions.RequestAccess"));
  41. } else {
  42. btn->setText(
  43. QTStr("MacPermissions.OpenPreferences").arg(preference));
  44. }
  45. btn->setEnabled(status != kPermissionAuthorized);
  46. btn->setProperty("status", status);
  47. }
  48. void OBSPermissions::on_capturePermissionButton_clicked()
  49. {
  50. OpenMacOSPrivacyPreferences("ScreenCapture");
  51. RequestPermission(kScreenCapture);
  52. }
  53. void OBSPermissions::on_videoPermissionButton_clicked()
  54. {
  55. MacPermissionStatus status =
  56. (MacPermissionStatus)ui->videoPermissionButton
  57. ->property("status")
  58. .toInt();
  59. if (status == kPermissionNotDetermined) {
  60. status = RequestPermission(kVideoDeviceAccess);
  61. SetStatus(ui->videoPermissionButton, status,
  62. QTStr("MacPermissions.Item.Camera"));
  63. } else {
  64. OpenMacOSPrivacyPreferences("Camera");
  65. }
  66. }
  67. void OBSPermissions::on_audioPermissionButton_clicked()
  68. {
  69. MacPermissionStatus status =
  70. (MacPermissionStatus)ui->audioPermissionButton
  71. ->property("status")
  72. .toInt();
  73. if (status == kPermissionNotDetermined) {
  74. status = RequestPermission(kAudioDeviceAccess);
  75. SetStatus(ui->audioPermissionButton, status,
  76. QTStr("MacPermissions.Item.Microphone"));
  77. } else {
  78. OpenMacOSPrivacyPreferences("Microphone");
  79. }
  80. }
  81. void OBSPermissions::on_accessibilityPermissionButton_clicked()
  82. {
  83. OpenMacOSPrivacyPreferences("Accessibility");
  84. RequestPermission(kAccessibility);
  85. }
  86. void OBSPermissions::on_continueButton_clicked()
  87. {
  88. config_set_int(App()->GetAppConfig(), "General",
  89. "MacOSPermissionsDialogLastShown",
  90. MACOS_PERMISSIONS_DIALOG_VERSION);
  91. close();
  92. }