LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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 ******************************************************************************/
34namespace librepcb {
35
36/*******************************************************************************
37 * Class FileDownload
38 ******************************************************************************/
39
46class FileDownload final : public NetworkRequestBase {
47 Q_OBJECT
48
49public:
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
94signals:
95
105
115
116private: // Methods
117 void prepareRequest() override;
118 void finalizeRequest() override;
119 void emitSuccessfullyFinishedSignals(QString contentType) noexcept override;
120 void fetchNewData(QIODevice& device) noexcept override;
121
122private: // Data
124 QScopedPointer<QSaveFile> mFile;
125 QCryptographicHash::Algorithm mHashAlgorithm;
128};
129
130/*******************************************************************************
131 * End of File
132 ******************************************************************************/
133
134} // namespace librepcb
135
136#endif
This class is used to download a file asynchronously in a separate thread.
Definition filedownload.h:46
void prepareRequest() override
Definition filedownload.cpp:72
void setZipExtractionDirectory(const FilePath &dir) noexcept
Set extraction directory of the ZIP file to download.
Definition filedownload.cpp:63
FilePath mDestination
Definition filedownload.h:123
void fileDownloaded(librepcb::FilePath filepath)
File successfully downloaded signal (emitted right before finished())
FileDownload(const FileDownload &other)=delete
FilePath mExtractZipToDir
Definition filedownload.h:127
void setExpectedChecksum(QCryptographicHash::Algorithm algorithm, const QByteArray &checksum) noexcept
Set the expected checksum of the file to download.
Definition filedownload.cpp:56
QScopedPointer< QSaveFile > mFile
Definition filedownload.h:124
void fetchNewData(QIODevice &device) noexcept override
Definition filedownload.cpp:165
QCryptographicHash::Algorithm mHashAlgorithm
Definition filedownload.h:125
void finalizeRequest() override
Definition filedownload.cpp:98
QByteArray mExpectedChecksum
Definition filedownload.h:126
void emitSuccessfullyFinishedSignals(QString contentType) noexcept override
Definition filedownload.cpp:156
~FileDownload() noexcept
Definition filedownload.cpp:49
void zipFileExtracted(librepcb::FilePath directory)
ZIP file successfully extracted signal (emitted right before finished())
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
Base class for network requests which are processed in the network access manager.
Definition networkrequestbase.h:57
Definition occmodel.cpp:76