MCPcopy Create free account
hub / github.com/bumptop/BumpTop / addTransfer

Method addTransfer

trunk/win/Source/BT_FileTransferManager.cpp:447–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445
446
447bool FileTransferManager::addTransfer(FileTransfer& transfer, bool blocking, int numRedirects)
448{
449 bool succeeded = true;
450 QNetworkRequest request = QNetworkRequest(QUrl::fromEncoded(transfer.getUrl().toAscii()));
451
452 // uploads using qt for this function is not supported as no one seems to use it here. See addPostTransfer
453 assert(transfer.getType() == FileTransfer::Download);
454
455 // set the user agent
456 QString userAgent = QString("BumpTop/r%1/%2").arg(SVN_VERSION_NUMBER).arg(winOS->GetGUID());
457 QByteArray tmp = userAgent.toAscii();
458 request.setRawHeader("User-Agent", tmp);
459
460 // create a new transfer
461 FileTransferWrapper * ftw = new FileTransferWrapper(transfer, &transferList, blocking, numRedirects);
462 transferList.append(ftw);
463
464 // set the proxy settings if necessary
465 if (transfer.getUrl().startsWith("http://", Qt::CaseInsensitive))
466 {
467 if (!GLOBAL(settings).httpProxyUrl.isEmpty())
468 {
469 QUrl proxyUrl = QUrl(GLOBAL(settings).httpProxyUrl);
470 QNetworkProxy proxy = QNetworkProxy(QNetworkProxy::Socks5Proxy, proxyUrl.host(), proxyUrl.port(8080), proxyUrl.userName(), proxyUrl.password());
471 ftw->_manager->setProxy(proxy);
472 }
473 }
474
475 QNetworkReply * reply = ftw->_manager->get(request);
476 ftw->_reply = reply;
477 assert(QObject::connect(ftw->_manager, SIGNAL(authenticationRequired(QNetworkReply *, QAuthenticator *)), ftw, SLOT(authenticate(QNetworkReply *, QAuthenticator *))));
478
479 if (blocking)
480 {
481 QEventLoop loop;
482 assert(QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())));
483
484 // set the timeout
485 if (transfer.getTimeout())
486 QTimer::singleShot(transfer.getTimeout() * 1000, &loop, SLOT(quit()));
487
488 // loop until we finish downloading
489 loop.exec();
490
491 // handle the reply after we finish
492 succeeded = ftw->finishedReply(reply);
493 }
494 else
495 {
496 // let the wrapper handle the file transfer and any redirects
497 assert(QObject::connect(ftw->_manager, SIGNAL(finished(QNetworkReply*)), ftw, SLOT(finished(QNetworkReply*))));
498 assert(QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), ftw, SLOT(error(QNetworkReply::NetworkError))));
499 }
500
501 return succeeded;
502}
503
504bool FileTransferManager::addPostTransfer(FileTransfer& transfer, bool blocking, QObject* progressListener)

Callers 8

getHttpRequestMethod · 0.80
requestSourceUpdateMethod · 0.80
requestImageUpdateMethod · 0.80
getVersionStringMethod · 0.80
downloadNewVersionMethod · 0.80
getHttpRequestMethod · 0.80
finishedReplyMethod · 0.80

Calls 15

assertClass · 0.85
finishedFunction · 0.85
quitFunction · 0.85
toAsciiMethod · 0.80
getUrlMethod · 0.80
GetGUIDMethod · 0.80
hostMethod · 0.80
finishedReplyMethod · 0.80
QNetworkRequestClass · 0.50
QStringFunction · 0.50
QUrlClass · 0.50
QNetworkProxyClass · 0.50

Tested by

no test coverage detected