Mercurial > hg > svcore
comparison data/fileio/FileSource.cpp @ 926:926f33d3a8b7 tony_integration
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 17 Jun 2014 12:52:27 +0100 |
parents | b9d7352336ce |
children | 613ee830de5e |
comparison
equal
deleted
inserted
replaced
910:55e552b4f1b7 | 926:926f33d3a8b7 |
---|---|
483 } | 483 } |
484 m_done = true; | 484 m_done = true; |
485 if (m_reply) { | 485 if (m_reply) { |
486 QNetworkReply *r = m_reply; | 486 QNetworkReply *r = m_reply; |
487 m_reply = 0; | 487 m_reply = 0; |
488 r->abort(); | 488 // Can only call abort() when there are no errors. |
489 if (r->error() == QNetworkReply::NoError) { | |
490 r->abort(); | |
491 } | |
489 r->deleteLater(); | 492 r->deleteLater(); |
490 } | 493 } |
491 if (m_localFile) { | 494 if (m_localFile) { |
492 delete m_localFile; // does not actually delete the file | 495 delete m_localFile; // does not actually delete the file |
493 m_localFile = 0; | 496 m_localFile = 0; |
516 bool | 519 bool |
517 FileSource::isAvailable() | 520 FileSource::isAvailable() |
518 { | 521 { |
519 waitForStatus(); | 522 waitForStatus(); |
520 bool available = true; | 523 bool available = true; |
521 if (!m_ok) available = false; | 524 if (!m_ok) { |
522 else available = (m_lastStatus / 100 == 2); | 525 available = false; |
523 #ifdef DEBUG_FILE_SOURCE | 526 } else { |
524 cerr << "FileSource::isAvailable: " << (available ? "yes" : "no") | 527 // http 2xx status codes mean success |
525 << endl; | 528 available = (m_lastStatus / 100 == 2); |
529 } | |
530 #ifdef DEBUG_FILE_SOURCE | |
531 cerr << "FileSource::isAvailable: " << (available ? "yes" : "no") << endl; | |
526 #endif | 532 #endif |
527 return available; | 533 return available; |
528 } | 534 } |
529 | 535 |
530 void | 536 void |
632 if (!m_reply) { | 638 if (!m_reply) { |
633 cerr << "WARNING: FileSource::metaDataChanged() called without a reply object being known to us" << endl; | 639 cerr << "WARNING: FileSource::metaDataChanged() called without a reply object being known to us" << endl; |
634 return; | 640 return; |
635 } | 641 } |
636 | 642 |
643 // Handle http transfer status codes. | |
644 | |
637 int status = | 645 int status = |
638 m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); | 646 m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); |
639 | 647 |
648 // If this is a redirection (3xx) code, do the redirect | |
640 if (status / 100 == 3) { | 649 if (status / 100 == 3) { |
641 QString location = m_reply->header | 650 QString location = m_reply->header |
642 (QNetworkRequest::LocationHeader).toString(); | 651 (QNetworkRequest::LocationHeader).toString(); |
643 #ifdef DEBUG_FILE_SOURCE | 652 #ifdef DEBUG_FILE_SOURCE |
644 cerr << "FileSource::metaDataChanged: redirect to \"" | 653 cerr << "FileSource::metaDataChanged: redirect to \"" |
663 } | 672 } |
664 } | 673 } |
665 } | 674 } |
666 | 675 |
667 m_lastStatus = status; | 676 m_lastStatus = status; |
677 | |
678 // 400 and up are failures, get the error string | |
668 if (m_lastStatus / 100 >= 4) { | 679 if (m_lastStatus / 100 >= 4) { |
669 m_errorString = QString("%1 %2") | 680 m_errorString = QString("%1 %2") |
670 .arg(status) | 681 .arg(status) |
671 .arg(m_reply->attribute | 682 .arg(m_reply->attribute |
672 (QNetworkRequest::HttpReasonPhraseAttribute).toString()); | 683 (QNetworkRequest::HttpReasonPhraseAttribute).toString()); |
710 #ifdef DEBUG_FILE_SOURCE | 721 #ifdef DEBUG_FILE_SOURCE |
711 cerr << "FileSource::replyFinished()" << endl; | 722 cerr << "FileSource::replyFinished()" << endl; |
712 #endif | 723 #endif |
713 | 724 |
714 if (m_done) return; | 725 if (m_done) return; |
726 | |
727 QString scheme = m_url.scheme().toLower(); | |
728 // For ftp transfers, replyFinished() will be called on success. | |
729 // metaDataChanged() is never called for ftp transfers. | |
730 if (scheme == "ftp") { | |
731 m_lastStatus = 200; // http ok | |
732 } | |
715 | 733 |
716 bool error = (m_lastStatus / 100 >= 4); | 734 bool error = (m_lastStatus / 100 >= 4); |
717 | 735 |
718 cleanup(); | 736 cleanup(); |
719 | 737 |