1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013, 2014 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 #include <QDialog> |
|
21 #include "Main.h" |
|
22 #include "Types.h" |
|
23 |
|
24 class LDDocument; |
|
25 class QFile; |
|
26 class PartDownloadRequest; |
|
27 class Ui_DownloadFrom; |
|
28 class QNetworkAccessManager; |
|
29 class QNetworkRequest; |
|
30 class QNetworkReply; |
|
31 class QAbstractButton; |
|
32 |
|
33 // ============================================================================= |
|
34 // |
|
35 class PartDownloader : public QDialog |
|
36 { |
|
37 public: |
|
38 enum Source |
|
39 { |
|
40 PartsTracker, |
|
41 CustomURL, |
|
42 }; |
|
43 |
|
44 enum Button |
|
45 { |
|
46 Download, |
|
47 Abort, |
|
48 Close |
|
49 }; |
|
50 |
|
51 enum TableColumn |
|
52 { |
|
53 PartLabelColumn, |
|
54 ProgressColumn, |
|
55 }; |
|
56 |
|
57 using RequestList = QList<PartDownloadRequest*>; |
|
58 |
|
59 Q_OBJECT |
|
60 PROPERTY (public, LDDocument*, primaryFile, setPrimaryFile, STOCK_WRITE) |
|
61 PROPERTY (public, bool, isAborted, setAborted, STOCK_WRITE) |
|
62 PROPERTY (private, Ui_DownloadFrom*, interface, setInterface, STOCK_WRITE) |
|
63 PROPERTY (private, QStringList, filesToDownload, setFilesToDownload, STOCK_WRITE) |
|
64 PROPERTY (private, RequestList, requests, setRequests, STOCK_WRITE) |
|
65 PROPERTY (private, QPushButton*, downloadButton, setDownloadButton, STOCK_WRITE) |
|
66 |
|
67 public: |
|
68 explicit PartDownloader (QWidget* parent = null); |
|
69 virtual ~PartDownloader(); |
|
70 |
|
71 void downloadFile (QString dest, QString url, bool primary); |
|
72 QPushButton* getButton (Button i); |
|
73 QString getURL() const; |
|
74 Source getSource() const; |
|
75 void modifyDestination (QString& dest) const; |
|
76 |
|
77 static QString getDownloadPath(); |
|
78 static void staticBegin(); |
|
79 |
|
80 public slots: |
|
81 void buttonClicked (QAbstractButton* btn); |
|
82 void checkIfFinished(); |
|
83 void sourceChanged (int i); |
|
84 }; |
|
85 |
|
86 // ============================================================================= |
|
87 // |
|
88 class PartDownloadRequest : public QObject |
|
89 { |
|
90 public: |
|
91 enum EState |
|
92 { |
|
93 ERequesting, |
|
94 EDownloading, |
|
95 EFinished, |
|
96 EFailed, |
|
97 }; |
|
98 |
|
99 Q_OBJECT |
|
100 PROPERTY (public, int, tableRow, setTableRow, STOCK_WRITE) |
|
101 PROPERTY (private, EState, state, setState, STOCK_WRITE) |
|
102 PROPERTY (private, PartDownloader*, prompt, setPrompt, STOCK_WRITE) |
|
103 PROPERTY (private, QString, url, setURL, STOCK_WRITE) |
|
104 PROPERTY (private, QString, destinaton, setDestination, STOCK_WRITE) |
|
105 PROPERTY (private, QString, filePath, setFilePath, STOCK_WRITE) |
|
106 PROPERTY (private, QNetworkAccessManager*, networkManager, setNetworkManager, STOCK_WRITE) |
|
107 PROPERTY (private, QNetworkReply*, networkReply, setNetworkReply, STOCK_WRITE) |
|
108 PROPERTY (private, bool, isFirstUpdate, setFirstUpdate, STOCK_WRITE) |
|
109 PROPERTY (private, int64, numBytesRead, setNumBytesRead, STOCK_WRITE) |
|
110 PROPERTY (private, int64, numBytesTotal, setNumBytesTotal, STOCK_WRITE) |
|
111 PROPERTY (private, bool, isPrimary, setPrimary, STOCK_WRITE) |
|
112 PROPERTY (private, QFile*, filePointer, setFilePointer, STOCK_WRITE) |
|
113 |
|
114 public: |
|
115 explicit PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent); |
|
116 PartDownloadRequest (const PartDownloadRequest&) = delete; |
|
117 virtual ~PartDownloadRequest(); |
|
118 void updateToTable(); |
|
119 bool isFinished() const; |
|
120 void operator= (const PartDownloadRequest&) = delete; |
|
121 |
|
122 public slots: |
|
123 void downloadFinished(); |
|
124 void readyRead(); |
|
125 void downloadProgress (qint64 recv, qint64 total); |
|
126 void abort(); |
|
127 }; |
|