/
qauthgsi.h
74 lines (65 loc) · 2.12 KB
/
qauthgsi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef QAUTHGSI_H
#define QAUTHGSI_H
#include <QGuiApplication>
#include <QAndroidActivityResultReceiver>
#include <memory>
class QAuthGSI : public QObject
{
Q_OBJECT
public:
typedef enum
{
QGSI_SIGN_IN = 1973,
QGSI_GET_TOKEN = 1974
} GSIJavaIntent; // Made public because used in the interface now
private:
typedef enum
{
ERROR_INVALID_ACCOUNT = 0x10001,
ERROR_INVALID_TOKEN = 0x10002,
} GSIJavaErrorCodes;
typedef enum
{
ERROR_UNKNOWN = 0x20001, // We do not get an informative error code in all cases.
} GSICppErrorCodes;
struct QGSIAARR : public QAndroidActivityResultReceiver
{
static constexpr int RESULT_OK = -1;
QGSIAARR(QAuthGSI * p_caller) : caller(p_caller) {}
QAuthGSI * caller = nullptr;
void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data) override;
};
// Meta-type registering
struct QAuthGSIRegisterer
{
QAuthGSIRegisterer();
};
static const QAuthGSIRegisterer registerer;
public:
static const QString WAIT_FOR_ASYNC_ANSWER;
public:
explicit QAuthGSI(QGuiApplication *parent);
//Interface
void signIn(bool silently);
void signOut();
void obtainToken();
// Why is it public and here ? Because it is called by JNI handlers. NO MORE :)
private:
void startGSIIntent(QAuthGSI::GSIJavaIntent reason);
QString obtainTokenImpl(bool silently, QAuthGSI::GSIJavaIntent reason); // no reason to have a bool nor a QString on public interface right now
signals:
// GSI
void gsiTokenReceived(QString tokenId, QAuthGSI::GSIJavaIntent reason);
void gsiTokenRequestFailed(int resultCode, QSharedPointer<const QAndroidJniObject> data);
void failedRefresh(int statusCode, bool silently);
void successfulSignOut();
public slots:
private:
QGuiApplication * theApp = nullptr;
private:
// GSI
std::unique_ptr<QGSIAARR> activityReceiver;
};
Q_DECLARE_METATYPE(QSharedPointer<const QAndroidJniObject>)
Q_DECLARE_METATYPE(QAuthGSI::GSIJavaIntent) // After QAuthGSI declaration
#endif // QAUTHGSI_H