QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsnetworkcontentfetchertask.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsnetworkcontentfetchertask.h
3 -------------------
4 begin : March, 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19
20#ifndef QGSNETWORKCONTENTFETCHERTASK_H
21#define QGSNETWORKCONTENTFETCHERTASK_H
22
23#include "qgis_core.h"
24#include "qgshttpheaders.h"
25#include "qgstaskmanager.h"
26
27#include <QNetworkReply>
28#include <QNetworkRequest>
29
31
49class CORE_EXPORT QgsNetworkContentFetcherTask : public QgsTask
50{
51 Q_OBJECT
52
53 public:
54
65 QgsNetworkContentFetcherTask( const QUrl &url, const QString &authcfg = QString(), QgsTask::Flags flags = QgsTask::CanCancel,
66 const QString &description = QString(), const QgsHttpHeaders &headers = QgsHttpHeaders() );
67
78 QgsNetworkContentFetcherTask( const QNetworkRequest &request, const QString &authcfg = QString(), QgsTask::Flags flags = QgsTask::CanCancel,
79 const QString &description = QString(), const QgsHttpHeaders &headers = QgsHttpHeaders() );
80
82
83 bool run() override;
84 void cancel() override;
85
94 QNetworkReply *reply();
95
101 QString contentDispositionFilename() const;
102
111 QString contentAsString() const;
112
113 signals:
114
123 void fetched();
124
130 void errorOccurred( QNetworkReply::NetworkError code, const QString &errorMsg );
131
132 private:
133
134 QNetworkRequest mRequest;
135 QString mAuthcfg;
136 QgsNetworkContentFetcher *mFetcher = nullptr;
137 QString mMode;
138 QgsHttpHeaders mHeaders;
139};
140
141#endif //QGSNETWORKCONTENTFETCHERTASK_H
Implements simple HTTP header management.
QgsNetworkContentFetcherTask(const QUrl &url, const QString &authcfg=QString(), QgsTask::Flags flags=QgsTask::CanCancel, const QString &description=QString(), const QgsHttpHeaders &headers=QgsHttpHeaders())
Constructor for a QgsNetworkContentFetcherTask which fetches the specified url.
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 ...
QNetworkReply * reply()
Returns the network reply.
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...
HTTP network content fetcher.
Flags flags() const
Returns the flags associated with the task.
virtual bool run()=0
Performs the task's operation.
QFlags< Flag > Flags
virtual void cancel()
Notifies the task that it should terminate.
QgsTask(const QString &description=QString(), QgsTask::Flags flags=AllFlags)
Constructor for QgsTask.
@ CanCancel
Task can be canceled.
QString description() const
Returns the task's description.