1 /*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
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
FetchJob(QObject * parent)24 FetchJob::FetchJob(QObject* parent):
25 Job(parent),
26 d(new Private)
27 {
28 }
29
FetchJob(const AccountPtr & account,QObject * parent)30 FetchJob::FetchJob(const AccountPtr& account, QObject* parent):
31 Job(account, parent),
32 d(new Private)
33 {
34 }
35
~FetchJob()36 FetchJob::~FetchJob()
37 {
38 delete d;
39 }
40
items() const41 ObjectsList FetchJob::items() const
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
dispatchRequest(QNetworkAccessManager * accessManager,const QNetworkRequest & request,const QByteArray & data,const QString & contentType)51 void FetchJob::dispatchRequest(QNetworkAccessManager* accessManager, const QNetworkRequest& request,
52 const QByteArray& data, const QString& contentType)
53 {
54 Q_UNUSED(data)
55 Q_UNUSED(contentType)
56
57 accessManager->get(request);
58 }
59
handleReply(const QNetworkReply * reply,const QByteArray & rawData)60 void FetchJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
61 {
62 d->items << handleReplyWithItems(reply, rawData);
63 }
64
aboutToStart()65 void FetchJob::aboutToStart()
66 {
67 d->items.clear();
68
69 Job::aboutToStart();
70 }
71
handleReplyWithItems(const QNetworkReply * reply,const QByteArray & rawData)72 ObjectsList FetchJob::handleReplyWithItems(const QNetworkReply* reply, const QByteArray& rawData)
73 {
74 Q_UNUSED(reply)
75 Q_UNUSED(rawData)
76
77 return ObjectsList();
78 }
79