1
0

window-permissions.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******************************************************************************
  2. Copyright (C) 2014 by Hugh 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 "window-permissions.hpp"
  16. #include "obs-app.hpp"
  17. OBSPermissions::OBSPermissions(QWidget *parent, MacPermissionStatus capture,
  18. MacPermissionStatus video,
  19. MacPermissionStatus audio,
  20. MacPermissionStatus accessibility)
  21. : QDialog(parent), ui(new Ui::OBSPermissions)
  22. {
  23. ui->setupUi(this);
  24. SetStatus(ui->capturePermissionButton, capture,
  25. QTStr("MacPermissions.Item.ScreenRecording"));
  26. SetStatus(ui->videoPermissionButton, video,
  27. QTStr("MacPermissions.Item.Camera"));
  28. SetStatus(ui->audioPermissionButton, audio,
  29. QTStr("MacPermissions.Item.Microphone"));
  30. SetStatus(ui->accessibilityPermissionButton, accessibility,
  31. QTStr("MacPermissions.Item.Accessibility"));
  32. }
  33. void OBSPermissions::SetStatus(QPushButton *btn, MacPermissionStatus status,
  34. const QString &preference)
  35. {
  36. if (status == kPermissionAuthorized) {
  37. btn->setText(QTStr("MacPermissions.AccessGranted"));
  38. } else if (status == kPermissionNotDetermined) {
  39. btn->setText(QTStr("MacPermissions.RequestAccess"));
  40. } else {
  41. btn->setText(
  42. QTStr("MacPermissions.OpenPreferences").arg(preference));
  43. }
  44. btn->setEnabled(status != kPermissionAuthorized);
  45. btn->setProperty("status", status);
  46. }
  47. void OBSPermissions::on_capturePermissionButton_clicked()
  48. {
  49. OpenMacOSPrivacyPreferences("ScreenCapture");
  50. RequestPermission(kScreenCapture);
  51. }
  52. void OBSPermissions::on_videoPermissionButton_clicked()
  53. {
  54. MacPermissionStatus status =
  55. (MacPermissionStatus)ui->videoPermissionButton
  56. ->property("status")
  57. .toInt();
  58. if (status == kPermissionNotDetermined) {
  59. status = RequestPermission(kVideoDeviceAccess);
  60. SetStatus(ui->videoPermissionButton, status,
  61. QTStr("MacPermissions.Item.Camera"));
  62. } else {
  63. OpenMacOSPrivacyPreferences("Camera");
  64. }
  65. }
  66. void OBSPermissions::on_audioPermissionButton_clicked()
  67. {
  68. MacPermissionStatus status =
  69. (MacPermissionStatus)ui->audioPermissionButton
  70. ->property("status")
  71. .toInt();
  72. if (status == kPermissionNotDetermined) {
  73. status = RequestPermission(kAudioDeviceAccess);
  74. SetStatus(ui->audioPermissionButton, status,
  75. QTStr("MacPermissions.Item.Microphone"));
  76. } else {
  77. OpenMacOSPrivacyPreferences("Microphone");
  78. }
  79. }
  80. void OBSPermissions::on_accessibilityPermissionButton_clicked()
  81. {
  82. OpenMacOSPrivacyPreferences("Accessibility");
  83. RequestPermission(kAccessibility);
  84. }
  85. void OBSPermissions::on_continueButton_clicked()
  86. {
  87. config_set_int(GetGlobalConfig(), "General",
  88. "MacOSPermissionsDialogLastShown",
  89. MACOS_PERMISSIONS_DIALOG_VERSION);
  90. close();
  91. }