Kgapi

fetchjob.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #include "fetchjob.h"
10 #include "../debug.h"
11 #include "object.h"
12 
13 #include <QNetworkAccessManager>
14 #include <QNetworkRequest>
15 
16 using namespace KGAPI2;
17 
18 class Q_DECL_HIDDEN FetchJob::Private
19 {
20  public:
21  ObjectsList items;
22 };
23 
25  Job(parent),
26  d(new Private)
27 {
28 }
29 
31  Job(account, parent),
32  d(new Private)
33 {
34 }
35 
37 {
38  delete d;
39 }
40 
42 {
43  if (isRunning()) {
44  qCWarning(KGAPIDebug) << "Called items() on a running job, returning empty list.";
45  return ObjectsList();
46  }
47 
48  return d->items;
49 }
50 
52  const QByteArray& data, const QString& contentType)
53 {
54  Q_UNUSED(data)
55  Q_UNUSED(contentType)
56 
57  accessManager->get(request);
58 }
59 
60 void FetchJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
61 {
62  d->items << handleReplyWithItems(reply, rawData);
63 }
64 
66 {
67  d->items.clear();
68 
70 }
71 
73 {
74  Q_UNUSED(reply)
75  Q_UNUSED(rawData)
76 
77  return ObjectsList();
78 }
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:425
bool isRunning() const
Whether job is running.
virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
A reply handler that returns items parsed from @ rawData.
Definition: fetchjob.cpp:72
void aboutToStart() override
KGAPI::Job::aboutToStart implementation.
Definition: fetchjob.cpp:65
Abstract base class for all jobs in LibKGAPI.
Definition: job.h:41
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition: fetchjob.cpp:41
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI::Job::dispatchRequest implementation.
Definition: fetchjob.cpp:51
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI::Job::handleReply implementation.
Definition: fetchjob.cpp:60
~FetchJob() override
Destructor.
Definition: fetchjob.cpp:36
Abstract superclass for all jobs that fetch resources from Google.
Definition: fetchjob.h:24
QNetworkReply * get(const QNetworkRequest &request)
QObject * parent() const const
FetchJob(QObject *parent=nullptr)
Constructor for jobs that don&#39;t require authentication.
Definition: fetchjob.cpp:24
virtual void aboutToStart()
This method is invoked right before Job::start() is called.
Definition: job.cpp:523
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 18 2020 23:08:55 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.