LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_FILEDOWNLOAD_H
21 #define LIBREPCB_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 
49 class FileDownload final : public NetworkRequestBase {
50  Q_OBJECT
51 
52 public:
53  // Constructors / Destructor
54  FileDownload() = delete;
55  FileDownload(const FileDownload& other) = delete;
56 
63  FileDownload(const QUrl& url, const FilePath& dest) noexcept;
64 
65  ~FileDownload() noexcept;
66 
67  // Setters
68 
79  void setExpectedChecksum(QCryptographicHash::Algorithm algorithm,
80  const QByteArray& checksum) noexcept;
81 
92  void setZipExtractionDirectory(const FilePath& dir) noexcept;
93 
94  // Operator Overloadings
95  FileDownload& operator=(const FileDownload& rhs) = delete;
96 
97 signals:
98 
107  void fileDownloaded(librepcb::FilePath filepath);
108 
117  void zipFileExtracted(librepcb::FilePath directory);
118 
119 private: // Methods
120  void prepareRequest() override;
121  void finalizeRequest() override;
122  void emitSuccessfullyFinishedSignals() noexcept override;
123  void fetchNewData() noexcept override;
124 
125 private: // Data
127  QScopedPointer<QSaveFile> mFile;
128  QCryptographicHash::Algorithm mHashAlgorithm;
129  QByteArray mExpectedChecksum;
131 };
132 
133 /*******************************************************************************
134  * End of File
135  ******************************************************************************/
136 
137 } // namespace librepcb
138 
139 #endif // LIBREPCB_FILEDOWNLOAD_H
QByteArray mExpectedChecksum
Definition: filedownload.h:129
This class is used to download a file asynchronously in a separate thread.
Definition: filedownload.h:49
void finalizeRequest() override
Definition: filedownload.cpp:96
void prepareRequest() override
Definition: filedownload.cpp:70
void emitSuccessfullyFinishedSignals() noexceptoverride
Definition: filedownload.cpp:154
FilePath mExtractZipToDir
Definition: filedownload.h:130
void setZipExtractionDirectory(const FilePath &dir) noexcept
Set extraction directory of the ZIP file to download.
Definition: filedownload.cpp:61
Base class for network requests which are processed in the network access manager.
Definition: networkrequestbase.h:60
QCryptographicHash::Algorithm mHashAlgorithm
Definition: filedownload.h:128
void fileDownloaded(librepcb::FilePath filepath)
File successfully downloaded signal (emited right before finished())
~FileDownload() noexcept
Definition: filedownload.cpp:47
void fetchNewData() noexceptoverride
Definition: filedownload.cpp:161
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void zipFileExtracted(librepcb::FilePath directory)
ZIP file successfully extracted signal (emited right before finished())
FilePath mDestination
Definition: filedownload.h:126
QScopedPointer< QSaveFile > mFile
Definition: filedownload.h:127
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:54