1
0

auth-base.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. };
  24. struct Def {
  25. std::string service;
  26. Type type;
  27. };
  28. typedef std::function<std::shared_ptr<Auth>()> create_cb;
  29. inline Auth(const Def &d) : def(d) {}
  30. virtual ~Auth() {}
  31. inline Type type() const { return def.type; }
  32. inline const char *service() const { return def.service.c_str(); }
  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 void Load();
  38. static void Save();
  39. protected:
  40. static void RegisterAuth(const Def &d, create_cb create);
  41. private:
  42. Def def;
  43. };