auth-base.hpp 1.2 KB

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