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 
47 class LibraryDownload final : public QObject {
48  Q_OBJECT
49 
50 public:
51  // Constructors / Destructor
52  LibraryDownload() = delete;
53  LibraryDownload(const LibraryDownload& other) = delete;
54  LibraryDownload(const QUrl& urlToZip, const FilePath& destDir) noexcept;
55  ~LibraryDownload() noexcept;
56 
57  // Getters
58  const FilePath& getDestinationDir() const noexcept { return mDestDir; }
59 
60  // Setters
61 
65  void setExpectedZipFileSize(qint64 bytes) noexcept;
66 
70  void setExpectedChecksum(QCryptographicHash::Algorithm algorithm,
71  const QByteArray& checksum) noexcept;
72 
73  // Operator Overloadings
74  LibraryDownload& operator=(const LibraryDownload& rhs) = delete;
75 
76 public slots:
77 
81  void start() noexcept;
82 
86  void abort() noexcept;
87 
88 signals:
89 
90  void progressState(const QString& status);
91  void progressPercent(int percent);
92  void finished(bool success, const QString& errMsg);
93  void abortRequested(); // internal signal!
94 
95 private: // Methods
96  void downloadErrored(const QString& errMsg) noexcept;
97  void downloadAborted() noexcept;
98  void downloadSucceeded() noexcept;
99  FilePath getPathToLibDir() noexcept;
100 
101 private: // Data
102  QScopedPointer<FileDownload> mFileDownload;
105 };
106 
107 /*******************************************************************************
108  * End of File
109  ******************************************************************************/
110 
111 } // namespace manager
112 } // namespace library
113 } // namespace librepcb
114 
115 #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:46
LibraryDownload & operator=(const LibraryDownload &rhs)=delete
const FilePath & getDestinationDir() const noexcept
Definition: librarydownload.h:58
void progressState(const QString &status)
FilePath mTempDestDir
Definition: librarydownload.h:104
void start() noexcept
Start downloading the library.
Definition: librarydownload.cpp:94
FilePath mDestDir
Definition: librarydownload.h:103
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:127
void downloadAborted() noexcept
Definition: librarydownload.cpp:125
QScopedPointer< FileDownload > mFileDownload
Definition: librarydownload.h:102
void abort() noexcept
Abort downloading the library.
Definition: librarydownload.cpp:113
The LibraryDownload class.
Definition: librarydownload.h:47
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)