1 /* 2 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk> 3 4 SPDX-License-Identifier: LGPL-2.1-or-later 5 */ 6 7 #ifndef HTTPWORKER_H 8 #define HTTPWORKER_H 9 10 #include <QNetworkReply> 11 #include <QUrl> 12 13 class QNetworkReply; 14 namespace KNSCore 15 { 16 class HTTPWorker : public QObject 17 { 18 Q_OBJECT 19 public: 20 enum JobType { 21 GetJob, 22 DownloadJob, // Much the same as a get... except with a filesystem destination, rather than outputting data 23 }; 24 explicit HTTPWorker(const QUrl &url, JobType jobType = GetJob, QObject *parent = nullptr); 25 explicit HTTPWorker(const QUrl &source, const QUrl &destination, JobType jobType = DownloadJob, QObject *parent = nullptr); 26 ~HTTPWorker() override; 27 28 void startRequest(); 29 30 void setUrl(const QUrl &url); 31 32 Q_SIGNAL void error(QString error); 33 Q_SIGNAL void progress(qlonglong current, qlonglong total); 34 Q_SIGNAL void completed(); 35 Q_SIGNAL void data(const QByteArray &data); 36 37 /** 38 * Fired in case there is a http error reported 39 * In some instances this is useful information for our users, and we want to make sure we report this centrally 40 * @param status The HTTP status code (fired in cases where it is perceived by QNetworkReply as an error) 41 * @param rawHeaders The raw HTTP headers for the errored-out network request 42 */ 43 Q_SIGNAL void httpError(int status, QList<QNetworkReply::RawHeaderPair> rawHeaders); 44 45 Q_SLOT void handleReadyRead(); 46 Q_SLOT void handleFinished(); 47 Q_SLOT void handleData(const QByteArray &data); 48 49 private: 50 class Private; 51 Private *d; 52 }; 53 54 } 55 56 #endif // HTTPWORKER_H 57