Changeset View
Changeset View
Standalone View
Standalone View
src/core/jobs/downloadjob.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2016 Dan Leinir Turthra Jensen <admin@leinir.dk> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Lesser General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Lesser General Public | ||||
15 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #include "downloadjob.h" | ||||
19 | | ||||
20 | #include "httpworker.h" | ||||
21 | | ||||
22 | #include "knewstuffcore_debug.h" | ||||
23 | | ||||
24 | using namespace KNSCore; | ||||
25 | | ||||
26 | class DownloadJob::Private | ||||
27 | { | ||||
28 | public: | ||||
29 | Private() {} | ||||
30 | QUrl source; | ||||
31 | QUrl destination; | ||||
32 | }; | ||||
33 | | ||||
34 | DownloadJob::DownloadJob(const QUrl& source, const QUrl& destination, int permissions, JobFlags flags, QObject* parent) | ||||
35 | : FileCopyJob(source, destination, permissions, flags, parent) | ||||
36 | , d(new Private) | ||||
37 | { | ||||
38 | d->source = source; | ||||
39 | d->destination = destination; | ||||
40 | } | ||||
41 | | ||||
42 | DownloadJob::DownloadJob(QObject* parent) | ||||
43 | : FileCopyJob(parent) | ||||
44 | , d(new Private) | ||||
45 | { | ||||
46 | } | ||||
47 | | ||||
48 | DownloadJob::~DownloadJob() | ||||
49 | { | ||||
50 | delete d; | ||||
51 | } | ||||
52 | | ||||
53 | void DownloadJob::start() | ||||
54 | { | ||||
55 | qCDebug(KNEWSTUFFCORE) << Q_FUNC_INFO; | ||||
56 | HTTPWorker* worker = new HTTPWorker(d->source, d->destination, HTTPWorker::DownloadJob, this); | ||||
57 | connect(worker, &HTTPWorker::completed, this, &DownloadJob::handleWorkerCompleted); | ||||
58 | worker->startRequest(); | ||||
59 | } | ||||
60 | | ||||
61 | void DownloadJob::handleWorkerCompleted() | ||||
62 | { | ||||
63 | // qCDebug(KNEWSTUFFCORE) << Q_FUNC_INFO; | ||||
64 | emitResult(); | ||||
65 | } |