DecklinkOutputUI.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. char *modulePath = obs_module_get_config_path(obs_current_module(), "");
  67. os_mkdirs(modulePath);
  68. char *path = obs_module_get_config_path(
  69. obs_current_module(), "decklinkPreviewOutputProps.json");
  70. obs_data_t *settings = previewPropertiesView->GetSettings();
  71. if (settings)
  72. obs_data_save_json_safe(settings, path, "tmp", "bak");
  73. }
  74. void DecklinkOutputUI::on_outputButton_clicked()
  75. {
  76. SaveSettings();
  77. output_toggle();
  78. }
  79. void DecklinkOutputUI::PropertiesChanged()
  80. {
  81. SaveSettings();
  82. }
  83. void DecklinkOutputUI::OutputStateChanged(bool active)
  84. {
  85. QString text;
  86. if (active) {
  87. text = QString(obs_module_text("Stop"));
  88. } else {
  89. text = QString(obs_module_text("Start"));
  90. }
  91. ui->outputButton->setChecked(active);
  92. ui->outputButton->setText(text);
  93. }
  94. void DecklinkOutputUI::on_previewOutputButton_clicked()
  95. {
  96. SavePreviewSettings();
  97. preview_output_toggle();
  98. }
  99. void DecklinkOutputUI::PreviewPropertiesChanged()
  100. {
  101. SavePreviewSettings();
  102. }
  103. void DecklinkOutputUI::PreviewOutputStateChanged(bool active)
  104. {
  105. QString text;
  106. if (active) {
  107. text = QString(obs_module_text("Stop"));
  108. } else {
  109. text = QString(obs_module_text("Start"));
  110. }
  111. ui->previewOutputButton->setChecked(active);
  112. ui->previewOutputButton->setText(text);
  113. }