QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgis_core.h"
23 
24 #ifndef QT_NO_SSL
25 #include <QSslError>
26 #endif
27 
43 class CORE_EXPORT QgsFileDownloader : public QObject
44 {
45  Q_OBJECT
46  public:
47 
58  QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg = QString(), bool delayStart = false );
59 
60  signals:
65 
71 
73  void downloadError( QStringList errorMessages );
75  void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
76 
77  public slots:
78 
84  void cancelDownload();
85 
87  void startDownload();
88 
89  private slots:
91  void onReadyRead();
93  void onFinished();
95  void onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
97  void onRequestTimedOut( QNetworkReply *reply );
98 
99 #ifndef QT_NO_SSL
100 
106  void onSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
107 #endif
108 
109  protected:
110  ~QgsFileDownloader() override;
111 
112  private:
113 
118  void error( const QStringList &errorMessages );
119  void error( const QString &errorMessage );
120  QUrl mUrl;
121  QNetworkReply *mReply = nullptr;
122  QFile mFile;
123  bool mDownloadCanceled;
124  QStringList mErrors;
125  QString mAuthCfg;
126 };
127 
128 #endif // QGSFILEDOWNLOADER_H
QgsFileDownloader
QgsFileDownloader is a utility class for downloading files.
Definition: qgsfiledownloader.h:44
QgsFileDownloader::downloadExited
void downloadExited()
Emitted always when the downloader exits.
QgsFileDownloader::downloadProgress
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
Emitted when data are ready to be processed.
QgsFileDownloader::downloadCanceled
void downloadCanceled()
Emitted when the download was canceled by the user.
QgsFileDownloader::downloadError
void downloadError(QStringList errorMessages)
Emitted when an error makes the download fail.
QgsFileDownloader::downloadCompleted
void downloadCompleted()
Emitted when the download has completed successfully.