src/partDownloader.cpp

changeset 984
a7b6f987d269
parent 981
5d5d84ab2c48
child 985
ed7b31b9f904
equal deleted inserted replaced
983:05ba93066194 984:a7b6f987d269
320 delete req; 320 delete req;
321 321
322 m_requests.clear(); 322 m_requests.clear();
323 323
324 // Update everything now 324 // Update everything now
325 if (primaryFile() != null) 325 if (primaryFile() != nullptr)
326 { 326 {
327 g_win->changeDocument (primaryFile()); 327 g_win->changeDocument (primaryFile());
328 g_win->doFullRefresh(); 328 g_win->doFullRefresh();
329 g_win->renderer()->resetAngles(); 329 g_win->renderer()->resetAngles();
330 } 330 }
359 359
360 case Close: 360 case Close:
361 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Close)); 361 return qobject_cast<QPushButton*> (form()->buttonBox->button (QDialogButtonBox::Close));
362 } 362 }
363 363
364 return null; 364 return nullptr;
365 } 365 }
366 366
367 // ============================================================================= 367 // =============================================================================
368 // 368 //
369 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) : 369 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) :
374 m_destinaton (dest), 374 m_destinaton (dest),
375 m_filePath (parent->getDownloadPath() + DIRSLASH + dest), 375 m_filePath (parent->getDownloadPath() + DIRSLASH + dest),
376 m_networkManager (new QNetworkAccessManager), 376 m_networkManager (new QNetworkAccessManager),
377 m_isFirstUpdate (true), 377 m_isFirstUpdate (true),
378 m_isPrimary (primary), 378 m_isPrimary (primary),
379 m_filePointer (null) 379 m_filePointer (nullptr)
380 { 380 {
381 // Make sure that we have a valid destination. 381 // Make sure that we have a valid destination.
382 QString dirpath = Dirname (filePath()); 382 QString dirpath = Dirname (filePath());
383 383
384 QDir dir (dirpath); 384 QDir dir (dirpath);
478 478
479 if (filePointer()) 479 if (filePointer())
480 { 480 {
481 filePointer()->close(); 481 filePointer()->close();
482 delete filePointer(); 482 delete filePointer();
483 setFilePointer (null); 483 setFilePointer (nullptr);
484 484
485 if (state() == State::Failed) 485 if (state() == State::Failed)
486 QFile::remove (filePath()); 486 QFile::remove (filePath());
487 } 487 }
488 488
493 } 493 }
494 494
495 // Try to load this file now. 495 // Try to load this file now.
496 LDDocument* f = OpenDocument (filePath(), false, not isPrimary()); 496 LDDocument* f = OpenDocument (filePath(), false, not isPrimary());
497 497
498 if (f == null) 498 if (f == nullptr)
499 return; 499 return;
500 500
501 // Iterate through this file and check for errors. If there's any that stems 501 // Iterate through this file and check for errors. If there's any that stems
502 // from unknown file references, try resolve that by downloading the reference. 502 // from unknown file references, try resolve that by downloading the reference.
503 // This is why downloading a part may end up downloading multiple files, as 503 // This is why downloading a part may end up downloading multiple files, as
504 // it resolves dependencies. 504 // it resolves dependencies.
505 for (LDObject* obj : f->objects()) 505 for (LDObject* obj : f->objects())
506 { 506 {
507 LDError* err = dynamic_cast<LDError*> (obj); 507 LDError* err = dynamic_cast<LDError*> (obj);
508 508
509 if (err == null or err->fileReferenced().isEmpty()) 509 if (err == nullptr or err->fileReferenced().isEmpty())
510 continue; 510 continue;
511 511
512 QString dest = err->fileReferenced(); 512 QString dest = err->fileReferenced();
513 prompt()->downloadFromPartsTracker (dest); 513 prompt()->downloadFromPartsTracker (dest);
514 } 514 }
546 void PartDownloadRequest::readyRead() 546 void PartDownloadRequest::readyRead()
547 { 547 {
548 if (state() == State::Failed) 548 if (state() == State::Failed)
549 return; 549 return;
550 550
551 if (filePointer() == null) 551 if (filePointer() == nullptr)
552 { 552 {
553 m_filePath.replace ("\\", "/"); 553 m_filePath.replace ("\\", "/");
554 554
555 // We have already asked the user whether we can overwrite so we're good 555 // We have already asked the user whether we can overwrite so we're good
556 // to go here. 556 // to go here.

mercurial