Simplify Upload and Download
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -46,15 +46,14 @@
|
||||
#include "Validator.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "net/NetRequest.h"
|
||||
|
||||
namespace Net {
|
||||
class Download : public NetAction {
|
||||
class Download : public NetRequest {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using Ptr = shared_qobject_ptr<class Download>;
|
||||
enum class Option { NoOptions = 0, AcceptLocalFiles = 1, MakeEternal = 2 };
|
||||
Q_DECLARE_FLAGS(Options, Option)
|
||||
|
||||
public:
|
||||
~Download() override = default;
|
||||
@ -66,34 +65,9 @@ class Download : public NetAction {
|
||||
static auto makeByteArray(QUrl url, std::shared_ptr<QByteArray> output, Options options = Option::NoOptions) -> Download::Ptr;
|
||||
static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
|
||||
|
||||
void init() override {};
|
||||
|
||||
public:
|
||||
void addValidator(Validator* v);
|
||||
auto abort() -> bool override;
|
||||
auto canAbort() const -> bool override { return true; };
|
||||
|
||||
private:
|
||||
auto handleRedirect() -> bool;
|
||||
|
||||
protected slots:
|
||||
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
|
||||
void downloadError(QNetworkReply::NetworkError error) override;
|
||||
void sslErrors(const QList<QSslError>& errors) override;
|
||||
void downloadFinished() override;
|
||||
void downloadReadyRead() override;
|
||||
|
||||
public slots:
|
||||
void executeTask() override;
|
||||
void init() override{};
|
||||
|
||||
protected:
|
||||
std::unique_ptr<Sink> m_sink;
|
||||
Options m_options;
|
||||
|
||||
std::chrono::steady_clock m_clock;
|
||||
std::chrono::time_point<std::chrono::steady_clock> m_last_progress_time;
|
||||
qint64 m_last_progress_bytes;
|
||||
virtual QNetworkReply* getReply(QNetworkRequest&) override;
|
||||
};
|
||||
} // namespace Net
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Net::Download::Options)
|
||||
|
Reference in New Issue
Block a user