1
0

DecklinkOutputUI.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "DecklinkOutputUI.h"
  2. #include <obs-module.h>
  3. #include <util/platform.h>
  4. #include <util/util.hpp>
  5. #include "decklink-ui-main.h"
  6. DecklinkOutputUI::DecklinkOutputUI(QWidget *parent) : QDialog(parent), ui(new Ui_Output)
  7. {
  8. ui->setupUi(this);
  9. setSizeGripEnabled(true);
  10. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  11. propertiesView = nullptr;
  12. previewPropertiesView = nullptr;
  13. }
  14. void DecklinkOutputUI::ShowHideDialog()
  15. {
  16. SetupPropertiesView();
  17. SetupPreviewPropertiesView();
  18. setVisible(!isVisible());
  19. }
  20. void DecklinkOutputUI::SetupPropertiesView()
  21. {
  22. if (propertiesView)
  23. delete propertiesView;
  24. obs_data_t *settings = obs_data_create();
  25. OBSData data = load_settings();
  26. if (data)
  27. obs_data_apply(settings, data);
  28. propertiesView = new OBSPropertiesView(settings, "decklink_output",
  29. (PropertiesReloadCallback)obs_get_output_properties, 170);
  30. ui->propertiesLayout->addWidget(propertiesView);
  31. obs_data_release(settings);
  32. connect(propertiesView, &OBSPropertiesView::Changed, this, &DecklinkOutputUI::PropertiesChanged);
  33. }
  34. void DecklinkOutputUI::SaveSettings()
  35. {
  36. BPtr<char> modulePath = obs_module_get_config_path(obs_current_module(), "");
  37. os_mkdirs(modulePath);
  38. BPtr<char> path = obs_module_get_config_path(obs_current_module(), "decklinkOutputProps.json");
  39. obs_data_t *settings = propertiesView->GetSettings();
  40. if (settings)
  41. obs_data_save_json_safe(settings, path, "tmp", "bak");
  42. }
  43. void DecklinkOutputUI::SetupPreviewPropertiesView()
  44. {
  45. if (previewPropertiesView)
  46. delete previewPropertiesView;
  47. obs_data_t *settings = obs_data_create();
  48. OBSData data = load_preview_settings();
  49. if (data)
  50. obs_data_apply(settings, data);
  51. previewPropertiesView = new OBSPropertiesView(settings, "decklink_output",
  52. (PropertiesReloadCallback)obs_get_output_properties, 170);
  53. ui->previewPropertiesLayout->addWidget(previewPropertiesView);
  54. obs_data_release(settings);
  55. connect(previewPropertiesView, &OBSPropertiesView::Changed, this, &DecklinkOutputUI::PreviewPropertiesChanged);
  56. }
  57. void DecklinkOutputUI::SavePreviewSettings()
  58. {
  59. BPtr<char> modulePath = obs_module_get_config_path(obs_current_module(), "");
  60. os_mkdirs(modulePath);
  61. BPtr<char> path = obs_module_get_config_path(obs_current_module(), "decklinkPreviewOutputProps.json");
  62. obs_data_t *settings = previewPropertiesView->GetSettings();
  63. if (settings)
  64. obs_data_save_json_safe(settings, path, "tmp", "bak");
  65. }
  66. void DecklinkOutputUI::on_outputButton_clicked()
  67. {
  68. SaveSettings();
  69. output_toggle();
  70. }
  71. void DecklinkOutputUI::PropertiesChanged()
  72. {
  73. SaveSettings();
  74. }
  75. void DecklinkOutputUI::OutputStateChanged(bool active)
  76. {
  77. QString text;
  78. if (active) {
  79. text = QString(obs_module_text("Stop"));
  80. } else {
  81. text = QString(obs_module_text("Start"));
  82. }
  83. ui->outputButton->setChecked(active);
  84. ui->outputButton->setText(text);
  85. }
  86. void DecklinkOutputUI::on_previewOutputButton_clicked()
  87. {
  88. SavePreviewSettings();
  89. preview_output_toggle();
  90. }
  91. void DecklinkOutputUI::PreviewPropertiesChanged()
  92. {
  93. SavePreviewSettings();
  94. }
  95. void DecklinkOutputUI::PreviewOutputStateChanged(bool active)
  96. {
  97. QString text;
  98. if (active) {
  99. text = QString(obs_module_text("Stop"));
  100. } else {
  101. text = QString(obs_module_text("Start"));
  102. }
  103. ui->previewOutputButton->setChecked(active);
  104. ui->previewOutputButton->setText(text);
  105. }