DecklinkOutputUI.cpp 3.2 KB

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