void Fetcher::downloadFinished(QNetworkReply* reply) { // qDebug() << "Reply Received" << reply->url(); if (reply->error() == QNetworkReply::NoError) { QUrl redirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if (redirectUrl == reply->url()) { showErrorMessage("Redirected to the original url. Aborting to avoid infinite loop.", this, QMessageBox::Critical); return; } if(!redirectUrl.isEmpty()) { qDebug() << "Redirect to" << redirectUrl; downloadUrl(redirectUrl); return; } processSearchResults(reply); } else { qDebug() << "Error:" << reply->errorString(); showErrorMessage("Error:" + reply->errorString(), this, QMessageBox::Critical); } reply->deleteLater(); }
void KWebKitPart::connectWebPageSignals(WebPage* page) { if (!page) return; connect(page, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(page, SIGNAL(loadAborted(QUrl)), this, SLOT(slotLoadAborted(QUrl))); connect(page, SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(slotLinkHovered(QString,QString,QString))); connect(page, SIGNAL(saveFrameStateRequested(QWebFrame*,QWebHistoryItem*)), this, SLOT(slotSaveFrameState(QWebFrame*,QWebHistoryItem*))); connect(page, SIGNAL(restoreFrameStateRequested(QWebFrame*)), this, SLOT(slotRestoreFrameState(QWebFrame*))); connect(page, SIGNAL(statusBarMessage(QString)), this, SLOT(slotSetStatusBarText(QString))); connect(page, SIGNAL(windowCloseRequested()), this, SLOT(slotWindowCloseRequested())); connect(page, SIGNAL(printRequested(QWebFrame*)), m_browserExtension, SLOT(slotPrintRequested(QWebFrame*))); connect(page, SIGNAL(frameCreated(QWebFrame*)), this, SLOT(slotFrameCreated(QWebFrame*))); connect(m_webView, SIGNAL(linkShiftClicked(QUrl)), page, SLOT(downloadUrl(QUrl))); connect(page, SIGNAL(loadProgress(int)), m_browserExtension, SIGNAL(loadingProgress(int))); connect(page, SIGNAL(selectionChanged()), m_browserExtension, SLOT(updateEditActions())); connect(m_browserExtension, SIGNAL(saveUrl(QUrl)), page, SLOT(downloadUrl(QUrl))); connect(page->mainFrame(), SIGNAL(loadFinished(bool)), this, SLOT(slotMainFrameLoadFinished(bool))); KWebWallet *wallet = page->wallet(); if (wallet) { connect(wallet, SIGNAL(saveFormDataRequested(QString,QUrl)), this, SLOT(slotSaveFormDataRequested(QString,QUrl))); connect(wallet, SIGNAL(fillFormRequestCompleted(bool)), this, SLOT(slotFillFormRequestCompleted(bool))); connect(wallet, SIGNAL(walletClosed()), this, SLOT(slotWalletClosed())); } }
void PageDownloader::processRedirection(QNetworkReply* reply) { QUrl newUrl = reply->attribute( QNetworkRequest::RedirectionTargetAttribute).toUrl(); qDebug() << QString("Redirection from %1 to %2 detected.") .arg(mUrlString).arg(newUrl.toString()); downloadUrl(newUrl); }
void MagnatuneAlbumDownloader::albumDownloadComplete( KIO::Job * downloadJob ) { debug() << "album download complete" << endl; if ( !downloadJob->error() == 0 ) { //TODO: error handling here return ; } if ( downloadJob != m_albumDownloadJob ) return ; //not the right job, so let's ignore it //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection. QString unzipString = "unzip "+ KProcess::quote( m_tempDir.name() + m_currentAlbumFileName) + " -d " +KProcess::quote( m_currentAlbumUnpackLocation ) + " &"; debug() << "unpacking: " << unzipString << endl; system( unzipString.ascii() ); if (m_currentAlbumId != -1 ) { //now I really want to add the album cover to the same folder where I just unzipped the album... The //only way of getting the actual location where the album was unpacked is using the artist and album names MagnatuneAlbum album = MagnatuneDatabaseHandler::instance()->getAlbumById( m_currentAlbumId ); MagnatuneArtist artist = MagnatuneDatabaseHandler::instance()->getArtistById( album.getArtistId() ); QString finalAlbumPath = m_currentAlbumUnpackLocation + "/" + artist.getName() + "/" + album.getName(); QString coverUrlString = album.getCoverURL(); KURL downloadUrl( coverUrlString ); debug() << "Adding cover " << downloadUrl.url() << " to collection at " << finalAlbumPath << endl; m_albumDownloadJob = KIO::file_copy( downloadUrl, KURL( finalAlbumPath + "/cover.jpg" ), -1, true, false, false ); connect( m_albumDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( coverAddComplete( KIO::Job* ) ) ); Amarok::StatusBar::instance() ->newProgressOperation( m_albumDownloadJob ) .setDescription( i18n( "Adding album cover to collection" ) ) .setAbortSlot( this, SLOT( coverAddAborted() ) ); } else { //we do not know exactly what album this is (we are most likely using the redownload manager) emit( downloadComplete( true ) ); } }
void Download::download( QString const &url, QString const & filename ) { QUrl downloadUrl( url ); QString localFilename = filename.isEmpty() ? ( downloadUrl.fileName() + QString( ".part" ) ): filename; m_networkRequest = QNetworkRequest( downloadUrl ); m_file = new QFile( localFilename ); m_file->open( QIODevice::ReadWrite ); download( m_networkRequest ); }
void PageDownloader::download(QString url) { qDebug() << QString("Downloading %1...").arg(url); if (!mNetworkManager) { mNetworkManager.reset(new QNetworkAccessManager); connect(mNetworkManager.data(), &QNetworkAccessManager::finished, this, &PageDownloader::onReplyFinished); } mUrlString = url; QUrl searchUrl(url); downloadUrl(searchUrl); }
void MagnatuneAlbumDownloader::albumDownloadComplete( KJob * downloadJob ) { DEBUG_BLOCK debug() << "album download complete"; if ( !downloadJob->error() == 0 ) { //TODO: error handling here return ; } if ( downloadJob != m_albumDownloadJob ) return ; //not the right job, so let's ignore it //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection. QString unzipString = "unzip " + KShell::quoteArg( m_tempDir->name() + m_currentAlbumFileName ) + " -d " + KShell::quoteArg( m_currentAlbumUnpackLocation ) + " &"; debug() << "unpacking: " << unzipString; if ( system( unzipString.toAscii() ) == -1 ) return; if ( m_currentAlbum ) { //now I really want to add the album cover to the same folder where I just unzipped the album... The //only way of getting the actual location where the album was unpacked is using the artist and album names QString finalAlbumPath = m_currentAlbumUnpackLocation + '/' + m_currentAlbum->albumArtist()->name() + '/' + m_currentAlbum->name(); QString coverUrlString = m_currentAlbum->coverUrl(); KUrl downloadUrl( coverUrlString ); debug() << "Adding cover " << downloadUrl.url() << " to collection at " << finalAlbumPath; m_albumDownloadJob = KIO::file_copy( downloadUrl, KUrl( finalAlbumPath + "/cover.jpg" ), -1, KIO::Overwrite | KIO::HideProgressInfo ); connect( m_albumDownloadJob, SIGNAL( result( KJob* ) ), SLOT( coverAddComplete( KJob* ) ) ); The::statusBar()->newProgressOperation( m_albumDownloadJob, i18n( "Adding album cover to collection" ) ) ->setAbortSlot( this, SLOT( coverAddAborted() ) ); emit( downloadComplete( true ) ); } else { //we do not know exactly what album this is (we are most likely using the redownload manager) emit( downloadComplete( true ) ); } }
void MagnatuneAlbumDownloader::downloadCover( QString albumCoverUrlString, QString fileName ) { KURL downloadUrl( albumCoverUrlString ); debug() << "Download Cover: " << downloadUrl.url() << " to: " << m_tempDir.name() << fileName << endl; m_albumDownloadJob = KIO::file_copy( downloadUrl, KURL( m_tempDir.name() + fileName ), -1, true, false, false ); connect( m_albumDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( coverDownloadComplete( KIO::Job* ) ) ); Amarok::StatusBar::instance() ->newProgressOperation( m_albumDownloadJob ) .setDescription( i18n( "Downloading album cover" ) ) .setAbortSlot( this, SLOT( coverDownloadAborted() ) ); }
void UpdateManager::updateResponseSlot(QNetworkReply *reply) { QString tmp(reply->readAll()); if (tmp.isEmpty()) { emit updateErrorSignal(); return; } QStringList s = tmp.split(";", QString::SkipEmptyParts); if (s.size() < 1) { //software_build; emit updateErrorSignal(); return; } bool softwareUpdate; bool a; int softwareBuild = s.at(0).toInt(&a); if (!a) { emit updateErrorSignal(); return; } softwareUpdate = softwareBuild > DefinitionHolder::SOFTWARE_BUILD; if (softwareUpdate) { int r = QMessageBox::question(0, tr("New Software Version"), tr("A new version of %1 is available!<br>" "Do you want to download the new version?") .arg(DefinitionHolder::NAME), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (r == QMessageBox::Yes) { QUrl downloadUrl(DefinitionHolder::DOWNLOAD_URL); QDesktopServices::openUrl(downloadUrl); emit updatesAccepted(); } } else { //no updates available emit noUpdateSignal(); } //delete reply reply->deleteLater(); }
void Fetcher::search() { updatePageCount(); if ( (ui->leQuery->text().isEmpty()) && (ui->cbSite->itemText(ui->cbSite->currentIndex()).isEmpty()) ) showErrorMessage("<h3>No search terms entered.</h3><p>Please enter some search terms, or specify a site to search in the 'More Options' section.</p>",this); else if (queryResultsCount.find(ui->leQuery->text()).value() > 7) showErrorMessage("The maximum number of results for this search term has been reached. Try a different search term.",this); else { QUrl tmpUrl = composeUrl(); downloadUrl(tmpUrl); (*queryResultsCount.find(ui->leQuery->text()))++; } }
void UpdateInfo::writeElement( QXmlStreamWriter &xml ) { xml.writeStartElement( QLatin1String("owncloudclient") ); if ( !version().isEmpty() ) { xml.writeTextElement( QLatin1String("version"), version() ); } if ( !versionString().isEmpty() ) { xml.writeTextElement( QLatin1String("versionstring"), versionString() ); } if ( !web().isEmpty() ) { xml.writeTextElement( QLatin1String("web"), web() ); } if ( !downloadUrl().isEmpty() ) { xml.writeTextElement( QLatin1String("downloadurl"), web() ); } xml.writeEndElement(); }
//! [2] void DownloadManager::downloadFinished() { // Reset the progress information when the download has finished m_progressTotal = 0; m_progressValue = 0; m_progressMessage.clear(); emit progressValueChanged(); emit progressTotalChanged(); emit progressMessageChanged(); // Close the file where the data have been written m_output.close(); // Add a status or error message if (m_currentDownload->error()) { addErrorMessage(QString("Failed: %1").arg(m_currentDownload->errorString())); } else if (m_currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) { m_output.remove(); QUrl redirecturl = m_currentDownload->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); if(redirecturl.isValid() && (redirecturl != m_currentDownload->url())) /* Avoid Fake/Redirect Loop */ { downloadUrl(redirecturl.toString()); } } else { addStatusMessage("Succeeded."); ++m_downloadedCount; } /** * We can't call 'delete m_currentDownload' here, because this method might have been invoked directly as result of a signal * emission of the network reply object. */ m_currentDownload->deleteLater(); m_currentDownload = 0; emit activeDownloadsChanged(); basename = ""; // Trigger the execution of the next job startNextDownload(); }
NS_IMETHODIMP nsCRLManager::UpdateCRLFromURL( const PRUnichar *url, const PRUnichar* key, bool *res) { nsresult rv; nsAutoString downloadUrl(url); nsAutoString dbKey(key); nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); if(NS_FAILED(rv)){ *res = false; return rv; } rv = nssComponent->DownloadCRLDirectly(downloadUrl, dbKey); if(NS_FAILED(rv)){ *res = false; } else { *res = true; } return NS_OK; }
JNIEXPORT jbyteArray JNICALL Java_com_example_androidtest_TestActivity_downloadUrl(JNIEnv* env, jobject obj, jstring url ){ const char* url_c = env->GetStringUTFChars(url, NULL); if (!url_c) return NULL; LOGI( "Download URL: %s", url_c ); CURL_DOWNLOAD_OBJECT* downloadObject = new CURL_DOWNLOAD_OBJECT; downloadObject->data = NULL; downloadObject->size=0; if (downloadUrl(url_c, downloadObject)){ env->ReleaseStringUTFChars(url, url_c); jbyteArray ret = env->NewByteArray(downloadObject->size); env->SetByteArrayRegion(ret, 0, downloadObject->size, (jbyte*)downloadObject->data); free(downloadObject->data); delete downloadObject; return ret; }else{ env->ReleaseStringUTFChars(url, url_c); return NULL; } }
wordsImporter::wordsImporter(bool backTrans, QString src, QString dst, QObject * parent) : QObject(parent) , backTranslation(backTrans) { words = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); cleanWords = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); backtransl = new wordsBuilder (QString("%1-%2-%2").arg(src).arg(dst)); pica = new picturesDownloader(); sndUrl = new soundUrlExtractor(QString("%1-%2").arg(src).arg(dst)); sndDownloader = new urlDownloader (); connect (this, SIGNAL(wowNewWord(QString)), words, SLOT(add(QString)), Qt::QueuedConnection); connect (words, SIGNAL(cleanWord(QString)), cleanWords, SLOT(add(QString)), Qt::QueuedConnection); connect (cleanWords, SIGNAL(cleanWord(QString, QByteArray)), this, SLOT(returnWord(QString, QByteArray)), Qt::QueuedConnection); connect (this, SIGNAL(translateItBack(QString)), backtransl, SLOT(add(QString)), Qt::QueuedConnection); connect (this, SIGNAL(picturize(QString)), pica, SLOT(add(QString)), Qt::QueuedConnection); connect (this, SIGNAL(soundize(QString)), sndUrl, SLOT(add(QString)), Qt::QueuedConnection); connect (sndUrl, SIGNAL(downloadUrl(QString, QUrl)), sndDownloader, SLOT(add(QString, QUrl)), Qt::QueuedConnection); connect (sndDownloader, SIGNAL(downloadDone(QString, QByteArray)), this, SLOT(saveSnd(QString, QByteArray)), Qt::QueuedConnection); connect (backtransl, SIGNAL(cleanWord(QString, QByteArray)), this, SLOT(saveCard(QString, QByteArray)), Qt::QueuedConnection); }
bool SRTMProvider::downloadZipFile(int fileIndex, QString fileName, QFile &zipFile){ //Bugfixversuch: fileIndex QString altZipUrl = _url.toString() + fileList[fileIndex]; //Url bis .hgt.zip // //Bugfixversuch: fileIndex altZipUrl.toAscii().constData(); QUrl srtmUrl(altZipUrl); QByteArray data; downloadUrl(srtmUrl, data); // Zipfile soll nun runtergeladen werden. if(data.isEmpty()){ std::cout << "Fehler beim downloaden der Daten für " << fileList[fileIndex] << "." << std::endl; return false; // download failed } QFileInfo fileInfo(fileName); QString filePath = fileInfo.absolutePath(); QDir makedir; makedir.mkpath(filePath); zipFile.open(QIODevice::WriteOnly); zipFile.write(data); // Speichern des geladenen Zipfiles zipFile.close(); return true; // download successful }
void DownloadThread::downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& cookies) { // Process request QNetworkReply *reply = downloadUrl(url, cookies); connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(checkDownloadSize(qint64,qint64))); }
void DownloadThread::processDlFinished(QNetworkReply* reply) { QString url = reply->url().toString(); qDebug("Download finished: %s", qPrintable(url)); // Check if the request was successful if (reply->error() != QNetworkReply::NoError) { // Failure qDebug("Download failure (%s), reason: %s", qPrintable(url), qPrintable(errorCodeToString(reply->error()))); emit downloadFailure(url, errorCodeToString(reply->error())); reply->deleteLater(); return; } // Check if the server ask us to redirect somewhere lese const QVariant redirection = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (redirection.isValid()) { // We should redirect QUrl newUrl = redirection.toUrl(); // Resolve relative urls if (newUrl.isRelative()) newUrl = reply->url().resolved(newUrl); const QString newUrlString = newUrl.toString(); qDebug("Redirecting from %s to %s", qPrintable(url), qPrintable(newUrlString)); m_redirectMapping.insert(newUrlString, url); // redirecting with first cookies downloadUrl(newUrlString, m_networkManager.cookieJar()->cookiesForUrl(url)); reply->deleteLater(); return; } // Checking if it was redirected, restoring initial URL if (m_redirectMapping.contains(url)) { url = m_redirectMapping.take(url); } // Success QTemporaryFile *tmpfile = new QTemporaryFile; if (tmpfile->open()) { tmpfile->setAutoRemove(false); QString filePath = tmpfile->fileName(); qDebug("Temporary filename is: %s", qPrintable(filePath)); if (reply->isOpen() || reply->open(QIODevice::ReadOnly)) { QByteArray replyData = reply->readAll(); if (reply->rawHeader("Content-Encoding") == "gzip") { // uncompress gzip reply replyData = gUncompress(reinterpret_cast<unsigned char*>(replyData.data()), replyData.length()); } tmpfile->write(replyData); tmpfile->close(); // XXX: tmpfile needs to be deleted on Windows before using the file // or it will complain that the file is used by another process. delete tmpfile; // Send finished signal emit downloadFinished(url, filePath); } else { delete tmpfile; fsutils::forceRemove(filePath); // Error when reading the request emit downloadFailure(url, tr("I/O Error")); } } else { delete tmpfile; emit downloadFailure(url, tr("I/O Error")); } // Clean up reply->deleteLater(); }
void SRTMProvider::createFileList() { QStringList continents; continents << "Africa" << "Australia" << "Eurasia" << "Islands" << "North_America" << "South_America"; QString url = _url.toString(); QStringList dateiListe; int capCount = 0; int lat; int lon; int pos = 0; foreach (QString continent, continents) { // für jeden Kontinent, die vorhandenen Ziparchive in die Liste eintragen QString urlTemp = QString(url+continent+"/").toAscii().constData(); // Kontinent zur url hinzufügen QUrl srtmUrl(urlTemp); // urlTemp zu QUrl casten, für spätere Verwendung. QString replyString; // Hierein wird später die NetworkReply aus downloadUrl gespeichert. downloadUrl(srtmUrl, replyString); if(!replyString.isEmpty()) // Erstellen der Liste, falls Download erfolgreich. { QRegExp regex("<li>\\s*<a\\s+href=\"([^\"]+)"); regex.indexIn(replyString); pos = 0; capCount = 0; dateiListe.clear(); while ((pos = regex.indexIn(replyString, pos)) != -1) { dateiListe << regex.cap(1); pos += regex.matchedLength(); capCount++; } QRegExp innerRx("([NS])(\\d{2})([EW])(\\d{3})"); for (int i = 0; i < capCount; i++){ int po = innerRx.indexIn(dateiListe[i]); if (po > -1){ lat = innerRx.cap(2).toInt(); lon = innerRx.cap(4).toInt(); if (innerRx.cap(1) == "S") { lat = -lat; } if (innerRx.cap(3) == "W") { lon = - lon; } //S00E000.hgt.zip //123456789012345 => 15 bytes long fileList[latLonToIndex(lat, lon)] = continent+"/"+dateiListe[i].right(15); } } } else { std::cout << "Fehler beim laden der Daten für " << continent << "." << std::endl; } } // end: foreach(QString continent, continents)