-
Notifications
You must be signed in to change notification settings - Fork 1
/
domjudgeapimanager.h
95 lines (73 loc) · 2.63 KB
/
domjudgeapimanager.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef DOMJUDGEAPIMANAGER_H
#define DOMJUDGEAPIMANAGER_H
#include <QObject>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkAccessManager>
#include <QJsonDocument>
#include <QDebug>
namespace DJ
{
namespace Shared
{
class DomjudgeApiManager : public QObject
{
Q_OBJECT
public:
static DomjudgeApiManager *sharedApiManager() {
static DomjudgeApiManager *_instance = nullptr;
if (!_instance) {
_instance = new DomjudgeApiManager();
}
return _instance;
}
void setConnectionInfo(QString protocol, QString url, QString username, QString password);
void loadUserData();
void loadContestsData();
void loadTeamData(QString cid);
void loadGroupsData(QString cid);
void loadProblemData(QString cid);
void loadSubmissions(QString cid);
void loadJudgings(QString cid);
protected:
class DomjudgeApiRequest : public QNetworkRequest {
friend class DomjudgeApiManager;
explicit DomjudgeApiRequest(QString method, QList<QPair<QString, QString>> arguments = QList<QPair<QString, QString> >());
};
private:
explicit DomjudgeApiManager();
QString protocol, url, username, password;
QNetworkAccessManager *accessManager;
QList<QNetworkRequest> userRequests;
QList<QNetworkRequest> contestsRequests;
QList<QNetworkRequest> teamsRequests;
QList<QNetworkRequest> groupsRequests;
QList<QNetworkRequest> problemRequests;
QList<QNetworkRequest> submissionRequests;
QList<QNetworkRequest> judgingRequests;
template<typename... ArgsError, typename... ArgsSuccess>
bool processReply(QNetworkReply *reply,
QList<QNetworkRequest> *requests,
void(DomjudgeApiManager::*errorFunc)(ArgsError...args),
void(DomjudgeApiManager::*successFunc)(ArgsSuccess...args));
signals:
void userLoaded(QJsonDocument user);
void userDataFailedLoading(QString error);
void contestsDataLoaded(QJsonDocument contestsData);
void contestsDataFailedLoading(QString error);
void groupsDataLoaded(QJsonDocument data);
void groupsDataFailedLoading(QString error);
void teamsDataLoaded(QJsonDocument data);
void teamsDataFailedLoading(QString error);
void problemsDataLoaded(QJsonDocument data);
void problemsDataFailedLoading(QString error);
void submissionsDataLoaded(QJsonDocument data);
void submissionsDataFailedLoading(QString error);
void judgingsDataLoaded(QJsonDocument data);
void judgingsDataFailedLoading(QString error);
private slots:
void replyFinished(QNetworkReply *reply);
};
}
}
#endif // DOMJUDGEAPIMANAGER_H