| 329 | } |
| 330 | |
| 331 | bool FileTransferWrapper::finishedReply(QNetworkReply * reply) |
| 332 | { |
| 333 | assert(reply == _reply); |
| 334 | bool hasError = false; |
| 335 | bool succeeded = false; |
| 336 | |
| 337 | if (_aborted) |
| 338 | return false; |
| 339 | |
| 340 | // handle any redirects |
| 341 | QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); |
| 342 | QString redirectUrlStr = redirectUrl.toString(); |
| 343 | if (getMaxNumberOfRedirects() > 0 && !redirectUrl.isEmpty()) |
| 344 | { |
| 345 | FileTransfer transfer = _ft; |
| 346 | transfer.setUrl(redirectUrl.toString()); |
| 347 | deleteLater(); |
| 348 | return ftManager->addTransfer(transfer, isBlocking(), getMaxNumberOfRedirects()-1); |
| 349 | } |
| 350 | |
| 351 | // if the reply has not finished, mark as error |
| 352 | if (!reply->isFinished()) |
| 353 | hasError = true; |
| 354 | |
| 355 | // set the transfer data functions |
| 356 | QByteArray data = reply->readAll(); |
| 357 | switch (_ft.getType()) |
| 358 | { |
| 359 | case FileTransfer::Upload: |
| 360 | // save the upload reply to the temporary string |
| 361 | if (!_ft.shouldSaveToFile()) |
| 362 | { |
| 363 | QString *outBuffer = _ft.openTemporaryString(); |
| 364 | outBuffer->append(data); |
| 365 | |
| 366 | if (verbose) consoleWrite("POST " + _ft.getTemporaryString() + "\n\n"); |
| 367 | } |
| 368 | break; |
| 369 | |
| 370 | case FileTransfer::Download: |
| 371 | // save the file to disk |
| 372 | if (_ft.shouldSaveToFile()) |
| 373 | { |
| 374 | QFile file(_ft.getLocalPath()); |
| 375 | if (!file.open(QIODevice::WriteOnly)) |
| 376 | hasError = true; |
| 377 | if (file.write(data) == -1) |
| 378 | hasError = true; |
| 379 | file.close(); |
| 380 | } |
| 381 | // save the file to the temporary string |
| 382 | else |
| 383 | { |
| 384 | QString * outBuffer = _ft.openTemporaryString(); |
| 385 | outBuffer->append(data); |
| 386 | |
| 387 | if (verbose) consoleWrite("POST " + _ft.getTemporaryString() + "\n\n"); |
| 388 | } |
no test coverage detected