QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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:
62  void downloadCompleted();
64  void downloadExited();
65 
70  void downloadCanceled();
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 is a utility class for downloading files.