ui-validation.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "ui-validation.hpp"
  2. #include <obs.hpp>
  3. #include <QString>
  4. #include <QMessageBox>
  5. #include <QPushButton>
  6. #include <obs-app.hpp>
  7. static int CountVideoSources()
  8. {
  9. int count = 0;
  10. auto countSources = [](void *param, obs_source_t *source) {
  11. if (!source)
  12. return true;
  13. uint32_t flags = obs_source_get_output_flags(source);
  14. if ((flags & OBS_SOURCE_VIDEO) != 0)
  15. (*reinterpret_cast<int *>(param))++;
  16. return true;
  17. };
  18. obs_enum_sources(countSources, &count);
  19. return count;
  20. }
  21. bool UIValidation::NoSourcesConfirmation(QWidget *parent)
  22. {
  23. // There are sources, don't need confirmation
  24. if (CountVideoSources() != 0)
  25. return true;
  26. // Ignore no video if no parent is visible to alert on
  27. if (!parent->isVisible())
  28. return true;
  29. QString msg = QTStr("NoSources.Text");
  30. msg += "\n\n";
  31. msg += QTStr("NoSources.Text.AddSource");
  32. QMessageBox messageBox(parent);
  33. messageBox.setWindowTitle(QTStr("NoSources.Title"));
  34. messageBox.setText(msg);
  35. QAbstractButton *yesButton =
  36. messageBox.addButton(QTStr("Yes"), QMessageBox::YesRole);
  37. messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
  38. messageBox.setIcon(QMessageBox::Question);
  39. messageBox.exec();
  40. if (messageBox.clickedButton() != yesButton)
  41. return false;
  42. else
  43. return true;
  44. }