LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
librarydownload.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_WORKSPACE_LIBRARYDOWNLOAD_H
21 #define LIBREPCB_WORKSPACE_LIBRARYDOWNLOAD_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 
35 class FileDownload;
36 
37 namespace library {
38 namespace manager {
39 
40 /*******************************************************************************
41  * Class LibraryDownload
42  ******************************************************************************/
43 
50 class LibraryDownload final : public QObject {
51  Q_OBJECT
52 
53 public:
54  // Constructors / Destructor
55  LibraryDownload() = delete;
56  LibraryDownload(const LibraryDownload& other) = delete;
57  LibraryDownload(const QUrl& urlToZip, const FilePath& destDir) noexcept;
58  ~LibraryDownload() noexcept;
59 
60  // Getters
61  const FilePath& getDestinationDir() const noexcept { return mDestDir; }
62 
63  // Setters
64 
68  void setExpectedZipFileSize(qint64 bytes) noexcept;
69 
73  void setExpectedChecksum(QCryptographicHash::Algorithm algorithm,
74  const QByteArray& checksum) noexcept;
75 
76  // Operator Overloadings
77  LibraryDownload& operator=(const LibraryDownload& rhs) = delete;
78 
79 public slots:
80 
84  void start() noexcept;
85 
89  void abort() noexcept;
90 
91 signals:
92 
93  void progressState(const QString& status);
94  void progressPercent(int percent);
95  void finished(bool success, const QString& errMsg);
96  void abortRequested(); // internal signal!
97 
98 private: // Methods
99  void downloadErrored(const QString& errMsg) noexcept;
100  void downloadAborted() noexcept;
101  void downloadSucceeded() noexcept;
102  FilePath getPathToLibDir() noexcept;
103 
104 private: // Data
105  QScopedPointer<FileDownload> mFileDownload;
108 };
109 
110 /*******************************************************************************
111  * End of File
112  ******************************************************************************/
113 
114 } // namespace manager
115 } // namespace library
116 } // namespace librepcb
117 
118 #endif // LIBREPCB_WORKSPACE_LIBRARYDOWNLOAD_H
void downloadErrored(const QString &errMsg) noexcept
Definition: librarydownload.cpp:121
This class is used to download a file asynchronously in a separate thread.
Definition: filedownload.h:49
LibraryDownload & operator=(const LibraryDownload &rhs)=delete
const FilePath & getDestinationDir() const noexcept
Definition: librarydownload.h:61
void progressState(const QString &status)
FilePath mTempDestDir
Definition: librarydownload.h:107
void start() noexcept
Start downloading the library.
Definition: librarydownload.cpp:94
FilePath mDestDir
Definition: librarydownload.h:106
void setExpectedZipFileSize(qint64 bytes) noexcept
Set the expected size of the requested content.
Definition: librarydownload.cpp:72
void downloadSucceeded() noexcept
Definition: librarydownload.cpp:129
~LibraryDownload() noexcept
Definition: librarydownload.cpp:64
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
void downloadAborted() noexcept
Definition: librarydownload.cpp:125
QScopedPointer< FileDownload > mFileDownload
Definition: librarydownload.h:105
void abort() noexcept
Abort downloading the library.
Definition: librarydownload.cpp:113
The LibraryDownload class.
Definition: librarydownload.h:50
void setExpectedChecksum(QCryptographicHash::Algorithm algorithm, const QByteArray &checksum) noexcept
Definition: librarydownload.cpp:80
FilePath getPathToLibDir() noexcept
Definition: librarydownload.cpp:182
void finished(bool success, const QString &errMsg)