window-youtube-actions.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, const QString &broadcast,
  20. const QString &status, bool astart, bool astop);
  21. void failed();
  22. };
  23. class OBSYoutubeActions : public QDialog {
  24. Q_OBJECT
  25. Q_PROPERTY(QIcon thumbPlaceholder READ GetPlaceholder WRITE SetPlaceholder DESIGNABLE true)
  26. std::unique_ptr<Ui::OBSYoutubeActions> ui;
  27. signals:
  28. void ok(const QString &broadcast_id, const QString &stream_id, const QString &key, bool autostart,
  29. bool autostop, bool start_now);
  30. protected:
  31. void showEvent(QShowEvent *event) override;
  32. void UpdateOkButtonStatus();
  33. bool CreateEventAction(YoutubeApiWrappers *api, BroadcastDescription &broadcast, StreamDescription &stream,
  34. bool stream_later, bool ready_broadcast = false);
  35. bool ChooseAnEventAction(YoutubeApiWrappers *api, StreamDescription &stream);
  36. void ShowErrorDialog(QWidget *parent, QString text);
  37. public:
  38. explicit OBSYoutubeActions(QWidget *parent, Auth *auth, bool broadcastReady);
  39. virtual ~OBSYoutubeActions() override;
  40. bool Valid() { return valid; };
  41. private:
  42. void InitBroadcast();
  43. void ReadyBroadcast();
  44. void UiToBroadcast(BroadcastDescription &broadcast);
  45. void OpenYouTubeDashboard();
  46. void Cancel();
  47. void Accept();
  48. void SaveSettings(BroadcastDescription &broadcast);
  49. void LoadSettings();
  50. QIcon GetPlaceholder() { return thumbPlaceholder; }
  51. void SetPlaceholder(const QIcon &icon) { thumbPlaceholder = icon; }
  52. QString selectedBroadcast;
  53. bool autostart, autostop;
  54. bool valid = false;
  55. YoutubeApiWrappers *apiYouTube;
  56. WorkerThread *workerThread = nullptr;
  57. bool broadcastReady = false;
  58. QString thumbnailFile;
  59. QIcon thumbPlaceholder;
  60. };