QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
46 class CORE_EXPORT QgsFileDownloader : public QObject
47 {
48  Q_OBJECT
49  public:
50 
63  QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg = QString(), bool delayStart = false, Qgis::HttpMethod httpMethod = Qgis::HttpMethod::Get, const QByteArray &data = QByteArray() );
64 
65  signals:
67  void downloadCompleted( const QUrl &url );
69  void downloadExited();
70 
75  void downloadCanceled();
76 
78  void downloadError( QStringList errorMessages );
80  void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
81 
82  public slots:
83 
89  void cancelDownload();
90 
92  void startDownload();
93 
94  private slots:
96  void onReadyRead();
98  void onFinished();
100  void onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
102  void onRequestTimedOut( QNetworkReply *reply );
103 
104 #ifndef QT_NO_SSL
105 
111  void onSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
112 #endif
113 
114  protected:
115  ~QgsFileDownloader() override;
116 
117  private:
118 
123  void error( const QStringList &errorMessages );
124  void error( const QString &errorMessage );
125  QUrl mUrl;
126  QNetworkReply *mReply = nullptr;
127  QFile mFile;
128  bool mDownloadCanceled;
130  QByteArray mData;
131  QStringList mErrors;
132  QString mAuthCfg;
133 };
134 
135 #endif // QGSFILEDOWNLOADER_H
Qgis::HttpMethod
HttpMethod
Different methods of HTTP requests.
Definition: qgis.h:437
QgsFileDownloader
QgsFileDownloader is a utility class for downloading files.
Definition: qgsfiledownloader.h:46
qgis.h
Qgis::HttpMethod::Get
@ Get
GET method.