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 | #include "downloadjob.h" |
8 | |
9 | #include "httpworker.h" |
10 | |
11 | #include "knewstuffcore_debug.h" |
12 | |
13 | using namespace KNSCore; |
14 | |
15 | class KNSCore::DownloadJobPrivate |
16 | { |
17 | public: |
18 | DownloadJobPrivate() = default; |
19 | QUrl source; |
20 | QUrl destination; |
21 | }; |
22 | |
23 | DownloadJob::DownloadJob(const QUrl &source, const QUrl &destination, int permissions, JobFlags flags, QObject *parent) |
24 | : FileCopyJob(source, destination, permissions, flags, parent) |
25 | , d(new DownloadJobPrivate) |
26 | { |
27 | d->source = source; |
28 | d->destination = destination; |
29 | } |
30 | |
31 | DownloadJob::DownloadJob(QObject *parent) |
32 | : FileCopyJob(parent) |
33 | , d(new DownloadJobPrivate) |
34 | { |
35 | } |
36 | |
37 | DownloadJob::~DownloadJob() = default; |
38 | |
39 | void DownloadJob::start() |
40 | { |
41 | qCDebug(KNEWSTUFFCORE) << Q_FUNC_INFO; |
42 | HTTPWorker *worker = new HTTPWorker(d->source, d->destination, HTTPWorker::DownloadJob, this); |
43 | connect(sender: worker, signal: &HTTPWorker::completed, context: this, slot: &DownloadJob::handleWorkerCompleted); |
44 | connect(sender: worker, signal: &HTTPWorker::error, context: this, slot: &DownloadJob::handleWorkerError); |
45 | worker->startRequest(); |
46 | } |
47 | |
48 | void DownloadJob::handleWorkerCompleted() |
49 | { |
50 | emitResult(); |
51 | } |
52 | |
53 | void KNSCore::DownloadJob::handleWorkerError(const QString &error) |
54 | { |
55 | setError(KJob::UserDefinedError); |
56 | setErrorText(error); |
57 | } |
58 | |
59 | #include "moc_downloadjob.cpp" |
60 | |