1
0

ui-validation.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "ui-validation.hpp"
  2. #include <obs.hpp>
  3. #include <QString>
  4. #include <QMessageBox>
  5. #include <QPushButton>
  6. #include <obs-app.hpp>
  7. #include <obs-service.h>
  8. static int CountVideoSources()
  9. {
  10. int count = 0;
  11. auto countSources = [](void *param, obs_source_t *source) {
  12. if (!source)
  13. return true;
  14. uint32_t flags = obs_source_get_output_flags(source);
  15. if ((flags & OBS_SOURCE_VIDEO) != 0)
  16. (*reinterpret_cast<int *>(param))++;
  17. return true;
  18. };
  19. obs_enum_sources(countSources, &count);
  20. return count;
  21. }
  22. bool UIValidation::NoSourcesConfirmation(QWidget *parent)
  23. {
  24. // There are sources, don't need confirmation
  25. if (CountVideoSources() != 0)
  26. return true;
  27. // Ignore no video if no parent is visible to alert on
  28. if (!parent->isVisible())
  29. return true;
  30. QString msg = QTStr("NoSources.Text");
  31. msg += "\n\n";
  32. msg += QTStr("NoSources.Text.AddSource");
  33. QMessageBox messageBox(parent);
  34. messageBox.setWindowTitle(QTStr("NoSources.Title"));
  35. messageBox.setText(msg);
  36. QAbstractButton *yesButton =
  37. messageBox.addButton(QTStr("Yes"), QMessageBox::YesRole);
  38. messageBox.addButton(QTStr("No"), QMessageBox::NoRole);
  39. messageBox.setIcon(QMessageBox::Question);
  40. messageBox.exec();
  41. if (messageBox.clickedButton() != yesButton)
  42. return false;
  43. else
  44. return true;
  45. }
  46. StreamSettingsAction
  47. UIValidation::StreamSettingsConfirmation(QWidget *parent, OBSService service)
  48. {
  49. // Custom services can user API key in URL or user/pass combo.
  50. // So only check there is a URL
  51. char const *serviceType = obs_service_get_type(service);
  52. bool isCustomUrlService = (strcmp(serviceType, "rtmp_custom") == 0);
  53. char const *streamUrl = obs_service_get_url(service);
  54. char const *streamKey = obs_service_get_key(service);
  55. bool hasStreamUrl = (streamUrl != NULL && streamUrl[0] != '\0');
  56. bool hasStreamKey = ((streamKey != NULL && streamKey[0] != '\0') ||
  57. isCustomUrlService);
  58. if (hasStreamUrl && hasStreamKey)
  59. return StreamSettingsAction::ContinueStream;
  60. QString msg;
  61. if (!hasStreamUrl && !hasStreamKey) {
  62. msg = QTStr("Basic.Settings.Stream.MissingUrlAndApiKey");
  63. } else if (!hasStreamKey) {
  64. msg = QTStr("Basic.Settings.Stream.MissingStreamKey");
  65. } else {
  66. msg = QTStr("Basic.Settings.Stream.MissingUrl");
  67. }
  68. QMessageBox messageBox(parent);
  69. messageBox.setWindowTitle(
  70. QTStr("Basic.Settings.Stream.MissingSettingAlert"));
  71. messageBox.setText(msg);
  72. QPushButton *cancel;
  73. QPushButton *settings;
  74. #ifdef __APPLE__
  75. #define ACCEPT_BUTTON QMessageBox::AcceptRole
  76. #define REJECT_BUTTON QMessageBox::ResetRole
  77. #else
  78. #define ACCEPT_BUTTON QMessageBox::NoRole
  79. #define REJECT_BUTTON QMessageBox::NoRole
  80. #endif
  81. settings = messageBox.addButton(
  82. QTStr("Basic.Settings.Stream.StreamSettingsWarning"),
  83. ACCEPT_BUTTON);
  84. cancel = messageBox.addButton(QTStr("Cancel"), REJECT_BUTTON);
  85. messageBox.setDefaultButton(settings);
  86. messageBox.setEscapeButton(cancel);
  87. messageBox.setIcon(QMessageBox::Warning);
  88. messageBox.exec();
  89. if (messageBox.clickedButton() == settings)
  90. return StreamSettingsAction::OpenSettings;
  91. if (messageBox.clickedButton() == cancel)
  92. return StreamSettingsAction::Cancel;
  93. return StreamSettingsAction::ContinueStream;
  94. }