| 42 | } |
| 43 | |
| 44 | void ServerConnection::httpDownloadFinished(QNetworkReply *reply) |
| 45 | { |
| 46 | auto op_iter = m_operations_in_flight.find(reply); |
| 47 | assert(op_iter != m_operations_in_flight.end()); |
| 48 | if(reply->error()) { |
| 49 | emit networkFailure(tr("Download failure: %1").arg(reply->errorString())); |
| 50 | m_operations_in_flight.erase(reply); |
| 51 | reply->deleteLater(); |
| 52 | return; |
| 53 | } |
| 54 | const QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); |
| 55 | OperationData op_data(op_iter->second); |
| 56 | m_operations_in_flight.erase(reply); |
| 57 | |
| 58 | if(!redirectionTarget.isNull()) { |
| 59 | qCritical() << "Redirections are not handled yet"; |
| 60 | } |
| 61 | op_data.target->write(reply->readAll()); |
| 62 | op_data.target->close(); |
| 63 | switch (op_data.targetType) { |
| 64 | case 0: // a manifest file |
| 65 | { |
| 66 | QBuffer *buf(qobject_cast<QBuffer *>(op_data.target)); |
| 67 | emit retrievedManifest(op_data.requested_url,buf->data()); |
| 68 | delete buf; |
| 69 | op_data.target = nullptr; |
| 70 | break; |
| 71 | } |
| 72 | default: |
| 73 | assert(false); |
| 74 | } |
| 75 | reply->deleteLater(); |
| 76 | } |
| 77 | |
| 78 | void ServerConnection::onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) |
| 79 | { |