1 | /* |
2 | SPDX-FileCopyrightText: 2010 Aleix Pol Gonzalez <aleixpol@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KDEVPLATFORM_PLUGIN_REVIEWBOARDJOBS_H |
8 | #define KDEVPLATFORM_PLUGIN_REVIEWBOARDJOBS_H |
9 | |
10 | #include <QList> |
11 | #include <QNetworkAccessManager> |
12 | #include <QPair> |
13 | #include <QUrl> |
14 | |
15 | #include <KJob> |
16 | |
17 | class QNetworkReply; |
18 | |
19 | namespace ReviewBoard |
20 | { |
21 | /** |
22 | * Http call to the specified service. |
23 | * Converts returned json data to a QVariant to be used from actual API calls |
24 | * |
25 | * @note It is reviewboard-agnostic. |
26 | */ |
27 | class HttpCall : public KJob |
28 | { |
29 | Q_OBJECT |
30 | Q_PROPERTY(QVariant result READ result) |
31 | public: |
32 | enum Method { |
33 | Get, |
34 | Put, |
35 | Post, |
36 | }; |
37 | |
38 | HttpCall(const QUrl &s, |
39 | const QString &apiPath, |
40 | const QList<QPair<QString, QString>> &queryParameters, |
41 | Method m, |
42 | const QByteArray &post, |
43 | bool multipart, |
44 | QObject *parent); |
45 | |
46 | void start() override; |
47 | |
48 | QVariant result() const; |
49 | |
50 | private Q_SLOTS: |
51 | void onFinished(); |
52 | |
53 | private: |
54 | // TODO: change to QJsonObject |
55 | QVariant m_result; |
56 | QNetworkReply *m_reply; |
57 | QUrl m_requrl; |
58 | QByteArray m_post; |
59 | |
60 | QNetworkAccessManager m_manager; |
61 | bool m_multipart; |
62 | Method m_method; |
63 | }; |
64 | |
65 | class ReviewRequest : public KJob |
66 | { |
67 | Q_OBJECT |
68 | public: |
69 | ReviewRequest(const QUrl &server, const QString &id, QObject *parent) |
70 | : KJob(parent) |
71 | , m_server(server) |
72 | , m_id(id) |
73 | { |
74 | } |
75 | QString requestId() const |
76 | { |
77 | return m_id; |
78 | } |
79 | void setRequestId(QString id) |
80 | { |
81 | m_id = id; |
82 | } |
83 | QUrl server() const |
84 | { |
85 | return m_server; |
86 | } |
87 | |
88 | private: |
89 | QUrl m_server; |
90 | QString m_id; |
91 | }; |
92 | |
93 | class NewRequest : public ReviewRequest |
94 | { |
95 | Q_OBJECT |
96 | public: |
97 | NewRequest(const QUrl &server, const QString &project, QObject *parent = nullptr); |
98 | void start() override; |
99 | |
100 | private Q_SLOTS: |
101 | void done(); |
102 | |
103 | private: |
104 | HttpCall *m_newreq; |
105 | QString m_project; |
106 | }; |
107 | |
108 | class UpdateRequest : public ReviewRequest |
109 | { |
110 | Q_OBJECT |
111 | public: |
112 | UpdateRequest(const QUrl &server, const QString &id, const QVariantMap &newValues, QObject *parent = nullptr); |
113 | void start() override; |
114 | |
115 | private Q_SLOTS: |
116 | void done(); |
117 | |
118 | private: |
119 | HttpCall *m_req; |
120 | QString m_project; |
121 | }; |
122 | |
123 | class SubmitPatchRequest : public ReviewRequest |
124 | { |
125 | Q_OBJECT |
126 | public: |
127 | SubmitPatchRequest(const QUrl &server, const QUrl &patch, const QString &basedir, const QString &id, QObject *parent = nullptr); |
128 | void start() override; |
129 | |
130 | private Q_SLOTS: |
131 | void done(); |
132 | |
133 | private: |
134 | HttpCall *m_uploadpatch; |
135 | QUrl m_patch; |
136 | QString m_basedir; |
137 | }; |
138 | |
139 | class ProjectsListRequest : public KJob |
140 | { |
141 | Q_OBJECT |
142 | public: |
143 | ProjectsListRequest(const QUrl &server, QObject *parent = nullptr); |
144 | void start() override; |
145 | QVariantList repositories() const; |
146 | |
147 | private Q_SLOTS: |
148 | void requestRepositoryList(int startIndex); |
149 | void done(KJob *done); |
150 | |
151 | private: |
152 | QUrl m_server; |
153 | QVariantList m_repositories; |
154 | }; |
155 | |
156 | class ReviewListRequest : public KJob |
157 | { |
158 | Q_OBJECT |
159 | public: |
160 | ReviewListRequest(const QUrl &server, const QString &user, const QString &reviewStatus, QObject *parent = nullptr); |
161 | void start() override; |
162 | QVariantList reviews() const; |
163 | |
164 | private Q_SLOTS: |
165 | void requestReviewList(int startIndex); |
166 | void done(KJob *done); |
167 | |
168 | private: |
169 | QUrl m_server; |
170 | QString m_user; |
171 | QString m_reviewStatus; |
172 | QVariantList m_reviews; |
173 | }; |
174 | |
175 | QByteArray urlToData(const QUrl &); |
176 | } |
177 | |
178 | #endif |
179 | |