KNewStuff

downloadjob.cpp
1 /*
2  Copyright (C) 2016 Dan Leinir Turthra Jensen <[email protected]>
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  connect(worker, &HTTPWorker::error, this, &DownloadJob::handleWorkerError);
59  worker->startRequest();
60 }
61 
62 void DownloadJob::handleWorkerCompleted()
63 {
64  emitResult();
65 }
66 
67 void KNSCore::DownloadJob::handleWorkerError(const QString& error)
68 {
69  setError(KJob::UserDefinedError);
70  setErrorText(error);
71 }
Contains the core functionality for handling interaction with NewStuff providers. ...
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.