int LmcCom::getCover(MemoryStruct* cover, TrackInfo* track) { char* url = 0; int status = fail; if (track && !isEmpty(track->artworkurl)) { asprintf(&url, "http://%s:%d/%s", host, 9000, track->artworkurl); status = downloadFile(url, cover); free(url); } if (status != success) { // http://<server>:<port>/music/<track_id>/cover.jpg if (isEmpty(track->artworkTrackId)) asprintf(&url, "http://%s:%d/music/%d/cover.jpg", host, 9000, track->id); else asprintf(&url, "http://%s:%d/music/%s/cover.jpg", host, 9000, track->artworkTrackId); status = downloadFile(url, cover); free(url); } return status; }
Updater::Updater(const UpdateInformation &information, QObject *parent) : QObject(parent), m_transfer(NULL), m_transfersCount(0), m_transfersSuccessful(true) { const QString path(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/OtterBrowser/")); QDir directory(path); if (!directory.exists()) { QDir().mkdir(path); } else if (directory.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).count() > 0) { directory.setNameFilters(QStringList(QLatin1String("*.*"))); directory.setFilter(QDir::Files); for (int i = 0; i < directory.entryList().count(); ++i) { directory.remove(directory.entryList().at(i)); } } clearUpdate(); downloadFile(information.scriptUrl, path); m_transfer = downloadFile(information.fileUrl, path); m_transfer->setUpdateInterval(500); connect(m_transfer, SIGNAL(progressChanged(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64))); }
int LmcCom::getCurrentCover(MemoryStruct* cover, TrackInfo* track) { char* url = 0; int status = fail; if (track && !isEmpty(track->artworkurl)) { asprintf(&url, "http://%s:%d/%s", host, 9000, track->artworkurl); status = downloadFile(url, cover); free(url); } if (status != success) { // http://localhost:9000/music/current/cover.jpg?player=f0:4d:a2:33:b7:ed asprintf(&url, "http://%s:%d/music/current/cover.jpg?player=%s", host, 9000, escId); status = downloadFile(url, cover); free(url); } return status; }
boolean OTAUpdateClass::checkUpdate(void) { String vxp_name, vxp_digest; if(!downloadFile(UPDATE_MD5)) { return false; } if(!parseUpdateMD5(&vxp_name, &vxp_digest)) { return false; } if(checkMD5(this->firmware_name, vxp_digest.c_str())) { DEBUG_UPDATE("found no new firmware!\r\n"); return false; } DEBUG_UPDATE("found a new firmware %s [%s]!\r\n", vxp_name.c_str(), vxp_digest.c_str()); if(!downloadFile(UPDATE_VXP)) { return false; } if(!checkMD5("C:\\" UPDATE_VXP, vxp_digest.c_str())) { DEBUG_UPDATE("new firmware has a wrong md5sum!\r\n"); return false; } DEBUG_UPDATE("new firmware is ok!\r\n"); return true; }
void UpdaterComponent::downloadUpdate(const QVariantMap& updateInfo) { if (isDownloading()) return; QLOG_INFO() << updateInfo; if (!updateInfo.contains("version") || !updateInfo.contains("manifestURL") || !updateInfo.contains("manifestHash") || !updateInfo.contains("fileURL") || !updateInfo.contains("fileHash") || !updateInfo.contains("fileName")) { QLOG_ERROR() << "updateInfo was missing fields required to carry out this action."; return; } m_version = updateInfo["version"].toString(); m_manifest = new Update(updateInfo["manifestURL"].toString(), UpdateManager::GetPath("manifest.xml.bz2", m_version, false), updateInfo["manifestHash"].toString(), this); // determine if we have a manifest (some distros don't like OE) m_hasManifest = ((!m_manifest->m_url.isEmpty()) && (!m_manifest->m_hash.isEmpty())); m_file = new Update(updateInfo["fileURL"].toString(), UpdateManager::GetPath(updateInfo["fileName"].toString(), m_version, true), updateInfo["fileHash"].toString(), this); if (m_hasManifest) connect(m_manifest, &Update::fileDone, this, &UpdaterComponent::fileComplete); connect(m_file, &Update::fileDone, this, &UpdaterComponent::fileComplete); // create directories we need QDir dr(QFileInfo(m_file->m_localPath).dir()); if (!dr.exists()) { if (!dr.mkpath(".")) { QLOG_ERROR() << "Failed to create update directory:" << dr.absolutePath(); emit downloadError("Failed to create download directory"); return; } } // this will first check if the files are done // and in that case emit the done signal. if (fileComplete(NULL)) return; if (!m_manifest->isReady() && m_hasManifest) downloadFile(m_manifest); if (!m_file->isReady()) downloadFile(m_file); }
int _tmain(int argc, _TCHAR* argv[]) { if (argc == 1) { bool res = CheckNetWorkWell(); printf("%d\n", res); return -1; } if (_tcscmp(argv[1], _T("/d")) == 0) { if (argc >= 5) { TCHAR * inUrl = argv[2];//下载地址 TCHAR* filepath = argv[3];//文件保存路径 TCHAR* uuid = argv[4];//文件编号 TCHAR * file_name = NULL;//文件名 if (argc > 6) { if (_tcscmp(argv[5], _T("/name")) == 0) { file_name = argv[6]; } else { Log(_T("%s"), _T("参数传递错误,应该是/name")); return -1; } } else if (argc == 6) { Log(_T("%s"), _T("参数传递少,/name 后面应该有文件名")); return -1; } return downloadFile(inUrl, filepath, uuid, file_name); } } else if (_tcscmp(argv[1], _T("/upload")) == 0) { char *uploadInfo = WcharToUTF8_New(argv[3]); //UploadInfo *info = new UploadInfo(argv[2], uploadInfo); UploadInfo info(argv[2], uploadInfo); UploadFile(&info); delete[]uploadInfo; } else { if (argc >= 4) { TCHAR * inUrl = argv[1]; TCHAR* filepath = argv[2]; TCHAR* uuid = argv[3]; TCHAR * file_name = NULL; if (argc > 5) { if (_tcscmp(argv[4], _T("/name")) == 0) { file_name = argv[5]; } else { Log(_T("%s"), _T("参数传递错误,应该是/name")); return -1; } } else if (argc == 5) { Log(_T("%s"), _T("参数传递少,/name 后面应该有文件名")); return -1; } return downloadFile(inUrl, filepath, uuid, file_name); } } return 0; }
void ftpClient::ftpCommandFinished(int commandId, bool error) { if (ftp->currentCommand() == QFtp::ConnectToHost) { if (error) { qDebug()<<"FTP"; qDebug()<<tr("Unable to connect to the FTP server " "at %1. Please check that the host " "name is correct.").arg(ftpServer); connectOrDisconnect(); return; } qDebug()<<tr("Logged onto %1.").arg(ftpServer); return; } //![6] //![7] if (ftp->currentCommand() == QFtp::Login) ftp->list(); //![7] //![8] if (ftp->currentCommand() == QFtp::Get) { if (error) { qDebug()<<tr("Canceled download of %1.").arg(file->fileName()); file->close(); file->remove(); } else { qDebug()<<tr("Downloaded %1 to current directory.").arg(file->fileName()); file->close(); if(!f_list.isEmpty()) downloadFile(); //Если есть еще файлы, то качаем else { delete file; qDebug()<<"end!!!"; /// А тут высылаем сигнал о выходе emit allDone(0,QProcess::NormalExit); } } //![8] //![9] } else if (ftp->currentCommand() == QFtp::List) { // if (isDirectory.isEmpty()) { // qDebug()<<tr("File scan ended!"); downloadFile(); //начинаем скачку файлов // } } //![9] }
DBoxFE_ProfileWizard::DBoxFE_ProfileWizard( QDialog *parent, Qt::WFlags flags ) : QDialog( parent, flags ) { // setup grafical user interface (gui) setupUi( this ); page = 0; // for download game database file m_http = new QHttp( this ); connect( m_http, SIGNAL( requestFinished( int, bool ) ), this, SLOT( httpRequestFinished( int, bool ) ) ); connect( m_http, SIGNAL( responseHeaderReceived( const QHttpResponseHeader & ) ), this, SLOT( readResponseHeader( const QHttpResponseHeader & ) ) ); // connection connect( btnBack, SIGNAL( clicked() ), this, SLOT( slotBack() ) ); connect( btnNext, SIGNAL( clicked() ), this, SLOT( slotNext() ) ); connect( btnNext, SIGNAL( clicked() ), this, SLOT( slotFinish() ) ); connect( btnHelp, SIGNAL( clicked() ), this, SLOT( slotHelp() ) ); connect( btnAbort, SIGNAL( clicked() ), this, SLOT( slotAbort() ) ); connect( btnSelectDir, SIGNAL( clicked() ), this, SLOT( slotSelectDir() ) ); connect( btnSearch, SIGNAL( clicked() ), this, SLOT( slotSearch() ) ); // enable button btnNext->setEnabled( true ); // center the wiget on desktop screen QDesktopWidget *desktop = qApp->desktop(); const QRect rect = desktop->availableGeometry( desktop->primaryScreen() ); int left = ( rect.width() - width() ) / 2; int top = ( rect.height() - height() ) / 2; setGeometry( left, top, width(), height() ); downloadFile(); }
int NetworkToolKits::HttpDownloadSimple(QString wgetPath, QString addr, QString outputFilePath) { QString cmdLine = wgetPath+" "+addr+" --no-check-certificate -O "+outputFilePath; qDebug()<<"HttpDownloadSimple:"<<cmdLine; QProcess proc; proc.start(cmdLine); // Wait for process start if(!proc.waitForStarted()){ qDebug()<<"process start failed"; return PROCESS_START_FAILED; } QByteArray proc_output; while (false == proc.waitForFinished()) { qDebug()<<"Process finish failed"; return PROCESS_FINISH_FAILED; } proc_output = proc.readAll(); QFile downloadFile(outputFilePath); if((!downloadFile.exists())||(downloadFile.size()==0)){ qDebug()<<"download file failed"; return DOWNLOAD_FAILED; } return NTK_OK; }
void CModListView::loadScreenshots() { if (ui->tabWidget->currentIndex() == 2 && ui->modInfoWidget->isVisible()) { ui->screenshotsList->clear(); QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString(); assert(modModel->hasMod(modName)); //should be filtered out by check above for (QString & url : modModel->getMod(modName).getValue("screenshots").toStringList()) { // URL must be encoded to something else to get rid of symbols illegal in file names auto hashed = QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5); auto hashedStr = QString::fromUtf8(hashed.toHex()); QString fullPath = CLauncherDirs::get().downloadsPath() + '/' + hashedStr + ".png"; QPixmap pixmap(fullPath); if (pixmap.isNull()) { // image file not exists or corrupted - try to redownload downloadFile(hashedStr + ".png", url, "screenshots"); } else { // managed to load cached image QIcon icon(pixmap); QListWidgetItem * item = new QListWidgetItem(icon, QString(tr("Screenshot %1")).arg(ui->screenshotsList->count() + 1)); ui->screenshotsList->addItem(item); } } } }
// retrieve bootstrapinfo from manifest bool bootstrapDataIsAvailable(BootstrapInfo &bootstrapInfo) { if (!bootstrapInfo.data.empty()) { return true; } if (bootstrapInfo.url.empty()) { return false; } // download it long status; bootstrapInfo.data = downloadFile(NULL, bootstrapInfo.url, status); if (status != 200) { std::cerr << __func__ << " http status " << status << std::endl; if (!bootstrapInfo.data.empty()) { // dump http if any std::cerr << std::string(&(bootstrapInfo.data)[0], &(bootstrapInfo.data)[0] + (bootstrapInfo.data).size()) << std::endl; bootstrapInfo.data.clear(); } return false; } if (bootstrapInfo.data.empty()) { return false; } return true; }
static void downloadCallback(WMWidget * w, void *data) { _Panel *panel = (_Panel *) data; pid_t newPid; WMButton *button = (WMButton *) w; pid_t *pid; if (button == panel->totB) { pid = &panel->tilePID; } else { pid = &panel->barPID; } if (*pid == 0) { newPid = downloadFile(WMWidgetScreen(w), panel, NULL); if (newPid < 0) { return; } WMSetButtonText(button, _("Stop")); if (button == panel->totB) { AddDeadChildHandler(newPid, finishedTileDownload, data); } else { AddDeadChildHandler(newPid, finishedBarDownload, data); } *pid = newPid; } else { *pid = 0; WMSetButtonText(button, _("Download")); } }
int SyncTabWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QTabWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: on_pushButton_4_clicked(); break; case 1: on_pushButton_3_clicked(); break; case 2: on_pushButton_2_clicked(); break; case 3: on_pushButton_clicked(); break; case 4: downloadFile(); break; case 5: cancelDownload(); break; case 6: httpFinished(); break; case 7: httpReadyRead(); break; case 8: updateDataReadProgress((*reinterpret_cast< qint64(*)>(_a[1])),(*reinterpret_cast< qint64(*)>(_a[2]))); break; case 9: enableDownloadButton(); break; case 10: slotAuthenticationRequired((*reinterpret_cast< QNetworkReply*(*)>(_a[1])),(*reinterpret_cast< QAuthenticator*(*)>(_a[2]))); break; case 11: error((*reinterpret_cast< QNetworkReply::NetworkError(*)>(_a[1]))); break; default: ; } _id -= 12; } return _id; }
void FtpApp::createActions() { refresh = new QAction("&Refresh",this); refresh->setStatusTip("Refresh the list of files"); refresh->setShortcut(Qt::Key_F5); connect(refresh,SIGNAL(triggered()),this,SLOT(refreshList())); quitAction = new QAction(tr("&Quit"),this); quitAction->setStatusTip("Quit the JIGS File Sharing"); quitAction->setShortcut(Qt::CTRL + Qt::Key_Q); connect(quitAction, SIGNAL(triggered()), this, SLOT(quit())); aboutAction=new QAction(tr("&About"),this); aboutAction->setStatusTip("About JIGS File Sharing"); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutPopup())); uploadFileAction=new QAction("&Upload Single File",this); uploadFileAction->setShortcut(Qt::CTRL + Qt::Key_U); uploadFileAction->setStatusTip("Upload a single File to the FTP Server"); connect(uploadFileAction,SIGNAL(triggered()),this,SLOT(uploadFile())); downloadFileAction = new QAction("&Download Single File",this); downloadFileAction->setShortcut(Qt::CTRL + Qt::Key_D); downloadFileAction->setStatusTip("Download a single file from FTP sever"); connect(downloadFileAction,SIGNAL(triggered()),this,SLOT(downloadFile())); }
bool DcSoftwareUpdate::downloadPackage( DcPackageIndex::DcPackageDesc desc) { // TODO: Add progress reporting to this method via some optional method. // The method relies on a remote web server so there are many reasons for // failure. TODO: provide a method to report failures. bool rtval = false; if(!desc.isEmpty()) { if(verifyLocalPath(desc)) { QString baseUrl = _swPackageIndex.getBaseUrl(desc); QStringList lst = _swPackageIndex.getFileList(desc); foreach(QString f, lst) { QString dest = appendWithLocalPath(desc,f); if(downloadFile(baseUrl+f,dest)) { rtval = true; } } } }
// download a file, i.e., get it from remote FS INT ExecGet(PAIO_DEV sock, PSERVICE_CONTEXT sc) { int status = STATUS_OK; HANDLE hFile= NULL; int fileSize = getFileSize(sc->req.fileName); if (fileSize == -1) status = FS_ERROR; else { hFile = CreateFileA(sc->req.fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { printf("Error %d opening file %s!\n", GetLastError(), sc->req.fileName); status = FS_ERROR; } } // Start send Response _itoa_s(status, sc->resp.status, 10); _itoa_s(fileSize, sc->resp.dataSize, 10); if (!writeResponse(sock->dev, &sc->resp)) status = IO_ERROR; if (status == STATUS_OK) status = downloadFile(hFile, (SOCKET) sock->dev, fileSize); CloseHandle(hFile); return status; }
void ImageProcessing::contentListDownloadComplete() { QXmlStreamReader doc(m_contentList->downloadedData()); m_ImageList.clear(); m_delList.clear(); if (doc.hasError()) { qWarning() << __FUNCTION__ << ": Downloaded xml has errors"; return; } else { while (!doc.atEnd() && !doc.hasError()) { QXmlStreamReader::TokenType token = doc.readNext(); if (token == QXmlStreamReader::StartDocument) continue; if (token == QXmlStreamReader::StartElement) { if (doc.name() == "Url") { QUrl url(doc.readElementText()); if (url.isValid()) { m_ImageList[url.fileName()] = url.toDisplayString(); m_delList << url.fileName(); } } } } qWarning() << __FUNCTION__ << ": parsed contentlist.xml for" << m_ImageList.size() << "elements"; downloadFile(); } }
ClientInfo::ClientInfo( QWidget *parent, const char *name ) : ClientInfoBase( parent, name ) { connect( btnOpen, SIGNAL(clicked()), SLOT(downloadFile()) ); connect( btnQuit, SIGNAL(clicked()), qApp, SLOT(quit()) ); connect( &op, SIGNAL( data( const QByteArray &, QNetworkOperation * ) ), this, SLOT( newData( const QByteArray & ) ) ); }
PRIVATE void processRSSList(auto_handle *session, const simple_list items, uint16_t feedID) { simple_list current_item = items; simple_list current_url = NULL; am_filter filter = NULL; const char * url; char path[4096]; HTTPResponse *response = NULL; while(current_item && current_item->data) { feed_item item = (feed_item)current_item->data; current_url = item->urls; while(current_url && current_url->data) { url = (const char*)current_url->data; if(isMatch(session->filters, url, &filter)) { if(!session->match_only) { get_filename(path, NULL, url, session->download_folder); if (!has_been_downloaded(session->downloads, url) && !file_exists(path)) { dbg_printft(P_MSG, "[%d] Found new download: %s (%s)", feedID, item->name, url); response = downloadFile(url, path, filter->agent); if(response) { if(response->responseCode == 200) { if(session->prowl_key_valid) { prowl_sendNotification(PROWL_NEW_TRAILER, session->prowl_key, item->name); } if(session->download_done_script && *(session->download_done_script)) { callDownloadDoneScript(session->download_done_script, path); } dbg_printf(P_MSG, " Download complete (%dMB) (%.2fkB/s)", response->size / 1024 / 1024, response->downloadSpeed / 1024); /* add url to bucket list */ if (addToBucket(url, &session->downloads, session->max_bucket_items) == 0) { session->bucket_changed = 1; save_state(session->statefile, session->downloads); } } else { dbg_printf(P_ERROR, " Error: Download failed (Error Code %d)", response->responseCode); if(session->prowl_key_valid) { prowl_sendNotification(PROWL_DOWNLOAD_FAILED, session->prowl_key, item->name); } } HTTPResponse_free(response); } } else { dbg_printf(P_MSG, "File downloaded previously: %s", basename(path)); } } else { dbg_printft(P_MSG, "[%s] Match: %s (%s)", feedID, item->name, url); } } current_url = current_url->next; } current_item = current_item->next; } }
FtpWindow::FtpWindow(QWidget *parent) : QDialog(parent), ftp(0), networkSession(0) { ftpServerLabel = new QLabel(tr("Ftp &server:")); ftpServerLineEdit = new QLineEdit("ftp.qt.nokia.com"); ftpServerLabel->setBuddy(ftpServerLineEdit); statusLabel = new QLabel(tr("Please enter the name of an FTP server.")); fileList = new QTreeWidget; fileList->setEnabled(false); fileList->setRootIsDecorated(false); fileList->setHeaderLabels(QStringList() << tr("Name") << tr("Size") << tr("Owner") << tr("Group") << tr("Time")); fileList->header()->setStretchLastSection(false); connectButton = new QPushButton(tr("Connect")); connectButton->setDefault(true); cdToParentButton = new QPushButton; cdToParentButton->setIcon(QPixmap(":/images/cdtoparent.png")); cdToParentButton->setEnabled(false); downloadButton = new QPushButton(tr("Download")); downloadButton->setEnabled(false); quitButton = new QPushButton(tr("Quit")); buttonBox = new QDialogButtonBox; buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); progressDialog = new QProgressDialog(this); connect(fileList, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(processItem(QTreeWidgetItem*,int))); connect(fileList, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(enableDownloadButton())); connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); connect(connectButton, SIGNAL(clicked()), this, SLOT(connectOrDisconnect())); connect(cdToParentButton, SIGNAL(clicked()), this, SLOT(cdToParent())); connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLayout = new QHBoxLayout; topLayout->addWidget(ftpServerLabel); topLayout->addWidget(ftpServerLineEdit); topLayout->addWidget(cdToParentButton); topLayout->addWidget(connectButton); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(topLayout); mainLayout->addWidget(fileList); mainLayout->addWidget(statusLabel); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("FTP")); }
// --- Downloads ----------------------------------------------------------- // /// Downloads and returns the molecule with the compound ID \p id. /// If an error occurs a null pointer is returned. boost::shared_ptr<Molecule> PubChem::downloadMolecule(const QString &id) const { QScopedPointer<MoleculeFile> file(downloadFile(id)); if(!file){ return boost::shared_ptr<Molecule>(); } return file->molecule(); }
void MainWindow::downloadXsdFile( const QString &s_Path, const QString &s_XmlSchema ) { QString s_Filename = s_Path + "/" + s_XmlSchema; // ****************************************************************************************************** removeFile( s_Filename ); downloadFile( findCurl(), QLatin1String( "https://store.pangaea.de/software/" ) + QCoreApplication::applicationName() + "/" + s_XmlSchema, s_Filename ); }
bool ClientInfo::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: downloadFile(); break; case 1: newData((const QByteArray&)*((const QByteArray*)static_QUType_ptr.get(_o+1))); break; default: return ClientInfoBase::qt_invoke( _id, _o ); } return TRUE; }
void ImageProcessing::fileDownloadError(QNetworkReply::NetworkError error) { qWarning() << __FUNCTION__ << ": Unable to download" << m_fileInProgress << "with error" << error; if (m_fileInProgress == "contentlist.xml") { timeout(); } else { m_fileInProgress.clear(); downloadFile(); } }
QImage QGitHubReleaseAPIPrivate::avatar(int idx) const { if(m_avatars.contains(idx)) { return m_avatars.value(idx); } else { QImage img = QImage::fromData(downloadFile(avatarUrl(idx))); if(!img.isNull()) return *m_avatars.insert(idx, img); } return QImage(); }
// --- Downloads ----------------------------------------------------------- // /// Downloads and returns the molecule with the compound ID \p id. /// If an error occurs \c 0 is returned. /// /// The ownership of the returned molecule is passed to the caller. Molecule* PubChem::downloadMolecule(const QString &id) const { QScopedPointer<MoleculeFile> file(downloadFile(id)); if(!file){ return 0; } Molecule *molecule = file->molecule(); file->removeMolecule(molecule); return molecule; }
void HttpConnection::on(BufferedSocketListener::Line, const string& aLine) throw() { if(!ok) { if(aLine.find("200") == string::npos) { if(aLine.find("301") != string::npos || aLine.find("302") != string::npos){ moved302 = true; } else { socket->disconnect(); socket->removeListener(this); BufferedSocket::putSocket(socket); socket = NULL; fire(HttpConnectionListener::Failed(), this, aLine + " (" + currentUrl + ")"); coralizeState = CST_DEFAULT; return; } } ok = true; dcdebug("%s\n",aLine.c_str()); } else if(moved302 && Util::findSubString(aLine, "Location") != string::npos){ dcassert(socket); socket->removeListener(this); socket->disconnect(); BufferedSocket::putSocket(socket); socket = NULL; string location302 = aLine.substr(10, aLine.length() - 11); // make sure we can also handle redirects with relative paths if(Util::strnicmp(location302.c_str(), "http://", 7) != 0) { if(location302[0] == '/') { Util::decodeUrl(currentUrl, server, port, file); string tmp = "http://" + server; if(port != 80) tmp += ':' + Util::toString(port); location302 = tmp + location302; } else { string::size_type i = currentUrl.rfind('/'); dcassert(i != string::npos); location302 = currentUrl.substr(0, i + 1) + location302; } } fire(HttpConnectionListener::Redirected(), this, location302); coralizeState = CST_DEFAULT; downloadFile(location302); } else if(aLine == "\x0d") { socket->setDataMode(size); } else if(Util::findSubString(aLine, "Content-Length") != string::npos) { size = Util::toInt(aLine.substr(16, aLine.length() - 17)); } else if(Util::findSubString(aLine, "Content-Encoding") != string::npos) { if(aLine.substr(18, aLine.length() - 19) == "x-bzip2") fire(HttpConnectionListener::TypeBZ2(), this); } }
HttpWindow::HttpWindow(QWidget *parent) : QDialog(parent) { #ifndef QT_NO_SSL urlLineEdit = new QLineEdit("https://qt-project.org/"); #else urlLineEdit = new QLineEdit("http://qt-project.org/"); #endif urlLabel = new QLabel(tr("&URL:")); urlLabel->setBuddy(urlLineEdit); statusLabel = new QLabel(tr("Please enter the URL of a file you want to " "download.")); statusLabel->setWordWrap(true); downloadButton = new QPushButton(tr("Download")); downloadButton->setDefault(true); quitButton = new QPushButton(tr("Quit")); quitButton->setAutoDefault(false); buttonBox = new QDialogButtonBox; buttonBox->addButton(downloadButton, QDialogButtonBox::ActionRole); buttonBox->addButton(quitButton, QDialogButtonBox::RejectRole); progressDialog = new QProgressDialog(this); connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableDownloadButton())); connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(slotAuthenticationRequired(QNetworkReply*, QAuthenticator*))); #ifndef QT_NO_SSL connect(&qnam, SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)), this, SLOT(sslErrors(QNetworkReply*, QList<QSslError>))); #endif connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); QHBoxLayout *topLayout = new QHBoxLayout; topLayout->addWidget(urlLabel); topLayout->addWidget(urlLineEdit); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addLayout(topLayout); mainLayout->addWidget(statusLabel); mainLayout->addWidget(buttonBox); setLayout(mainLayout); setWindowTitle(tr("HTTP")); urlLineEdit->setFocus(); }
// --- Downloads ----------------------------------------------------------- // /// Downloads and returns the polymer (protein or nucleic acid) with /// the PDB ID of \p id. If an error occurs \c 0 is returned. /// /// The ownership of the returned polymer is passed to the caller. /// /// For example, to download the Lysozyme protein (PDB ID: 2LYZ): /// \code /// Polymer *lysozyme = pdb.downloadPolymer("2LYZ"); /// \endcode Polymer* ProteinDataBank::downloadPolymer(const QString &id) const { QScopedPointer<PolymerFile> file(downloadFile(id)); if(!file){ return 0; } Polymer *polymer = file->polymer(); file->removePolymer(polymer); return polymer; }
/** @brief DownloadTorrentFile * * @todo: document this function */ bool PlasmaInterface::DownloadTorrentFile( PlasmaResourceInfo& info, const wxString& destination_directory) const { wxString dl_target = destination_directory + wxFileName::GetPathSeparator() + info.m_torrent_filename; try { downloadFile( m_host, _T("Resources/") + info.m_torrent_filename, dl_target ); info.m_local_torrent_filepath = dl_target; } catch ( std::exception& e ) { wxLogError( _T("downloading file failed: :") + dl_target ); return false; } return true; }