File indexing completed on 2024-05-12 05:22:15
0001 /* 0002 * This file is part of LibKGAPI library 0003 * 0004 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #pragma once 0010 0011 #include "job.h" 0012 #include "kgapicore_export.h" 0013 0014 namespace KGAPI2 0015 { 0016 0017 /** 0018 * @headerfile fetchjob.h 0019 * @brief Abstract superclass for all jobs that fetch resources from Google 0020 * 0021 * @author Daniel Vrátil <dvratil@redhat.com> 0022 * @since 2.0 0023 */ 0024 class KGAPICORE_EXPORT FetchJob : public KGAPI2::Job 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 /** 0030 * @brief Constructor for jobs that don't require authentication 0031 * 0032 * @param parent 0033 */ 0034 explicit FetchJob(QObject *parent = nullptr); 0035 0036 /** 0037 * @brief Constructor for jobs that require authentication 0038 * 0039 * @param account Account to use to authenticate the requests sent by this job 0040 * @param parent 0041 */ 0042 explicit FetchJob(const KGAPI2::AccountPtr &account, QObject *parent = nullptr); 0043 0044 /** 0045 * @brief Destructor 0046 */ 0047 ~FetchJob() override; 0048 0049 /** 0050 * @brief Returns all items fetched by this job. 0051 * 0052 * Returns all items fetch by this job. This method can be called only 0053 * from handler of Job::finished signal. Calling this method on a running 0054 * job will print a warning and return an empty list. 0055 * 0056 * @return All items fetched by this job. 0057 */ 0058 virtual ObjectsList items() const; 0059 0060 protected: 0061 /** 0062 * @brief KGAPI::Job::dispatchRequest implementation 0063 * 0064 * @param accessManager 0065 * @param request 0066 * @param data 0067 * @param contentType 0068 */ 0069 void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override; 0070 0071 /** 0072 * @brief KGAPI::Job::handleReply implementation 0073 * 0074 * @param reply 0075 * @param rawData 0076 */ 0077 void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override; 0078 0079 /** 0080 * @brief KGAPI::Job::aboutToStart implementation 0081 */ 0082 void aboutToStart() override; 0083 0084 /** 0085 * @brief A reply handler that returns items parsed from \@ rawData 0086 * 0087 * This method can be reimplemented in a FetchJob subclasses. It is called 0088 * automatically when a reply is received and the returned items are stored 0089 * in FetchJob and accessible via FetchJob::items when the job has finished. 0090 * 0091 * If you need more control over handling reply and items, you can reimplement 0092 * FetchJob::handleReply. Note that reimplementing FetchJob::handleReply 0093 * usually requires reimplementing FetchJob::items as well and storing the 0094 * parsed items in your implementation. 0095 * 0096 * @param reply A QNetworkReply received from Google server 0097 * @param rawData Content of body of the @p reply. Don't use 0098 * QNetworkReply::readAll(), because the content has already been read 0099 * by Job implementation and thus it would return empty data. 0100 * 0101 * @return Items parsed from @p rawData 0102 */ 0103 virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData); 0104 0105 private: 0106 class Private; 0107 Private *const d; 0108 friend class Private; 0109 }; 0110 } // namespace KGAPI2