window-youtube-actions.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 &broadcast_id, const QString &stream_id,
  31. const QString &key, bool autostart, bool autostop,
  32. bool start_now);
  33. protected:
  34. void showEvent(QShowEvent *event) override;
  35. void UpdateOkButtonStatus();
  36. bool CreateEventAction(YoutubeApiWrappers *api,
  37. BroadcastDescription &broadcast,
  38. StreamDescription &stream, bool stream_later,
  39. bool ready_broadcast = false);
  40. bool ChooseAnEventAction(YoutubeApiWrappers *api,
  41. StreamDescription &stream);
  42. void ShowErrorDialog(QWidget *parent, QString text);
  43. public:
  44. explicit OBSYoutubeActions(QWidget *parent, Auth *auth,
  45. bool broadcastReady);
  46. virtual ~OBSYoutubeActions() override;
  47. bool Valid() { return valid; };
  48. private:
  49. void InitBroadcast();
  50. void ReadyBroadcast();
  51. void UiToBroadcast(BroadcastDescription &broadcast);
  52. void OpenYouTubeDashboard();
  53. void Cancel();
  54. void Accept();
  55. void SaveSettings(BroadcastDescription &broadcast);
  56. void LoadSettings();
  57. QIcon GetPlaceholder() { return thumbPlaceholder; }
  58. void SetPlaceholder(const QIcon &icon) { thumbPlaceholder = icon; }
  59. QString selectedBroadcast;
  60. bool autostart, autostop;
  61. bool valid = false;
  62. YoutubeApiWrappers *apiYouTube;
  63. WorkerThread *workerThread = nullptr;
  64. bool broadcastReady = false;
  65. QString thumbnailFile;
  66. QIcon thumbPlaceholder;
  67. };