window-youtube-actions.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include <QDialog>
  3. #include <QString>
  4. #include <QThread>
  5. #include "ui_OBSYoutubeActions.h"
  6. #include "youtube-api-wrappers.hpp"
  7. class WorkerThread : public QThread {
  8. Q_OBJECT
  9. public:
  10. WorkerThread(YoutubeApiWrappers *api) : QThread(), apiYouTube(api) {}
  11. void stop() { pending = false; }
  12. protected:
  13. YoutubeApiWrappers *apiYouTube;
  14. bool pending = true;
  15. public slots:
  16. void run() override;
  17. signals:
  18. void ready();
  19. void new_item(const QString &title, const QString &dateTimeString,
  20. const QString &broadcast, const QString &status,
  21. bool astart, bool astop);
  22. void failed();
  23. };
  24. class OBSYoutubeActions : public QDialog {
  25. Q_OBJECT
  26. Q_PROPERTY(QIcon thumbPlaceholder READ GetPlaceholder WRITE
  27. SetPlaceholder DESIGNABLE true)
  28. std::unique_ptr<Ui::OBSYoutubeActions> ui;
  29. signals:
  30. void ok(const QString &id, const QString &key, bool autostart,
  31. bool autostop, bool start_now);
  32. protected:
  33. void showEvent(QShowEvent *event) override;
  34. void UpdateOkButtonStatus();
  35. bool CreateEventAction(YoutubeApiWrappers *api,
  36. StreamDescription &stream, bool stream_later,
  37. bool ready_broadcast = false);
  38. bool ChooseAnEventAction(YoutubeApiWrappers *api,
  39. StreamDescription &stream);
  40. void ShowErrorDialog(QWidget *parent, QString text);
  41. public:
  42. explicit OBSYoutubeActions(QWidget *parent, Auth *auth,
  43. bool broadcastReady);
  44. virtual ~OBSYoutubeActions() override;
  45. bool Valid() { return valid; };
  46. private:
  47. void InitBroadcast();
  48. void ReadyBroadcast();
  49. void UiToBroadcast(BroadcastDescription &broadcast);
  50. void OpenYouTubeDashboard();
  51. void Cancel();
  52. void Accept();
  53. void SaveSettings(BroadcastDescription &broadcast);
  54. void LoadSettings();
  55. QIcon GetPlaceholder() { return thumbPlaceholder; }
  56. void SetPlaceholder(const QIcon &icon) { thumbPlaceholder = icon; }
  57. QString selectedBroadcast;
  58. bool autostart, autostop;
  59. bool valid = false;
  60. YoutubeApiWrappers *apiYouTube;
  61. WorkerThread *workerThread = nullptr;
  62. bool broadcastReady = false;
  63. QString thumbnailFile;
  64. QIcon thumbPlaceholder;
  65. };