59 // |
59 // |
60 QString PartDownloader::getDownloadPath() |
60 QString PartDownloader::getDownloadPath() |
61 { |
61 { |
62 QString path = cfg::downloadFilePath; |
62 QString path = cfg::downloadFilePath; |
63 |
63 |
64 #if DIRSLASH_CHAR != '/' |
64 if (DIRSLASH[0] != '/') |
65 path.replace (DIRSLASH, "/"); |
65 path.replace (DIRSLASH, "/"); |
66 #endif |
|
67 |
66 |
68 return path; |
67 return path; |
69 } |
68 } |
70 |
69 |
71 // ============================================================================= |
70 // ============================================================================= |
322 |
321 |
323 // ============================================================================= |
322 // ============================================================================= |
324 // |
323 // |
325 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) : |
324 PartDownloadRequest::PartDownloadRequest (QString url, QString dest, bool primary, PartDownloader* parent) : |
326 QObject (parent), |
325 QObject (parent), |
327 m_state (ERequesting), |
326 m_state (DLRQ_Requesting), |
328 m_prompt (parent), |
327 m_prompt (parent), |
329 m_url (url), |
328 m_url (url), |
330 m_destinaton (dest), |
329 m_destinaton (dest), |
331 m_filePath (PartDownloader::getDownloadPath() + DIRSLASH + dest), |
330 m_filePath (PartDownloader::getDownloadPath() + DIRSLASH + dest), |
332 m_networkManager (new QNetworkAccessManager), |
331 m_networkManager (new QNetworkAccessManager), |
360 |
359 |
361 // ============================================================================= |
360 // ============================================================================= |
362 // |
361 // |
363 void PartDownloadRequest::updateToTable() |
362 void PartDownloadRequest::updateToTable() |
364 { |
363 { |
365 const int labelcol = PartDownloader::PartLabelColumn, |
364 int const labelcol = PartDownloader::PartLabelColumn; |
366 progcol = PartDownloader::ProgressColumn; |
365 int const progcol = PartDownloader::ProgressColumn; |
367 QTableWidget* table = prompt()->interface()->progress; |
366 QTableWidget* table = prompt()->interface()->progress; |
368 QProgressBar* prog; |
367 QProgressBar* prog; |
369 |
368 |
370 switch (state()) |
369 switch (state()) |
371 { |
370 { |
372 case ERequesting: |
371 case DLRQ_Requesting: |
373 case EDownloading: |
372 case DLRQ_Downloading: |
374 { |
373 { |
375 prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol)); |
374 prog = qobject_cast<QProgressBar*> (table->cellWidget (tableRow(), progcol)); |
376 |
375 |
377 if (not prog) |
376 if (not prog) |
378 { |
377 { |
382 |
381 |
383 prog->setRange (0, numBytesTotal()); |
382 prog->setRange (0, numBytesTotal()); |
384 prog->setValue (numBytesRead()); |
383 prog->setValue (numBytesRead()); |
385 } break; |
384 } break; |
386 |
385 |
387 case EFinished: |
386 case DLRQ_Finished: |
388 case EFailed: |
387 case DLRQ_Failed: |
389 { |
388 { |
390 const QString text = (state() == EFinished) |
389 const QString text = (state() == DLRQ_Finished) |
391 ? "<b><span style=\"color: #080\">FINISHED</span></b>" |
390 ? "<b><span style=\"color: #080\">FINISHED</span></b>" |
392 : "<b><span style=\"color: #800\">FAILED</span></b>"; |
391 : "<b><span style=\"color: #800\">FAILED</span></b>"; |
393 |
392 |
394 QLabel* lb = new QLabel (text); |
393 QLabel* lb = new QLabel (text); |
395 lb->setAlignment (Qt::AlignCenter); |
394 lb->setAlignment (Qt::AlignCenter); |
419 if (networkReply()->error() != QNetworkReply::NoError) |
418 if (networkReply()->error() != QNetworkReply::NoError) |
420 { |
419 { |
421 if (isPrimary() && not prompt()->isAborted()) |
420 if (isPrimary() && not prompt()->isAborted()) |
422 critical (networkReply()->errorString()); |
421 critical (networkReply()->errorString()); |
423 |
422 |
424 setState (EFailed); |
423 setState (DLRQ_Failed); |
425 } |
424 } |
426 elif (state() != EFailed) |
425 elif (state() != DLRQ_Failed) |
427 setState (EFinished); |
426 setState (DLRQ_Finished); |
428 |
427 |
429 setNumBytesRead (numBytesTotal()); |
428 setNumBytesRead (numBytesTotal()); |
430 updateToTable(); |
429 updateToTable(); |
431 |
430 |
432 if (filePointer()) |
431 if (filePointer()) |
433 { |
432 { |
434 filePointer()->close(); |
433 filePointer()->close(); |
435 delete filePointer(); |
434 delete filePointer(); |
436 setFilePointer (null); |
435 setFilePointer (null); |
437 |
436 |
438 if (state() == EFailed) |
437 if (state() == DLRQ_Failed) |
439 QFile::remove (filePath()); |
438 QFile::remove (filePath()); |
440 } |
439 } |
441 |
440 |
442 if (state() != EFinished) |
441 if (state() != DLRQ_Finished) |
443 { |
442 { |
444 prompt()->checkIfFinished(); |
443 prompt()->checkIfFinished(); |
445 return; |
444 return; |
446 } |
445 } |
447 |
446 |
480 // |
479 // |
481 void PartDownloadRequest::downloadProgress (int64 recv, int64 total) |
480 void PartDownloadRequest::downloadProgress (int64 recv, int64 total) |
482 { |
481 { |
483 setNumBytesRead (recv); |
482 setNumBytesRead (recv); |
484 setNumBytesTotal (total); |
483 setNumBytesTotal (total); |
485 setState (EDownloading); |
484 setState (DLRQ_Downloading); |
486 updateToTable(); |
485 updateToTable(); |
487 } |
486 } |
488 |
487 |
489 // ============================================================================= |
488 // ============================================================================= |
490 // |
489 // |
491 void PartDownloadRequest::readyRead() |
490 void PartDownloadRequest::readyRead() |
492 { |
491 { |
493 if (state() == EFailed) |
492 if (state() == DLRQ_Failed) |
494 return; |
493 return; |
495 |
494 |
496 if (filePointer() == null) |
495 if (filePointer() == null) |
497 { |
496 { |
498 m_filePath.replace ("\\", "/"); |
497 m_filePath.replace ("\\", "/"); |
502 setFilePointer (new QFile (filePath().toLocal8Bit())); |
501 setFilePointer (new QFile (filePath().toLocal8Bit())); |
503 |
502 |
504 if (not filePointer()->open (QIODevice::WriteOnly)) |
503 if (not filePointer()->open (QIODevice::WriteOnly)) |
505 { |
504 { |
506 critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno))); |
505 critical (format (tr ("Couldn't open %1 for writing: %2"), filePath(), strerror (errno))); |
507 setState (EFailed); |
506 setState (DLRQ_Failed); |
508 networkReply()->abort(); |
507 networkReply()->abort(); |
509 updateToTable(); |
508 updateToTable(); |
510 prompt()->checkIfFinished(); |
509 prompt()->checkIfFinished(); |
511 return; |
510 return; |
512 } |
511 } |
517 |
516 |
518 // ============================================================================= |
517 // ============================================================================= |
519 // |
518 // |
520 bool PartDownloadRequest::isFinished() const |
519 bool PartDownloadRequest::isFinished() const |
521 { |
520 { |
522 return state() == EFinished || state() == EFailed; |
521 return state() == DLRQ_Finished || state() == DLRQ_Failed; |
523 } |
522 } |
524 |
523 |
525 // ============================================================================= |
524 // ============================================================================= |
526 // |
525 // |
527 void PartDownloadRequest::abort() |
526 void PartDownloadRequest::abort() |