20#include "moc_qgsnetworkcontentfetchertask.cpp"
31 :
QgsTask( description.isEmpty() ? tr(
"Fetching %1" ).arg( request.url().toString() ) : description, flags )
40 mFetcher->deleteLater();
57 const int progress = ( bytesReceived * 100 ) / bytesTotal;
66 bool hasErrorOccurred =
false;
69 hasErrorOccurred =
true;
92 return mFetcher ? mFetcher->
reply() :
nullptr;
Handles HTTP network content fetching in a background task.
bool run() override
Performs the task's operation.
QString contentAsString() const
Returns the fetched content as a string.
QString contentDispositionFilename() const
Returns the associated filename from the reply's content disposition header, if present.
void fetched()
Emitted when the network content has been fetched, regardless of whether the fetch was successful or ...
~QgsNetworkContentFetcherTask() override
QNetworkReply * reply()
Returns the network reply.
void cancel() override
Notifies the task that it should terminate.
void errorOccurred(QNetworkReply::NetworkError code, const QString &errorMsg)
Emitted when an error with code error occurred while processing the request errorMsg is a textual des...
QgsNetworkContentFetcherTask(const QUrl &url, const QString &authcfg=QString(), QgsTask::Flags flags=QgsTask::CanCancel, const QString &description=QString())
Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.
HTTP network content fetcher.
QString contentDispositionFilename() const
Returns the associated filename from the reply's content disposition header, if present.
void finished()
Emitted when content has loaded.
void errorOccurred(QNetworkReply::NetworkError code, const QString &errorMsg)
Emitted when an error with code error occurred while processing the request errorMsg is a textual des...
void cancel()
Cancels any ongoing request.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data is received.
QNetworkReply * reply()
Returns a reference to the network reply.
QString contentAsString() const
Returns the fetched content as a string.
void fetchContent(const QUrl &url, const QString &authcfg=QString())
Fetches content from a remote URL and handles redirects.
Abstract base class for long running background tasks.
double progress() const
Returns the task's progress (between 0.0 and 100.0)
virtual void cancel()
Notifies the task that it should terminate.
bool isCanceled() const
Will return true if task should terminate ASAP.
void setProgress(double progress)
Sets the task's current progress.