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