2018-07-07 13:08:57 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common/NetworkCommon.hpp"
|
2019-08-20 23:29:11 +02:00
|
|
|
#include "util/QObjectRef.hpp"
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2019-09-19 18:26:38 +02:00
|
|
|
#include <QHttpMultiPart>
|
2018-07-07 13:08:57 +02:00
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
class QNetworkReply;
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
class NetworkResult;
|
|
|
|
|
2019-08-20 20:27:16 +02:00
|
|
|
class NetworkRequester : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void requestUrl();
|
|
|
|
};
|
|
|
|
|
|
|
|
class NetworkWorker : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void doneUrl();
|
|
|
|
};
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
struct NetworkData {
|
2018-07-16 17:23:41 +02:00
|
|
|
NetworkData();
|
|
|
|
~NetworkData();
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
QNetworkRequest request_;
|
2019-08-20 23:29:11 +02:00
|
|
|
bool hasCaller_{};
|
|
|
|
QObjectRef<QObject> caller_;
|
2019-08-21 00:01:27 +02:00
|
|
|
bool cache_{};
|
|
|
|
bool executeConcurrently_{};
|
2018-07-07 13:08:57 +02:00
|
|
|
|
|
|
|
NetworkReplyCreatedCallback onReplyCreated_;
|
|
|
|
NetworkErrorCallback onError_;
|
|
|
|
NetworkSuccessCallback onSuccess_;
|
|
|
|
|
|
|
|
NetworkRequestType requestType_ = NetworkRequestType::Get;
|
|
|
|
|
|
|
|
QByteArray payload_;
|
2019-09-19 18:26:38 +02:00
|
|
|
// lifetime secured by lifetimeManager_
|
|
|
|
QHttpMultiPart *multiPartPayload_{};
|
2018-07-07 13:08:57 +02:00
|
|
|
|
2019-08-20 20:08:49 +02:00
|
|
|
// Timer that tracks the timeout
|
|
|
|
// By default, there's no explicit timeout for the request
|
|
|
|
// to enable the timer, the "setTimeout" function needs to be called before
|
|
|
|
// execute is called
|
|
|
|
bool hasTimeout_{};
|
2019-08-20 23:30:39 +02:00
|
|
|
QTimer *timer_;
|
2019-09-19 18:26:38 +02:00
|
|
|
QObject *lifetimeManager_;
|
2019-08-20 20:08:49 +02:00
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
QString getHash();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString hash_;
|
|
|
|
};
|
|
|
|
|
2019-08-20 20:08:49 +02:00
|
|
|
void load(const std::shared_ptr<NetworkData> &data);
|
|
|
|
|
2018-07-07 13:08:57 +02:00
|
|
|
} // namespace chatterino
|