auth-base.hpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. public:
  19. enum class Type {
  20. None,
  21. OAuth_StreamKey
  22. };
  23. struct Def {
  24. std::string service;
  25. Type type;
  26. };
  27. typedef std::function<std::shared_ptr<Auth> ()> create_cb;
  28. inline Auth(const Def &d) : def(d) {}
  29. virtual ~Auth() {}
  30. inline Type type() const {return def.type;}
  31. inline const char *service() const {return def.service.c_str();}
  32. virtual void LoadUI() {}
  33. virtual void OnStreamConfig() {}
  34. static std::shared_ptr<Auth> Create(const std::string &service);
  35. static Type AuthType(const std::string &service);
  36. static void Load();
  37. static void Save();
  38. protected:
  39. static void RegisterAuth(const Def &d, create_cb create);
  40. private:
  41. Def def;
  42. };