2019-07-27 12:47:10 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class Auth : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
protected:
|
2019-09-22 21:19:10 +00:00
|
|
|
virtual void SaveInternal() = 0;
|
|
|
|
virtual bool LoadInternal() = 0;
|
2019-07-27 12:47:10 +00:00
|
|
|
|
|
|
|
bool firstLoad = true;
|
|
|
|
|
|
|
|
struct ErrorInfo {
|
|
|
|
std::string message;
|
|
|
|
std::string error;
|
|
|
|
|
|
|
|
ErrorInfo(std::string message_, std::string error_)
|
|
|
|
: message(message_), error(error_)
|
2019-09-22 21:19:10 +00:00
|
|
|
{
|
|
|
|
}
|
2019-07-27 12:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
None,
|
2019-09-22 21:19:10 +00:00
|
|
|
OAuth_StreamKey,
|
2019-07-27 12:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Def {
|
|
|
|
std::string service;
|
|
|
|
Type type;
|
|
|
|
};
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
typedef std::function<std::shared_ptr<Auth>()> create_cb;
|
2019-07-27 12:47:10 +00:00
|
|
|
|
|
|
|
inline Auth(const Def &d) : def(d) {}
|
|
|
|
virtual ~Auth() {}
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
inline Type type() const { return def.type; }
|
|
|
|
inline const char *service() const { return def.service.c_str(); }
|
2019-07-27 12:47:10 +00:00
|
|
|
|
|
|
|
virtual void LoadUI() {}
|
|
|
|
|
|
|
|
virtual void OnStreamConfig() {}
|
|
|
|
|
|
|
|
static std::shared_ptr<Auth> Create(const std::string &service);
|
|
|
|
static Type AuthType(const std::string &service);
|
|
|
|
static void Load();
|
|
|
|
static void Save();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void RegisterAuth(const Def &d, create_cb create);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Def def;
|
|
|
|
};
|