streaming-helpers.hpp 1.5 KB

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