streaming-helpers.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include "url-push-button.hpp"
  3. #include <QComboBox>
  4. #include <QLineEdit>
  5. #include <QLabel>
  6. #include <json11.hpp>
  7. extern json11::Json get_services_json();
  8. extern json11::Json get_service_from_json(const json11::Json &root,
  9. const char *name);
  10. enum class ListOpt : int {
  11. ShowAll = 1,
  12. Custom,
  13. };
  14. class StreamSettingsUI : public QObject {
  15. Q_OBJECT
  16. QLabel *ui_streamKeyLabel;
  17. QComboBox *ui_service;
  18. QComboBox *ui_server;
  19. QLineEdit *ui_customServer;
  20. UrlPushButton *ui_moreInfoButton;
  21. UrlPushButton *ui_streamKeyButton;
  22. json11::Json servicesRoot;
  23. bool servicesLoaded = false;
  24. QString lastService;
  25. public:
  26. inline void Setup(QLabel *streamKeyLabel, QComboBox *service,
  27. QComboBox *server, QLineEdit *customServer,
  28. UrlPushButton *moreInfoButton,
  29. UrlPushButton *streamKeyButton)
  30. {
  31. ui_streamKeyLabel = streamKeyLabel;
  32. ui_service = service;
  33. ui_server = server;
  34. ui_customServer = customServer;
  35. ui_moreInfoButton = moreInfoButton;
  36. ui_streamKeyButton = streamKeyButton;
  37. }
  38. inline bool IsCustomService() const
  39. {
  40. return ui_service->currentData().toInt() ==
  41. (int)ListOpt::Custom;
  42. }
  43. inline void ClearLastService() { lastService.clear(); }
  44. inline json11::Json GetServicesJson()
  45. {
  46. if (!servicesLoaded && servicesRoot.is_null()) {
  47. servicesRoot = get_services_json();
  48. servicesLoaded = true;
  49. }
  50. return servicesRoot;
  51. }
  52. inline const QString &LastService() const { return lastService; }
  53. bool IsServiceOutputHasNetworkFeatures();
  54. public slots:
  55. void UpdateMoreInfoLink();
  56. void UpdateKeyLink();
  57. void LoadServices(bool showAll);
  58. void UpdateServerList();
  59. };