QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <QProgressDialog>
23 #ifndef QT_NO_OPENSSL
24 #include <QSslError>
25 #endif
26 
41 class GUI_EXPORT QgsFileDownloader : public QObject
42 {
43  Q_OBJECT
44  public:
51  QgsFileDownloader( QUrl url, QString outputFileName, bool guiNotificationsEnabled = true );
52 
53  signals:
55  void downloadCompleted();
57  void downloadExited();
59  void downloadCanceled();
61  void downloadError( QStringList errorMessages );
63  void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
64 
65  public slots:
71  void onDownloadCanceled();
72 
73  private slots:
75  void onReadyRead();
77  void onFinished();
79  void onDownloadProgress( qint64 bytesReceived, qint64 bytesTotal );
81  void onRequestTimedOut();
83  void startDownload();
84 #ifndef QT_NO_OPENSSL
85 
90  void onSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
91 #endif
92 
93  protected:
95 
96  private:
101  void error( QStringList errorMessages );
102  void error( QString errorMessage );
103  QUrl mUrl;
104  QNetworkReply* mReply;
105  QFile mFile;
106  QProgressDialog* mProgressDialog;
107  bool mDownloadCanceled;
108  QStringList mErrors;
109  bool mGuiNotificationsEnabled;
110 };
111 
112 #endif // QGSFILEDOWNLOADER_H
QgsFileDownloader is a utility class for downloading files.