24 #include <QProgressBar> |
24 #include <QProgressBar> |
25 #include <QLabel> |
25 #include <QLabel> |
26 #include "partdownloader.h" |
26 #include "partdownloader.h" |
27 #include "partdownloadrequest.h" |
27 #include "partdownloadrequest.h" |
28 #include "mainwindow.h" |
28 #include "mainwindow.h" |
|
29 #include "documentmanager.h" |
29 |
30 |
30 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) : |
31 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) : |
31 QObject (parent), |
32 QObject (parent), |
|
33 HierarchyElement (parent), |
32 m_state (State::Requesting), |
34 m_state (State::Requesting), |
33 m_prompt (parent), |
35 m_prompt (parent), |
34 m_url (url), |
36 m_url (url), |
35 m_destination (dest), |
37 m_destination (dest), |
36 m_filePath (parent->downloadPath() + DIRSLASH + dest), |
38 m_filePath (parent->downloadPath() + DIRSLASH + dest), |
205 prompt()->checkIfFinished(); |
207 prompt()->checkIfFinished(); |
206 return; |
208 return; |
207 } |
209 } |
208 |
210 |
209 // Try to load this file now. |
211 // Try to load this file now. |
210 LDDocument* f = OpenDocument (filePath(), false, not isPrimary()); |
212 LDDocument* document = m_documents->openDocument (filePath(), false, not isPrimary()); |
211 |
213 |
212 if (f == nullptr) |
214 if (document == nullptr) |
213 return; |
215 return; |
214 |
216 |
215 // Iterate through this file and check for errors. If there's any that stems |
217 // Iterate through this file and check for errors. If there's any that stems |
216 // from unknown file references, try resolve that by downloading the reference. |
218 // from unknown file references, try resolve that by downloading the reference. |
217 // This is why downloading a part may end up downloading multiple files, as |
219 // This is why downloading a part may end up downloading multiple files, as |
218 // it resolves dependencies. |
220 // it resolves dependencies. |
219 for (LDObject* obj : f->objects()) |
221 for (LDObject* obj : document->objects()) |
220 { |
222 { |
221 LDError* err = dynamic_cast<LDError*> (obj); |
223 LDError* err = dynamic_cast<LDError*> (obj); |
222 |
224 |
223 if (err == nullptr or err->fileReferenced().isEmpty()) |
225 if (err == nullptr or err->fileReferenced().isEmpty()) |
224 continue; |
226 continue; |
225 |
227 |
226 QString dest = err->fileReferenced(); |
228 QString dest = err->fileReferenced(); |
227 prompt()->downloadFromPartsTracker (dest); |
229 prompt()->downloadFromPartsTracker (dest); |
228 } |
230 } |
229 |
231 |
230 prompt()->addFile (f); |
232 prompt()->addFile (document); |
231 |
233 |
232 if (isPrimary()) |
234 if (isPrimary()) |
233 { |
235 { |
234 AddRecentFile (filePath()); |
236 m_documents->addRecentFile (filePath()); |
235 prompt()->setPrimaryFile (f); |
237 prompt()->setPrimaryFile (document); |
236 } |
238 } |
237 |
239 |
238 prompt()->checkIfFinished(); |
240 prompt()->checkIfFinished(); |
239 } |
241 } |
240 |
242 |