Auth.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <QObject>
  3. class Auth : public QObject {
  4. Q_OBJECT
  5. protected:
  6. virtual void SaveInternal() = 0;
  7. virtual bool LoadInternal() = 0;
  8. bool firstLoad = true;
  9. struct ErrorInfo {
  10. std::string message;
  11. std::string error;
  12. ErrorInfo(std::string message_, std::string error_) : message(message_), error(error_) {}
  13. };
  14. public:
  15. enum class Type {
  16. None,
  17. OAuth_StreamKey,
  18. OAuth_LinkedAccount,
  19. };
  20. struct Def {
  21. std::string service;
  22. Type type;
  23. bool externalOAuth;
  24. bool usesBroadcastFlow;
  25. };
  26. typedef std::function<std::shared_ptr<Auth>()> create_cb;
  27. inline Auth(const Def &d) : def(d) {}
  28. virtual ~Auth() {}
  29. inline Type type() const { return def.type; }
  30. inline const char *service() const { return def.service.c_str(); }
  31. inline bool external() const { return def.externalOAuth; }
  32. inline bool broadcastFlow() const { return def.usesBroadcastFlow; }
  33. virtual void LoadUI() {}
  34. virtual void OnStreamConfig() {}
  35. static std::shared_ptr<Auth> Create(const std::string &service);
  36. static Type AuthType(const std::string &service);
  37. static bool External(const std::string &service);
  38. static void Load();
  39. static void Save();
  40. protected:
  41. static void RegisterAuth(const Def &d, create_cb create);
  42. private:
  43. Def def;
  44. };