LibrePCB Developers Documentation
filedownload.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_CORE_FILEDOWNLOAD_H
21 #define LIBREPCB_CORE_FILEDOWNLOAD_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/filepath.h"
27 #include "networkrequestbase.h"
28 
29 #include <QtCore>
30 
31 /*******************************************************************************
32  * Namespace / Forward Declarations
33  ******************************************************************************/
34 namespace librepcb {
35 
36 /*******************************************************************************
37  * Class FileDownload
38  ******************************************************************************/
39 
46 class FileDownload final : public NetworkRequestBase {
47  Q_OBJECT
48 
49 public:
50  // Constructors / Destructor
51  FileDownload() = delete;
52  FileDownload(const FileDownload& other) = delete;
53 
60  FileDownload(const QUrl& url, const FilePath& dest) noexcept;
61 
62  ~FileDownload() noexcept;
63 
64  // Setters
65 
76  void setExpectedChecksum(QCryptographicHash::Algorithm algorithm,
77  const QByteArray& checksum) noexcept;
78 
89  void setZipExtractionDirectory(const FilePath& dir) noexcept;
90 
91  // Operator Overloadings
92  FileDownload& operator=(const FileDownload& rhs) = delete;
93 
94 signals:
95 
104  void fileDownloaded(librepcb::FilePath filepath);
105 
114  void zipFileExtracted(librepcb::FilePath directory);
115 
116 private: // Methods
117  void prepareRequest() override;
118  void finalizeRequest() override;
119  void emitSuccessfullyFinishedSignals() noexcept override;
120  void fetchNewData() noexcept override;
121 
122 private: // Data
124  QScopedPointer<QSaveFile> mFile;
125  QCryptographicHash::Algorithm mHashAlgorithm;
126  QByteArray mExpectedChecksum;
128 };
129 
130 /*******************************************************************************
131  * End of File
132  ******************************************************************************/
133 
134 } // namespace librepcb
135 
136 #endif
QByteArray mExpectedChecksum
Definition: filedownload.h:126
This class is used to download a file asynchronously in a separate thread.
Definition: filedownload.h:46
Definition: occmodel.cpp:76
void finalizeRequest() override
Definition: filedownload.cpp:97
void prepareRequest() override
Definition: filedownload.cpp:71
FilePath mExtractZipToDir
Definition: filedownload.h:127
void setZipExtractionDirectory(const FilePath &dir) noexcept
Set extraction directory of the ZIP file to download.
Definition: filedownload.cpp:62
Base class for network requests which are processed in the network access manager.
Definition: networkrequestbase.h:55
QCryptographicHash::Algorithm mHashAlgorithm
Definition: filedownload.h:125
void fetchNewData() noexcept override
Definition: filedownload.cpp:162
void fileDownloaded(librepcb::FilePath filepath)
File successfully downloaded signal (emitted right before finished())
~FileDownload() noexcept
Definition: filedownload.cpp:48
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
void emitSuccessfullyFinishedSignals() noexcept override
Definition: filedownload.cpp:155
void zipFileExtracted(librepcb::FilePath directory)
ZIP file successfully extracted signal (emitted right before finished())
FilePath mDestination
Definition: filedownload.h:123
QScopedPointer< QSaveFile > mFile
Definition: filedownload.h:124
FileDownload & operator=(const FileDownload &rhs)=delete
void setExpectedChecksum(QCryptographicHash::Algorithm algorithm, const QByteArray &checksum) noexcept
Set the expected checksum of the file to download.
Definition: filedownload.cpp:55