| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | #ifndef WSJTX_FILEDOWNLOAD_H
 | 
					
						
							|  |  |  | #define WSJTX_FILEDOWNLOAD_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QObject>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  | #include <QPointer>
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | #include <QtNetwork/QNetworkAccessManager>
 | 
					
						
							|  |  |  | #include <QtNetwork/QNetworkReply>
 | 
					
						
							|  |  |  | #include <QTemporaryFile>
 | 
					
						
							| 
									
										
										
										
											2023-03-16 19:13:59 -07:00
										 |  |  | #include <QSaveFile>
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class FileDownload : public QObject { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     explicit FileDownload(); | 
					
						
							|  |  |  |     ~FileDownload(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |     void configure(QNetworkAccessManager *network_manager, const QString& source_url, const QString& destination_filename, const QString& user_agent); | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QNetworkAccessManager *manager_; | 
					
						
							|  |  |  |     QString source_url_; | 
					
						
							|  |  |  |     QString destination_filename_; | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |     QString user_agent_; | 
					
						
							|  |  |  |     QPointer<QNetworkReply> reply_; | 
					
						
							|  |  |  |     QNetworkRequest request_; | 
					
						
							| 
									
										
										
										
											2023-03-16 19:13:59 -07:00
										 |  |  |     QSaveFile destfile_; | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |     bool url_valid_; | 
					
						
							|  |  |  |     int redirect_count_; | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | signals: | 
					
						
							|  |  |  |             void complete(QString filename); | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |             void progress(QString filename); | 
					
						
							|  |  |  |             void load_finished() const; | 
					
						
							|  |  |  |             void download_error (QString const& reason) const; | 
					
						
							|  |  |  |             void error(QString const& reason) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public slots: | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |     void start_download(); | 
					
						
							|  |  |  |     void download(QUrl url); | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  |     void store(); | 
					
						
							| 
									
										
										
										
											2023-03-15 20:42:03 -07:00
										 |  |  |     void abort(); | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  |     void downloadComplete(QNetworkReply* data); | 
					
						
							|  |  |  |     void downloadProgress(qint64 recieved, qint64 total); | 
					
						
							| 
									
										
										
										
											2023-03-17 07:52:03 -07:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  |     void errorOccurred(QNetworkReply::NetworkError code); | 
					
						
							| 
									
										
										
										
											2023-03-17 07:52:03 -07:00
										 |  |  | #else
 | 
					
						
							|  |  |  |     void obsoleteError(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2023-03-09 12:10:20 -08:00
										 |  |  |     void replyComplete(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif //WSJTX_FILEDOWNLOAD_H
 |