DecklinkOutputUI.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. }
  16. void DecklinkOutputUI::ShowHideDialog()
  17. {
  18. SetupPropertiesView();
  19. SetupPreviewPropertiesView();
  20. setVisible(!isVisible());
  21. }
  22. void DecklinkOutputUI::SetupPropertiesView()
  23. {
  24. if (propertiesView)
  25. delete propertiesView;
  26. obs_data_t *settings = obs_data_create();
  27. OBSData data = load_settings();
  28. if (data)
  29. obs_data_apply(settings, data);
  30. propertiesView = new OBSPropertiesView(
  31. settings, "decklink_output",
  32. (PropertiesReloadCallback)obs_get_output_properties, 170);
  33. ui->propertiesLayout->addWidget(propertiesView);
  34. obs_data_release(settings);
  35. connect(propertiesView, &OBSPropertiesView::Changed, this,
  36. &DecklinkOutputUI::PropertiesChanged);
  37. }
  38. void DecklinkOutputUI::SaveSettings()
  39. {
  40. BPtr<char> modulePath =
  41. obs_module_get_config_path(obs_current_module(), "");
  42. os_mkdirs(modulePath);
  43. BPtr<char> path = obs_module_get_config_path(
  44. obs_current_module(), "decklinkOutputProps.json");
  45. obs_data_t *settings = propertiesView->GetSettings();
  46. if (settings)
  47. obs_data_save_json_safe(settings, path, "tmp", "bak");
  48. }
  49. void DecklinkOutputUI::SetupPreviewPropertiesView()
  50. {
  51. if (previewPropertiesView)
  52. delete previewPropertiesView;
  53. obs_data_t *settings = obs_data_create();
  54. OBSData data = load_preview_settings();
  55. if (data)
  56. obs_data_apply(settings, data);
  57. previewPropertiesView = new OBSPropertiesView(
  58. settings, "decklink_output",
  59. (PropertiesReloadCallback)obs_get_output_properties, 170);
  60. ui->previewPropertiesLayout->addWidget(previewPropertiesView);
  61. obs_data_release(settings);
  62. connect(previewPropertiesView, &OBSPropertiesView::Changed, this,
  63. &DecklinkOutputUI::PreviewPropertiesChanged);
  64. }
  65. void DecklinkOutputUI::SavePreviewSettings()
  66. {
  67. BPtr<char> modulePath =
  68. obs_module_get_config_path(obs_current_module(), "");
  69. os_mkdirs(modulePath);
  70. BPtr<char> path = obs_module_get_config_path(
  71. obs_current_module(), "decklinkPreviewOutputProps.json");
  72. obs_data_t *settings = previewPropertiesView->GetSettings();
  73. if (settings)
  74. obs_data_save_json_safe(settings, path, "tmp", "bak");
  75. }
  76. void DecklinkOutputUI::on_outputButton_clicked()
  77. {
  78. SaveSettings();
  79. output_toggle();
  80. }
  81. void DecklinkOutputUI::PropertiesChanged()
  82. {
  83. SaveSettings();
  84. }
  85. void DecklinkOutputUI::OutputStateChanged(bool active)
  86. {
  87. QString text;
  88. if (active) {
  89. text = QString(obs_module_text("Stop"));
  90. } else {
  91. text = QString(obs_module_text("Start"));
  92. }
  93. ui->outputButton->setChecked(active);
  94. ui->outputButton->setText(text);
  95. }
  96. void DecklinkOutputUI::on_previewOutputButton_clicked()
  97. {
  98. SavePreviewSettings();
  99. preview_output_toggle();
  100. }
  101. void DecklinkOutputUI::PreviewPropertiesChanged()
  102. {
  103. SavePreviewSettings();
  104. }
  105. void DecklinkOutputUI::PreviewOutputStateChanged(bool active)
  106. {
  107. QString text;
  108. if (active) {
  109. text = QString(obs_module_text("Stop"));
  110. } else {
  111. text = QString(obs_module_text("Start"));
  112. }
  113. ui->previewOutputButton->setChecked(active);
  114. ui->previewOutputButton->setText(text);
  115. }