1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> |
4 | SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #ifndef KIO_STOREDTRANSFERJOB |
10 | #define KIO_STOREDTRANSFERJOB |
11 | |
12 | #include "transferjob.h" |
13 | |
14 | namespace KIO |
15 | { |
16 | class StoredTransferJobPrivate; |
17 | /*! |
18 | * \class KIO::StoredTransferJob |
19 | * \inheaderfile KIO/StoredTransferJob |
20 | * \inmodule KIOCore |
21 | * |
22 | * \brief StoredTransferJob is a TransferJob (for downloading or uploading data) that |
23 | * also stores a QByteArray with the data, making it simpler to use than the |
24 | * standard TransferJob. |
25 | * |
26 | * For KIO::storedGet it puts the data into the member QByteArray, so the user |
27 | * of this class can get hold of the whole data at once by calling data() |
28 | * when the result signal is emitted. |
29 | * You should only use StoredTransferJob to download data if you cannot |
30 | * process the data by chunks while it's being downloaded, since storing |
31 | * everything in a QByteArray can potentially require a lot of memory. |
32 | * |
33 | * For KIO::storedPut the user of this class simply provides the bytearray from |
34 | * the start, and the job takes care of uploading it. |
35 | * You should only use StoredTransferJob to upload data if you cannot |
36 | * provide the in chunks while it's being uploaded, since storing |
37 | * everything in a QByteArray can potentially require a lot of memory. |
38 | */ |
39 | class KIOCORE_EXPORT StoredTransferJob : public KIO::TransferJob |
40 | { |
41 | Q_OBJECT |
42 | |
43 | public: |
44 | ~StoredTransferJob() override; |
45 | |
46 | /*! |
47 | * Set data to be uploaded. This is for put jobs. |
48 | * Automatically called by KIO::storedPut(const QByteArray &, ...), |
49 | * do not call this yourself. |
50 | */ |
51 | void setData(const QByteArray &arr); |
52 | |
53 | /*! |
54 | * Get hold of the downloaded data. This is for get jobs. |
55 | * You're supposed to call this only from the slot connected to the result() signal. |
56 | */ |
57 | QByteArray data() const; |
58 | |
59 | protected: |
60 | KIOCORE_NO_EXPORT explicit StoredTransferJob(StoredTransferJobPrivate &dd); |
61 | |
62 | private: |
63 | Q_DECLARE_PRIVATE(StoredTransferJob) |
64 | }; |
65 | |
66 | /*! |
67 | * \relates KIO::StoredTransferJob |
68 | * |
69 | * Get (means: read), into a single QByteArray. |
70 | * |
71 | * \a url the URL of the file |
72 | * |
73 | * \a reload Reload to reload the file, NoReload if it can be taken from the cache |
74 | * |
75 | * \a flags Can be HideProgressInfo here |
76 | * |
77 | * Returns the job handling the operation. |
78 | */ |
79 | KIOCORE_EXPORT StoredTransferJob *storedGet(const QUrl &url, LoadType reload = NoReload, JobFlags flags = DefaultFlags); |
80 | |
81 | /*! |
82 | * \relates KIO::StoredTransferJob |
83 | * |
84 | * Put (means: write) data from a QIODevice. |
85 | * |
86 | * \a input The data to write, a device to read from. Must be open for reading (data will be read from the current position). |
87 | * |
88 | * \a url Where to write data. |
89 | * |
90 | * \a permissions May be -1. In this case no special permission mode is set. |
91 | * |
92 | * \a flags Can be HideProgressInfo, Overwrite and Resume here. |
93 | * WARNING: Setting Resume means that the data will be appended to \a dest if \a dest exists. |
94 | * |
95 | * Returns the job handling the operation. |
96 | * |
97 | * \since 5.10 |
98 | */ |
99 | KIOCORE_EXPORT StoredTransferJob *storedPut(QIODevice *input, const QUrl &url, int permissions, JobFlags flags = DefaultFlags); |
100 | |
101 | /*! |
102 | * \relates KIO::StoredTransferJob |
103 | * |
104 | * Put (means: write) data from a single QByteArray. |
105 | * |
106 | * \a arr The data to write |
107 | * |
108 | * \a url Where to write data. |
109 | * |
110 | * \a permissions May be -1. In this case no special permission mode is set. |
111 | * |
112 | * \a flags Can be HideProgressInfo, Overwrite and Resume here. |
113 | * WARNING: Setting Resume means that the data will be appended to \a url if \a url exists. |
114 | * |
115 | * Returns the job handling the operation. |
116 | */ |
117 | KIOCORE_EXPORT StoredTransferJob *storedPut(const QByteArray &arr, const QUrl &url, int permissions, JobFlags flags = DefaultFlags); |
118 | |
119 | /*! |
120 | * \relates KIO::StoredTransferJob |
121 | * |
122 | * HTTP POST (means: write) data from a single QByteArray. |
123 | * |
124 | * \a arr The data to write |
125 | * |
126 | * \a url Where to write data. |
127 | * |
128 | * \a flags Can be HideProgressInfo here. |
129 | * |
130 | * Returns the job handling the operation. |
131 | */ |
132 | KIOCORE_EXPORT StoredTransferJob *storedHttpPost(const QByteArray &arr, const QUrl &url, JobFlags flags = DefaultFlags); |
133 | |
134 | /*! |
135 | * \relates KIO::StoredTransferJob |
136 | * |
137 | * HTTP POST (means: write) data from the given IO device. |
138 | * |
139 | * \a device Device from which the encoded data to be posted is read. Must be open for reading. |
140 | * |
141 | * \a url Where to write data. |
142 | * |
143 | * \a size Size of the encoded data to be posted. |
144 | * |
145 | * \a flags Can be HideProgressInfo here. |
146 | * |
147 | * Returns the job handling the operation. |
148 | * |
149 | */ |
150 | KIOCORE_EXPORT StoredTransferJob *storedHttpPost(QIODevice *device, const QUrl &url, qint64 size = -1, JobFlags flags = DefaultFlags); |
151 | |
152 | } |
153 | |
154 | #endif |
155 | |