| 32 class QNetworkReply; |
32 class QNetworkReply; |
| 33 class QAbstractButton; |
33 class QAbstractButton; |
| 34 |
34 |
| 35 // ============================================================================= |
35 // ============================================================================= |
| 36 // ----------------------------------------------------------------------------- |
36 // ----------------------------------------------------------------------------- |
| 37 extern class PartDownloader { |
37 class PartDownloader : public QDialog { |
| 38 public: |
|
| 39 constexpr static const char* k_OfficialURL = "http://ldraw.org/library/official/", |
|
| 40 *k_UnofficialURL = "http://ldraw.org/library/unofficial/"; |
|
| 41 |
|
| 42 PartDownloader() {} |
|
| 43 void download(); |
|
| 44 static str getDownloadPath(); |
|
| 45 void operator()() { download(); } |
|
| 46 } g_PartDownloader; |
|
| 47 |
|
| 48 // ============================================================================= |
|
| 49 // ----------------------------------------------------------------------------- |
|
| 50 class PartDownloadPrompt : public QDialog { |
|
| 51 Q_OBJECT |
38 Q_OBJECT |
| 52 PROPERTY (LDFile*, primaryFile, setPrimaryFile) |
39 PROPERTY (LDFile*, primaryFile, setPrimaryFile) |
| 53 PROPERTY (bool, aborted, setAborted) |
40 PROPERTY (bool, aborted, setAborted) |
| 54 |
41 |
| 55 public: |
42 public: |
| |
43 constexpr static const char* k_OfficialURL = "http://ldraw.org/library/official/", |
| |
44 *k_UnofficialURL = "http://ldraw.org/library/unofficial/"; |
| |
45 |
| 56 enum Source { |
46 enum Source { |
| 57 PartsTracker, |
47 PartsTracker, |
| 58 CustomURL, |
48 CustomURL, |
| 59 }; |
49 }; |
| 60 |
50 |
| 62 Download, |
52 Download, |
| 63 Abort, |
53 Abort, |
| 64 Close |
54 Close |
| 65 }; |
55 }; |
| 66 |
56 |
| 67 explicit PartDownloadPrompt (QWidget* parent = null); |
57 enum TableColumn { |
| 68 virtual ~PartDownloadPrompt(); |
58 PartLabelColumn, |
| |
59 ProgressColumn, |
| |
60 }; |
| |
61 |
| |
62 explicit PartDownloader (QWidget* parent = null); |
| |
63 virtual ~PartDownloader(); |
| 69 str getURL() const; |
64 str getURL() const; |
| |
65 static str getDownloadPath(); |
| 70 Source getSource() const; |
66 Source getSource() const; |
| 71 void downloadFile (str dest, str url, bool primary); |
67 void downloadFile (str dest, str url, bool primary); |
| 72 void modifyDest (str& dest) const; |
68 void modifyDest (str& dest) const; |
| 73 QPushButton* getButton (Button i); |
69 QPushButton* getButton (Button i); |
| |
70 static void k_download(); |
| 74 |
71 |
| 75 public slots: |
72 public slots: |
| 76 void sourceChanged (int i); |
73 void sourceChanged (int i); |
| 77 void checkIfFinished(); |
74 void checkIfFinished(); |
| 78 void buttonClicked (QAbstractButton* btn); |
75 void buttonClicked (QAbstractButton* btn); |
| 92 class PartDownloadRequest : public QObject { |
89 class PartDownloadRequest : public QObject { |
| 93 Q_OBJECT |
90 Q_OBJECT |
| 94 PROPERTY (int, tableRow, setTableRow) |
91 PROPERTY (int, tableRow, setTableRow) |
| 95 |
92 |
| 96 public: |
93 public: |
| 97 enum TableColumn { |
|
| 98 PartLabelColumn, |
|
| 99 ProgressColumn, |
|
| 100 }; |
|
| 101 |
|
| 102 enum State { |
94 enum State { |
| 103 Requesting, |
95 Requesting, |
| 104 Downloading, |
96 Downloading, |
| 105 Finished, |
97 Finished, |
| 106 Failed, |
98 Failed, |
| 107 }; |
99 }; |
| 108 |
100 |
| 109 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloadPrompt* parent); |
101 explicit PartDownloadRequest (str url, str dest, bool primary, PartDownloader* parent); |
| 110 PartDownloadRequest (const PartDownloadRequest&) = delete; |
102 PartDownloadRequest (const PartDownloadRequest&) = delete; |
| 111 virtual ~PartDownloadRequest(); |
103 virtual ~PartDownloadRequest(); |
| 112 void updateToTable(); |
104 void updateToTable(); |
| 113 bool isFinished() const; |
105 bool isFinished() const; |
| 114 const State& state() const; |
106 const State& state() const; |
| 120 void readyRead(); |
112 void readyRead(); |
| 121 void downloadProgress (qint64 recv, qint64 total); |
113 void downloadProgress (qint64 recv, qint64 total); |
| 122 void abort(); |
114 void abort(); |
| 123 |
115 |
| 124 private: |
116 private: |
| 125 PartDownloadPrompt* m_prompt; |
117 PartDownloader* m_prompt; |
| 126 str m_url, m_dest, m_fpath; |
118 str m_url, m_dest, m_fpath; |
| 127 QNetworkAccessManager* m_nam; |
119 QNetworkAccessManager* m_nam; |
| 128 QNetworkReply* m_reply; |
120 QNetworkReply* m_reply; |
| 129 bool m_firstUpdate; |
121 bool m_firstUpdate; |
| 130 State m_state; |
122 State m_state; |