QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
qgsfiledownloader.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfiledownloader.h
3 --------------------------------------
4 Date : November 2016
5 Copyright : (C) 2016 by Alessandro Pasotti
6 Email : apasotti at boundlessgeo dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSFILEDOWNLOADER_H
17#define QGSFILEDOWNLOADER_H
18
19#include <QObject>
20#include <QFile>
21#include <QNetworkReply>
22#include <QUrl>
23
24#include "qgis.h"
25#include "qgis_core.h"
26
27#ifndef QT_NO_SSL
28#include <QSslError>
29#endif
30
45class CORE_EXPORT QgsFileDownloader : public QObject
46{
47 Q_OBJECT
48 public:
49
62 QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg = QString(), bool delayStart = false, Qgis::HttpMethod httpMethod = Qgis::HttpMethod::Get, const QByteArray &data = QByteArray() );
63
64 signals:
66 void downloadCompleted( const QUrl &url );
69
75
77 void downloadError( QStringList errorMessages );
79 void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
80
81 public slots:
82
88 void cancelDownload();
89
91 void startDownload();
92
93 private slots:
95 void onReadyRead();
97 void onFinished();
99 void onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
101 void onRequestTimedOut( QNetworkReply *reply );
102
103#ifndef QT_NO_SSL
104
110 void onSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
111#endif
112
113 protected:
114 ~QgsFileDownloader() override;
115
116 private:
117
122 void error( const QStringList &errorMessages );
123 void error( const QString &errorMessage );
124 QUrl mUrl;
125 QNetworkReply *mReply = nullptr;
126 QFile mFile;
127 bool mDownloadCanceled;
129 QByteArray mData;
130 QStringList mErrors;
131 QString mAuthCfg;
132};
133
134#endif // QGSFILEDOWNLOADER_H
HttpMethod
Different methods of HTTP requests.
Definition qgis.h:791
@ Get
GET method.
QgsFileDownloader is a utility class for downloading files.
void downloadExited()
Emitted always when the downloader exits.
void downloadCanceled()
Emitted when the download was canceled by the user.
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
void downloadCompleted(const QUrl &url)
Emitted when the download has completed successfully.
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.