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 createjob.h 0019 * @brief Abstract superclass for all jobs that create new objects on the 0020 * server. 0021 * 0022 * @author Daniel Vrátil <dvratil@redhat.com> 0023 * @since 2.0 0024 */ 0025 class KGAPICORE_EXPORT CreateJob : public KGAPI2::Job 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 /** 0031 * @brief Constructor for jobs that don't require authentication 0032 * 0033 * @param parent 0034 */ 0035 explicit CreateJob(QObject *parent = nullptr); 0036 0037 /** 0038 * @brief Constructor for jobs that require authentication 0039 * 0040 * @param account Account to use to authenticate the requests sent by this job 0041 * @param parent 0042 */ 0043 explicit CreateJob(const KGAPI2::AccountPtr &account, QObject *parent = nullptr); 0044 0045 /** 0046 * @brief Destructor 0047 */ 0048 ~CreateJob() override; 0049 0050 /** 0051 * @return Returns newly created items 0052 */ 0053 virtual ObjectsList items() const; 0054 0055 protected: 0056 /** 0057 * @brief KGAPI::Job::dispatchRequest() 0058 * 0059 * @param accessManager 0060 * @param request 0061 * @param data 0062 * @param contentType 0063 */ 0064 void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override; 0065 0066 /** 0067 * @brief KGAPI2::Job::handleReply implementation 0068 * 0069 * \param reply 0070 * \param rawData 0071 */ 0072 void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override; 0073 0074 /** 0075 * @brief KGAPI2::Job::aboutToStart() implementation 0076 */ 0077 void aboutToStart() override; 0078 0079 /** 0080 * @brief A reply handler that returns items parsed from \@ rawData 0081 * 0082 * This method can be reimplemented in FetchJob subclasses. It is called 0083 * automatically when a reply is received and the returned items are stored 0084 * in FetchJob and accessible via FetchJob::items when the job has finished. 0085 * 0086 * If you need more control over handling reply and items, you can reimplement 0087 * FetchJob::handleReply. Note that reimplementing FetchJob::handleReply 0088 * usually requires reimplementing FetchJob::items as well and storing the 0089 * parsed items in your implementation. 0090 * 0091 * @param reply A QNetworkReply received from Google's server 0092 * @param rawData Content of body of the @p reply. Don't use 0093 * QNetworkReply::readAll(), because the content has already been read 0094 * by Job implementation and thus it would return empty data. 0095 * 0096 * @return Items parsed from @p rawData 0097 */ 0098 virtual ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData); 0099 0100 private: 0101 class Private; 0102 Private *const d; 0103 friend class Private; 0104 }; 0105 0106 } // namespace KGAPI2