QGIS API Documentation  3.20.0-Odense (decaadbb31)
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_core.h"
25 
26 #ifndef QT_NO_SSL
27 #include <QSslError>
28 #endif
29 
45 class CORE_EXPORT QgsFileDownloader : public QObject
46 {
47  Q_OBJECT
48  public:
49 
60  QgsFileDownloader( const QUrl &url, const QString &outputFileName, const QString &authcfg = QString(), bool delayStart = false );
61 
62  signals:
64  void downloadCompleted( const QUrl &url );
67 
73 
75  void downloadError( QStringList errorMessages );
77  void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
78 
79  public slots:
80 
86  void cancelDownload();
87 
89  void startDownload();
90 
91  private slots:
93  void onReadyRead();
95  void onFinished();
97  void onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
99  void onRequestTimedOut( QNetworkReply *reply );
100 
101 #ifndef QT_NO_SSL
102 
108  void onSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
109 #endif
110 
111  protected:
112  ~QgsFileDownloader() override;
113 
114  private:
115 
120  void error( const QStringList &errorMessages );
121  void error( const QString &errorMessage );
122  QUrl mUrl;
123  QNetworkReply *mReply = nullptr;
124  QFile mFile;
125  bool mDownloadCanceled;
126  QStringList mErrors;
127  QString mAuthCfg;
128 };
129 
130 #endif // QGSFILEDOWNLOADER_H
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.