Kgapi

fetchjob.h
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#pragma once
10
11#include "job.h"
12#include "kgapicore_export.h"
13
14namespace KGAPI2
15{
16
17/**
18 * @headerfile fetchjob.h
19 * @brief Abstract superclass for all jobs that fetch resources from Google
20 *
21 * @author Daniel Vrátil <dvratil@redhat.com>
22 * @since 2.0
23 */
24class KGAPICORE_EXPORT FetchJob : public KGAPI2::Job
25{
26 Q_OBJECT
27
28public:
29 /**
30 * @brief Constructor for jobs that don't require authentication
31 *
32 * @param parent
33 */
34 explicit FetchJob(QObject *parent = nullptr);
35
36 /**
37 * @brief Constructor for jobs that require authentication
38 *
39 * @param account Account to use to authenticate the requests sent by this job
40 * @param parent
41 */
42 explicit FetchJob(const KGAPI2::AccountPtr &account, QObject *parent = nullptr);
43
44 /**
45 * @brief Destructor
46 */
47 ~FetchJob() override;
48
49 /**
50 * @brief Returns all items fetched by this job.
51 *
52 * Returns all items fetch by this job. This method can be called only
53 * from handler of Job::finished signal. Calling this method on a running
54 * job will print a warning and return an empty list.
55 *
56 * @return All items fetched by this job.
57 */
58 virtual ObjectsList items() const;
59
60protected:
61 /**
62 * @brief KGAPI::Job::dispatchRequest implementation
63 *
64 * @param accessManager
65 * @param request
66 * @param data
67 * @param contentType
68 */
69 void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override;
70
71 /**
72 * @brief KGAPI::Job::handleReply implementation
73 *
74 * @param reply
75 * @param rawData
76 */
77 void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override;
78
79 /**
80 * @brief KGAPI::Job::aboutToStart implementation
81 */
82 void aboutToStart() override;
83
84 /**
85 * @brief A reply handler that returns items parsed from \@ rawData
86 *
87 * This method can be reimplemented in a FetchJob subclasses. It is called
88 * automatically when a reply is received and the returned items are stored
89 * in FetchJob and accessible via FetchJob::items when the job has finished.
90 *
91 * If you need more control over handling reply and items, you can reimplement
92 * FetchJob::handleReply. Note that reimplementing FetchJob::handleReply
93 * usually requires reimplementing FetchJob::items as well and storing the
94 * parsed items in your implementation.
95 *
96 * @param reply A QNetworkReply received from Google server
97 * @param rawData Content of body of the @p reply. Don't use
98 * QNetworkReply::readAll(), because the content has already been read
99 * by Job implementation and thus it would return empty data.
100 *
101 * @return Items parsed from @p rawData
102 */
103 virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData);
104
105private:
106 class Private;
107 Private *const d;
108 friend class Private;
109};
110} // namespace KGAPI2
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
Abstract base class for all jobs in LibKGAPI.
Definition job.h:41
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.