src/partDownloader.cc

changeset 714
b4a990f59a5e
parent 662
2f1bd9112408
child 717
fdc285e5952f
equal deleted inserted replaced
713:46377d340c23 714:b4a990f59a5e
40 // 40 //
41 void PartDownloader::staticBegin() 41 void PartDownloader::staticBegin()
42 { 42 {
43 QString path = getDownloadPath(); 43 QString path = getDownloadPath();
44 44
45 if (path == "" || QDir (path).exists() == false) 45 if (path.isEmpty() || not QDir (path).exists())
46 { 46 {
47 critical (PartDownloader::tr ("You need to specify a valid path for " 47 critical (PartDownloader::tr ("You need to specify a valid path for "
48 "downloaded files in the configuration to download paths.")); 48 "downloaded files in the configuration to download paths."));
49 49
50 (new ConfigDialog (ConfigDialog::DownloadTab, null))->exec(); 50 (new ConfigDialog (ConfigDialog::DownloadTab, null))->exec();
121 void PartDownloader::modifyDestination (QString& dest) const 121 void PartDownloader::modifyDestination (QString& dest) const
122 { 122 {
123 dest = dest.simplified(); 123 dest = dest.simplified();
124 124
125 // If the user doesn't want us to guess, stop right here. 125 // If the user doesn't want us to guess, stop right here.
126 if (net_guesspaths == false) 126 if (not net_guesspaths)
127 return; 127 return;
128 128
129 // Ensure .dat extension 129 // Ensure .dat extension
130 if (dest.right (4) != ".dat") 130 if (dest.right (4) != ".dat")
131 { 131 {
222 modifyDestination (dest); 222 modifyDestination (dest);
223 223
224 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest)) 224 if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest))
225 { 225 {
226 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest); 226 const QString overwritemsg = format (tr ("%1 already exists in download directory. Overwrite?"), dest);
227 if (!confirm (tr ("Overwrite?"), overwritemsg)) 227 if (not confirm (tr ("Overwrite?"), overwritemsg))
228 return; 228 return;
229 } 229 }
230 230
231 downloadButton()->setEnabled (false); 231 downloadButton()->setEnabled (false);
232 interface()->progress->setEnabled (true); 232 interface()->progress->setEnabled (true);
265 bool failed = isAborted(); 265 bool failed = isAborted();
266 266
267 // If there is some download still working, we're not finished. 267 // If there is some download still working, we're not finished.
268 for (PartDownloadRequest* req : requests()) 268 for (PartDownloadRequest* req : requests())
269 { 269 {
270 if (!req->isFinished()) 270 if (not req->isFinished())
271 return; 271 return;
272 272
273 if (req->state() == PartDownloadRequest::EFailed) 273 if (req->state() == PartDownloadRequest::EFailed)
274 failed = true; 274 failed = true;
275 } 275 }
286 reloadAllSubfiles(); 286 reloadAllSubfiles();
287 g_win->doFullRefresh(); 287 g_win->doFullRefresh();
288 g_win->R()->resetAngles(); 288 g_win->R()->resetAngles();
289 } 289 }
290 290
291 if (net_autoclose && !failed) 291 if (net_autoclose && not failed)
292 { 292 {
293 // Close automatically if desired. 293 // Close automatically if desired.
294 accept(); 294 accept();
295 } 295 }
296 else 296 else
337 // Make sure that we have a valid destination. 337 // Make sure that we have a valid destination.
338 QString dirpath = dirname (filePath()); 338 QString dirpath = dirname (filePath());
339 339
340 QDir dir (dirpath); 340 QDir dir (dirpath);
341 341
342 if (dir.exists() == false) 342 if (not dir.exists())
343 { 343 {
344 print ("Creating %1...\n", dirpath); 344 print ("Creating %1...\n", dirpath);
345 345
346 if (!dir.mkpath (dirpath)) 346 if (not dir.mkpath (dirpath))
347 critical (format (tr ("Couldn't create the directory %1!"), dirpath)); 347 critical (format (tr ("Couldn't create the directory %1!"), dirpath));
348 } 348 }
349 349
350 setNetworkReply (networkManager()->get (QNetworkRequest (QUrl (url)))); 350 setNetworkReply (networkManager()->get (QNetworkRequest (QUrl (url))));
351 connect (networkReply(), SIGNAL (finished()), this, SLOT (downloadFinished())); 351 connect (networkReply(), SIGNAL (finished()), this, SLOT (downloadFinished()));
372 case ERequesting: 372 case ERequesting:
373 case EDownloading: 373 case EDownloading:
374 { 374 {
375 prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol)); 375 prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol));
376 376
377 if (!prog) 377 if (not prog)
378 { 378 {
379 prog = new QProgressBar; 379 prog = new QProgressBar;
380 table->setCellWidget (tableRow(), progcol, prog); 380 table->setCellWidget (tableRow(), progcol, prog);
381 } 381 }
382 382
416 // 416 //
417 void PartDownloadRequest::downloadFinished() 417 void PartDownloadRequest::downloadFinished()
418 { 418 {
419 if (networkReply()->error() != QNetworkReply::NoError) 419 if (networkReply()->error() != QNetworkReply::NoError)
420 { 420 {
421 if (isPrimary() && !prompt()->isAborted()) 421 if (isPrimary() && not prompt()->isAborted())
422 critical (networkReply()->errorString()); 422 critical (networkReply()->errorString());
423 423
424 setState (EFailed); 424 setState (EFailed);
425 } 425 }
426 elif (state() != EFailed) 426 elif (state() != EFailed)
446 } 446 }
447 447
448 // Try to load this file now. 448 // Try to load this file now.
449 LDDocument* f = openDocument (filePath(), false); 449 LDDocument* f = openDocument (filePath(), false);
450 450
451 if (!f) 451 if (f == null)
452 return; 452 return;
453 453
454 f->setImplicit (!isPrimary()); 454 f->setImplicit (not isPrimary());
455 455
456 // Iterate through this file and check for errors. If there's any that stems 456 // Iterate through this file and check for errors. If there's any that stems
457 // from unknown file references, try resolve that by downloading the reference. 457 // from unknown file references, try resolve that by downloading the reference.
458 // This is why downloading a part may end up downloading multiple files, as 458 // This is why downloading a part may end up downloading multiple files, as
459 // it resolves dependencies. 459 // it resolves dependencies.
501 501
502 // We have already asked the user whether we can overwrite so we're good 502 // We have already asked the user whether we can overwrite so we're good
503 // to go here. 503 // to go here.
504 setFilePointer (new QFile (filePath().toLocal8Bit())); 504 setFilePointer (new QFile (filePath().toLocal8Bit()));
505 505
506 if (!filePointer()->open (QIODevice::WriteOnly)) 506 if (not filePointer()->open (QIODevice::WriteOnly))
507 { 507 {
508 critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno))); 508 critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno)));
509 setState (EFailed); 509 setState (EFailed);
510 networkReply()->abort(); 510 networkReply()->abort();
511 updateToTable(); 511 updateToTable();

mercurial