Commit 2349de76 authored by Anupam Basak's avatar Anupam Basak

Implement File Download using KIO

parent ed817de5
#include <KIO/CopyJob>
#include <KJob>
#include "downloader.h"
FMH::Downloader::Downloader(QObject *parent) : QObject(parent), manager(new QNetworkAccessManager), array(new QByteArray)
......@@ -11,6 +14,20 @@ FMH::Downloader::Downloader(QObject *parent) : QObject(parent), manager(new QNet
this->reply = nullptr;
void FMH::Downloader::downloadFile(const QUrl &source, const QUrl &destination) {
KIO::CopyJob *downloadJob = KIO::copy(source, destination);
QObject::connect(downloadJob, &KIO::CopyJob::processedSize, [=](KJob *job, qulonglong size){
emit progress(size, job->percent());
QObject::connect(downloadJob, &KIO::CopyJob::finished, [=](KJob *job){
emit done();
void FMH::Downloader::setFile(const QUrl &fileURL, const QUrl &fileName)
......@@ -25,6 +25,8 @@ public:
Downloader(QObject *parent = nullptr);
virtual ~Downloader();
void downloadFile(const QUrl &source, const QUrl &destination);
void setFile(const QUrl &fileURL, const QUrl &fileName = QUrl());
void getArray(const QUrl &fileURL, const QMap<QString, QString> &headers = {});
......@@ -36,6 +38,7 @@ private:
void progress(int percent);
void progress(qulonglong processedSize, unsigned long percent);
void downloadReady();
void fileSaved(QString path);
void warning(QString warning);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment