KNewStuff

downloadjob.cpp
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
13using namespace KNSCore;
14
15class KNSCore::DownloadJobPrivate
16{
17public:
18 DownloadJobPrivate() = default;
19 QUrl source;
20 QUrl destination;
21};
22
23DownloadJob::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
31DownloadJob::DownloadJob(QObject *parent)
32 : FileCopyJob(parent)
33 , d(new DownloadJobPrivate)
34{
35}
36
37DownloadJob::~DownloadJob() = default;
38
39void DownloadJob::start()
40{
41 qCDebug(KNEWSTUFFCORE) << Q_FUNC_INFO;
42 HTTPWorker *worker = new HTTPWorker(d->source, d->destination, HTTPWorker::DownloadJob, this);
43 connect(worker, &HTTPWorker::completed, this, &DownloadJob::handleWorkerCompleted);
44 connect(worker, &HTTPWorker::error, this, &DownloadJob::handleWorkerError);
45 worker->startRequest();
46}
47
48void DownloadJob::handleWorkerCompleted()
49{
50 emitResult();
51}
52
53void KNSCore::DownloadJob::handleWorkerError(const QString &error)
54{
55 setError(KJob::UserDefinedError);
56 setErrorText(error);
57}
58
59#include "moc_downloadjob.cpp"
void emitResult()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.