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