1
0

DecklinkOutputUI.cpp 3.1 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)
  7. : QDialog(parent), ui(new Ui_Output)
  8. {
  9. ui->setupUi(this);
  10. setSizeGripEnabled(true);
  11. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  12. propertiesView = nullptr;
  13. previewPropertiesView = nullptr;
  14. connect(ui->startOutput, SIGNAL(released()), this, SLOT(StartOutput()));
  15. connect(ui->stopOutput, SIGNAL(released()), this, SLOT(StopOutput()));
  16. connect(ui->startPreviewOutput, SIGNAL(released()), this,
  17. SLOT(StartPreviewOutput()));
  18. connect(ui->stopPreviewOutput, SIGNAL(released()), this,
  19. SLOT(StopPreviewOutput()));
  20. }
  21. void DecklinkOutputUI::ShowHideDialog()
  22. {
  23. SetupPropertiesView();
  24. SetupPreviewPropertiesView();
  25. setVisible(!isVisible());
  26. }
  27. void DecklinkOutputUI::SetupPropertiesView()
  28. {
  29. if (propertiesView)
  30. delete propertiesView;
  31. obs_data_t *settings = obs_data_create();
  32. OBSData data = load_settings();
  33. if (data)
  34. obs_data_apply(settings, data);
  35. propertiesView = new OBSPropertiesView(
  36. settings, "decklink_output",
  37. (PropertiesReloadCallback)obs_get_output_properties, 170);
  38. ui->propertiesLayout->addWidget(propertiesView);
  39. obs_data_release(settings);
  40. connect(propertiesView, SIGNAL(Changed()), this,
  41. SLOT(PropertiesChanged()));
  42. }
  43. void DecklinkOutputUI::SaveSettings()
  44. {
  45. BPtr<char> modulePath =
  46. obs_module_get_config_path(obs_current_module(), "");
  47. os_mkdirs(modulePath);
  48. BPtr<char> path = obs_module_get_config_path(
  49. obs_current_module(), "decklinkOutputProps.json");
  50. obs_data_t *settings = propertiesView->GetSettings();
  51. if (settings)
  52. obs_data_save_json_safe(settings, path, "tmp", "bak");
  53. }
  54. void DecklinkOutputUI::SetupPreviewPropertiesView()
  55. {
  56. if (previewPropertiesView)
  57. delete previewPropertiesView;
  58. obs_data_t *settings = obs_data_create();
  59. OBSData data = load_preview_settings();
  60. if (data)
  61. obs_data_apply(settings, data);
  62. previewPropertiesView = new OBSPropertiesView(
  63. settings, "decklink_output",
  64. (PropertiesReloadCallback)obs_get_output_properties, 170);
  65. ui->previewPropertiesLayout->addWidget(previewPropertiesView);
  66. obs_data_release(settings);
  67. connect(previewPropertiesView, SIGNAL(Changed()), this,
  68. SLOT(PreviewPropertiesChanged()));
  69. }
  70. void DecklinkOutputUI::SavePreviewSettings()
  71. {
  72. char *modulePath = obs_module_get_config_path(obs_current_module(), "");
  73. os_mkdirs(modulePath);
  74. char *path = obs_module_get_config_path(
  75. obs_current_module(), "decklinkPreviewOutputProps.json");
  76. obs_data_t *settings = previewPropertiesView->GetSettings();
  77. if (settings)
  78. obs_data_save_json_safe(settings, path, "tmp", "bak");
  79. }
  80. void DecklinkOutputUI::StartOutput()
  81. {
  82. SaveSettings();
  83. output_start();
  84. }
  85. void DecklinkOutputUI::StopOutput()
  86. {
  87. output_stop();
  88. }
  89. void DecklinkOutputUI::PropertiesChanged()
  90. {
  91. SaveSettings();
  92. }
  93. void DecklinkOutputUI::StartPreviewOutput()
  94. {
  95. SavePreviewSettings();
  96. preview_output_start();
  97. }
  98. void DecklinkOutputUI::StopPreviewOutput()
  99. {
  100. preview_output_stop();
  101. }
  102. void DecklinkOutputUI::PreviewPropertiesChanged()
  103. {
  104. SavePreviewSettings();
  105. }