File indexing completed on 2024-04-14 03:53:02

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
0004     SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_STOREDTRANSFERJOB
0010 #define KIO_STOREDTRANSFERJOB
0011 
0012 #include "transferjob.h"
0013 
0014 namespace KIO
0015 {
0016 class StoredTransferJobPrivate;
0017 /**
0018  * @class KIO::StoredTransferJob storedtransferjob.h <KIO/StoredTransferJob>
0019  *
0020  * StoredTransferJob is a TransferJob (for downloading or uploading data) that
0021  * also stores a QByteArray with the data, making it simpler to use than the
0022  * standard TransferJob.
0023  *
0024  * For KIO::storedGet it puts the data into the member QByteArray, so the user
0025  * of this class can get hold of the whole data at once by calling data()
0026  * when the result signal is emitted.
0027  * You should only use StoredTransferJob to download data if you cannot
0028  * process the data by chunks while it's being downloaded, since storing
0029  * everything in a QByteArray can potentially require a lot of memory.
0030  *
0031  * For KIO::storedPut the user of this class simply provides the bytearray from
0032  * the start, and the job takes care of uploading it.
0033  * You should only use StoredTransferJob to upload data if you cannot
0034  * provide the in chunks while it's being uploaded, since storing
0035  * everything in a QByteArray can potentially require a lot of memory.
0036  */
0037 class KIOCORE_EXPORT StoredTransferJob : public KIO::TransferJob
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     ~StoredTransferJob() override;
0043 
0044     /**
0045      * Set data to be uploaded. This is for put jobs.
0046      * Automatically called by KIO::storedPut(const QByteArray &, ...),
0047      * do not call this yourself.
0048      */
0049     void setData(const QByteArray &arr);
0050 
0051     /**
0052      * Get hold of the downloaded data. This is for get jobs.
0053      * You're supposed to call this only from the slot connected to the result() signal.
0054      */
0055     QByteArray data() const;
0056 
0057 protected:
0058     KIOCORE_NO_EXPORT explicit StoredTransferJob(StoredTransferJobPrivate &dd);
0059 
0060 private:
0061     Q_DECLARE_PRIVATE(StoredTransferJob)
0062 };
0063 
0064 /**
0065  * Get (means: read), into a single QByteArray.
0066  * @see StoredTransferJob
0067  *
0068  * @param url the URL of the file
0069  * @param reload Reload to reload the file, NoReload if it can be taken from the cache
0070  * @param flags Can be HideProgressInfo here
0071  * @return the job handling the operation.
0072  */
0073 KIOCORE_EXPORT StoredTransferJob *storedGet(const QUrl &url, LoadType reload = NoReload, JobFlags flags = DefaultFlags);
0074 
0075 /**
0076  * Put (means: write) data from a QIODevice.
0077  * @see StoredTransferJob
0078  *
0079  * @param input The data to write, a device to read from. Must be open for reading (data will be read from the current position).
0080  * @param url Where to write data.
0081  * @param permissions May be -1. In this case no special permission mode is set.
0082  * @param flags Can be HideProgressInfo, Overwrite and Resume here. WARNING:
0083  * Setting Resume means that the data will be appended to @p dest if @p dest exists.
0084  * @return the job handling the operation.
0085  *
0086  * @since 5.10
0087  */
0088 KIOCORE_EXPORT StoredTransferJob *storedPut(QIODevice *input, const QUrl &url, int permissions, JobFlags flags = DefaultFlags);
0089 
0090 /**
0091  * Put (means: write) data from a single QByteArray.
0092  * @see StoredTransferJob
0093  *
0094  * @param arr The data to write
0095  * @param url Where to write data.
0096  * @param permissions May be -1. In this case no special permission mode is set.
0097  * @param flags Can be HideProgressInfo, Overwrite and Resume here. WARNING:
0098  * Setting Resume means that the data will be appended to @p dest if @p dest exists.
0099  * @return the job handling the operation.
0100  */
0101 KIOCORE_EXPORT StoredTransferJob *storedPut(const QByteArray &arr, const QUrl &url, int permissions, JobFlags flags = DefaultFlags);
0102 
0103 /**
0104  * HTTP POST (means: write) data from a single QByteArray.
0105  * @see StoredTransferJob
0106  *
0107  * @param arr The data to write
0108  * @param url Where to write data.
0109  * @param flags Can be HideProgressInfo here.
0110  * @return the job handling the operation.
0111  */
0112 KIOCORE_EXPORT StoredTransferJob *storedHttpPost(const QByteArray &arr, const QUrl &url, JobFlags flags = DefaultFlags);
0113 /**
0114  * HTTP POST (means: write) data from the given IO device.
0115  * @see StoredTransferJob
0116  *
0117  * @param device Device from which the encoded data to be posted is read. Must be open for reading.
0118  * @param url Where to write data.
0119  * @param size Size of the encoded data to be posted.
0120  * @param flags Can be HideProgressInfo here.
0121  * @return the job handling the operation.
0122  *
0123  */
0124 KIOCORE_EXPORT StoredTransferJob *storedHttpPost(QIODevice *device, const QUrl &url, qint64 size = -1, JobFlags flags = DefaultFlags);
0125 
0126 }
0127 
0128 #endif