diff --git a/3rdparty/o2/src/o2requestor.h b/3rdparty/o2/src/o2requestor.h new file mode 100644 index 0000000000000000000000000000000000000000..e356229c21728641302d1c656d063193bd65979b --- /dev/null +++ b/3rdparty/o2/src/o2requestor.h @@ -0,0 +1,82 @@ +#ifndef O2REQUESTOR_H +#define O2REQUESTOR_H + +#include +#include +#include +#include +#include +#include + +#include "o2reply.h" + +class O2; + +/// Makes authenticated requests. +class O2Requestor: public QObject { + Q_OBJECT + +public: + explicit O2Requestor(QNetworkAccessManager *manager, O2 *authenticator, QObject *parent = 0); + ~O2Requestor(); + +public slots: + /// Make a GET request. + /// @return Request ID or -1 if there are too many requests in the queue. + int get(const QNetworkRequest &req); + + /// Make a POST request. + /// @return Request ID or -1 if there are too many requests in the queue. + int post(const QNetworkRequest &req, const QByteArray &data); + + /// Make a PUT request. + /// @return Request ID or -1 if there are too many requests in the queue. + int put(const QNetworkRequest &req, const QByteArray &data); + +signals: + /// Emitted when a request has been completed or failed. + void finished(int id, QNetworkReply::NetworkError error, QByteArray data); + + /// Emitted when an upload has progressed. + void uploadProgress(int id, qint64 bytesSent, qint64 bytesTotal); + +protected slots: + /// Handle refresh completion. + void onRefreshFinished(QNetworkReply::NetworkError error); + + /// Handle request finished. + void onRequestFinished(); + + /// Handle request error. + void onRequestError(QNetworkReply::NetworkError error); + + /// Re-try request (after successful token refresh). + void retry(); + + /// Finish the request, emit finished() signal. + void finish(); + + /// Handle upload progress. + void onUploadProgress(qint64 uploaded, qint64 total); + +protected: + int setup(const QNetworkRequest &request, QNetworkAccessManager::Operation operation); + + enum Status { + Idle, Requesting, ReRequesting + }; + + QNetworkAccessManager *manager_; + O2 *authenticator_; + QNetworkRequest request_; + QByteArray data_; + QNetworkReply *reply_; + Status status_; + int id_; + QNetworkAccessManager::Operation operation_; + QUrl url_; + O2ReplyList timedReplies_; + QNetworkReply::NetworkError error_; +}; + +#endif // O2REQUESTOR_H