KIO::TransferJob Class
class KIO::TransferJobThe transfer job pumps data into and/or out of a KIO worker. More...
Header: | #include <KIO/TransferJob> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOCore) |
Inherits: | KIO::SimpleJob |
Inherited By: | KIO::DavJob, KIO::MimetypeJob, KIO::SpecialJob, and KIO::StoredTransferJob |
Public Functions
QString | mimetype() const |
(since 5.0) QUrl | redirectUrl() const |
void | sendAsyncData(const QByteArray &data) |
void | setAsyncDataEnabled(bool enabled) |
void | setModificationTime(const QDateTime &mtime) |
(since 4.2.1) void | setTotalSize(KIO::filesize_t bytes) |
Signals
void | data(KIO::Job *job, const QByteArray &data) |
void | dataReq(KIO::Job *job, QByteArray &data) |
(since 5.78) void | mimeTypeFound(KIO::Job *job, const QString &mimeType) |
void | permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl) |
void | redirection(KIO::Job *job, const QUrl &url) |
Protected Slots
virtual void | slotData(const QByteArray &data) |
virtual void | slotDataReq() |
virtual void | slotMimetype(const QString &mimetype) |
virtual void | slotRedirection(const QUrl &url) |
Related Non-Members
KIO::TransferJob * | get(const QUrl &url, KIO::LoadType reload = NoReload, KIO::JobFlags flags = DefaultFlags) |
(since 4.7.3) KIO::TransferJob * | http_delete(const QUrl &url, KIO::JobFlags flags = DefaultFlags) |
KIO::TransferJob * | http_post(const QUrl &url, const QByteArray &postData, KIO::JobFlags flags = DefaultFlags) |
KIO::TransferJob * | http_post(const QUrl &url, QIODevice *device, qint64 size = -1, KIO::JobFlags flags = DefaultFlags) |
KIO::TransferJob * | put(const QUrl &url, int permissions, KIO::JobFlags flags = DefaultFlags) |
Detailed Description
Data is sent to the worker on request of the worker ( dataReq). If data coming from the worker can not be handled, the reading of data from the worker should be suspended.
Member Function Documentation
[signal]
void TransferJob::data(KIO::Job *job, const QByteArray &data)
Data from the worker has arrived.
job the job that emitted this signal
data data received from the worker.
End of data (EOD) has been reached if data.size() == 0, however, you should not be certain of data.size() == 0 ever happening (e.g. in case of an error), so you should rely on result() instead.
[signal]
void TransferJob::dataReq(KIO::Job *job, QByteArray &data)
Request for data.
Please note, that you shouldn't put too large chunks of data in it as this requires copies within the frame work, so you should rather split the data you want to pass here in reasonable chunks (about 1MB maximum)
job the job that emitted this signal
data buffer to fill with data to send to the worker. An empty buffer indicates end of data. (EOD)
[signal, since 5.78]
void TransferJob::mimeTypeFound(KIO::Job *job, const QString &mimeType)
MIME type determined.
job the job that emitted this signal
mimeType the MIME type
This function was introduced in 5.78.
QString TransferJob::mimetype() const
Call this in the slot connected to result, and only after making sure no error happened.
Returns the MIME type of the URL
[signal]
void TransferJob::permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl)
Signals a permanent redirection.
The redirection itself is handled internally.
job the job that emitted this signal
fromUrl the original URL
toUrl the new URL
[since 5.0]
QUrl TransferJob::redirectUrl() const
After the job has finished, it will return the final url in case a redirection has happened.
Returns the final url that can be empty in case no redirection has happened.
This function was introduced in 5.0.
[signal]
void TransferJob::redirection(KIO::Job *job, const QUrl &url)
Signals a redirection.
Use to update the URL shown to the user. The redirection itself is handled internally.
job the job that emitted this signal
url the new URL
void TransferJob::sendAsyncData(const QByteArray &data)
Provide data to the job when async data is enabled. Should be called exactly once after receiving a dataReq signal Sending an empty block indicates end of data.
void TransferJob::setAsyncDataEnabled(bool enabled)
Enable the async data mode. When async data is enabled, data should be provided to the job by calling sendAsyncData() instead of returning data in the dataReq() signal.
void TransferJob::setModificationTime(const QDateTime &mtime)
Sets the modification time of the file to be created (by KIO::put) Note that some KIO workers might ignore this.
[since 4.2.1]
void TransferJob::setTotalSize(KIO::filesize_t bytes)
Set the total size of data that we are going to send in a put job. Helps getting proper progress information.
This function was introduced in 4.2.1.
[virtual protected slot]
void TransferJob::slotData(const QByteArray &data)
[virtual protected slot]
void TransferJob::slotDataReq()
[virtual protected slot]
void TransferJob::slotMimetype(const QString &mimetype)
[virtual protected slot]
void TransferJob::slotRedirection(const QUrl &url)
Related Non-Members
KIO::TransferJob *get(const QUrl &url, KIO::LoadType reload = NoReload, KIO::JobFlags flags = DefaultFlags)
Get (means: read). This is the job to use in order to "download" a file into memory. The worker emits the data through the data() signal.
Special case: if you want to determine the MIME type of the file first, and then read it with the appropriate component, you can still use a KIO::get() directly. When that job emits the mimeType signal, (which is guaranteed to happen before it emits any data), put the job on hold:
job->putOnHold();
and forget about the job. The next time someone does a KIO::get() on the same URL (even in another process) this job will be resumed. This saves KIO from doing two requests to the server.
url the URL of the file
reload Reload to reload the file, NoReload if it can be taken from the cache
flags Can be HideProgressInfo here
Returns the job handling the operation.
[since 4.7.3]
KIO::TransferJob *http_delete(const QUrl &url, KIO::JobFlags flags = DefaultFlags)
HTTP DELETE.
Though this function servers the same purpose as KIO::file_delete, unlike file_delete it accommodates HTTP specific actions such as redirections.
url url resource to delete.
flags Can be HideProgressInfo here
Returns the job handling the operation.
This function was introduced in 4.7.3.
KIO::TransferJob *http_post(const QUrl &url, const QByteArray &postData, KIO::JobFlags flags = DefaultFlags)
HTTP POST (for form data).
Example:
job = KIO::http_post( url, postData, KIO::HideProgressInfo ); job->addMetaData("content-type", contentType );
postData is the data that you want to send and
contentType is the complete HTTP header line that specifies the content's MIME type, for example "Content-Type: text/xml".
You MUST specify content-type!
Often contentType is "Content-Type: application/x-www-form-urlencoded" and the postData is then an ASCII string (without null-termination!) with characters like space, linefeed and percent escaped like %20, %0A and %25.
url Where to write the data.
postData Encoded data to post.
flags Can be HideProgressInfo here
Returns the job handling the operation.
KIO::TransferJob *http_post(const QUrl &url, QIODevice *device, qint64 size = -1, KIO::JobFlags flags = DefaultFlags)
HTTP POST.
This function, unlike the one that accepts a QByteArray, accepts an IO device from which to read the encoded data to be posted to the server in order to to avoid holding the content of very large post requests, e.g. multimedia file uploads, in memory.
url Where to write the data.
device the device to read from
size Size of the encoded post data.
flags Can be HideProgressInfo here
Returns the job handling the operation.
KIO::TransferJob *put(const QUrl &url, int permissions, KIO::JobFlags flags = DefaultFlags)
Put (means: write)
url Where to write data.
permissions May be -1. In this case no special permission mode is set.
flags Can be HideProgressInfo, Overwrite and Resume here. WARNING: Setting Resume means that the data will be appended to dest if dest exists.
Returns the job handling the operation.
See also multi_get().