QGIS API Documentation  3.23.0-Master (7c4a6de034)
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 );
70 
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
HttpMethod
Different methods of HTTP requests.
Definition: qgis.h:349
@ 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.