KNewStuff

httpjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #include "httpjob.h"
8 
9 #include "knewstuffcore_debug.h"
10 #include "httpworker.h"
11 
12 #include <QTimer>
13 
14 using namespace KNSCore;
15 
16 class HTTPJob::Private
17 {
18 public:
19  QUrl source;
20  LoadType loadType = Reload;
21  JobFlags flags = DefaultFlags;
22 };
23 
24 HTTPJob::HTTPJob(const QUrl& source, LoadType loadType, JobFlags flags, QObject* parent)
25  : KJob(parent)
26  , d(new Private)
27 {
28  d->source = source;
29  d->loadType = loadType;
30  d->flags = flags;
31 }
32 
33 HTTPJob::HTTPJob(QObject* parent)
34  : KJob(parent)
35  , d(new Private)
36 {
37 }
38 
39 HTTPJob::~HTTPJob()
40 {
41  delete d;
42 }
43 
44 void HTTPJob::start()
45 {
46  HTTPWorker* worker = new HTTPWorker(d->source, HTTPWorker::GetJob, this);
47  connect(worker, &HTTPWorker::data, this, &HTTPJob::handleWorkerData);
48  connect(worker, &HTTPWorker::completed, this, &HTTPJob::handleWorkerCompleted);
49  connect(worker, &HTTPWorker::error, this, &HTTPJob::handleWorkerError);
50  worker->startRequest();
51 }
52 
53 void HTTPJob::handleWorkerData(const QByteArray& data)
54 {
55  Q_EMIT HTTPJob::data(this, data);
56 }
57 
58 void HTTPJob::handleWorkerCompleted()
59 {
60  emitResult();
61 }
62 
63 void KNSCore::HTTPJob::handleWorkerError(const QString& error)
64 {
65  setError(KJob::UserDefinedError);
66  setErrorText(error);
67 }
68 
69 HTTPJob* HTTPJob::get(const QUrl& source, LoadType loadType, JobFlags flags, QObject* parent)
70 {
71  HTTPJob* job = new HTTPJob(source, loadType, flags, parent);
72  QTimer::singleShot(0, job, &HTTPJob::start);
73  return job;
74 }
Contains the core functionality for handling interaction with NewStuff providers. ...
DefaultFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.