void Geolocation::resetAllGeolocationPermission() { if (m_isSuspended) { m_resetOnResume = true; return; } if (m_allowGeolocation == InProgress) { Page* page = this->page(); if (page) GeolocationController::from(page)->cancelPermissionRequest(*this); // This return is not technically correct as GeolocationController::cancelPermissionRequest() should have cleared the active request. // Neither iOS nor OS X supports cancelPermissionRequest() (https://bugs.webkit.org/show_bug.cgi?id=89524), so we workaround that and let ongoing requests complete. :( return; } // 1) Reset our own state. stopUpdating(); m_allowGeolocation = Unknown; m_hasChangedPosition = false; m_errorWaitingForResume = nullptr; // 2) Request new permission for the active notifiers. stopTimers(); // Go over the one shot and re-request permission. for (auto& notifier : m_oneShots) startRequest(notifier.get()); // Go over the watchers and re-request permission. GeoNotifierVector watcherCopy; m_watchers.getNotifiersVector(watcherCopy); for (auto& watcher : watcherCopy) startRequest(watcher.get()); }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); ui->stopButton->hide(); ui->imgDebug->hide(); mjpegLine1.append("--BoundaryString\r\n" "Content-type: image/jpeg\r\n" "Content-Length:\\s+"); mjpegLine2.append("\\d+"); mjpegLine3.append("(\r\n)+"); jpegBA.clear(); frameStarted = false; response.clear(); url = QUrl::fromEncoded("http://192.168.0.146:8081"); // url = QUrl::fromEncoded("http://24.52.217.108:8090"); startRequest(url); // imageReady=false; // status=0; // ui->imgDebug->hide(); // ui->imgOutput->hide(); }
bool HttpGet::getFile(const QUrl &url) { if (!url.isValid()) { std::cerr << "Error: Invalid URL" << std::endl; return false; } if (url.scheme() != "http") { std::cerr << "Error: URL must start with 'http:'" << std::endl; return false; } if (url.path().isEmpty()) { std::cerr << "Error: URL has no path" << std::endl; return false; } QString localFileName = QFileInfo(url.path()).fileName(); if (localFileName.isEmpty()) localFileName = "httpget.html"; file.setFileName(localFileName); if (!file.open(QIODevice::WriteOnly)) { std::cerr << "Error: Cannot write file " << qPrintable(file.fileName()) << ": " << qPrintable(file.errorString()) << std::endl; return false; } startRequest(url); return true; }
void MediaDownload::taskFinished() { QMutexLocker l(&m_bufferLock); /* These should both be true or both be false, anything else is a logic error. * This test does assume that we will never download the same byte twice. */ Q_ASSERT(!(m_bufferRanges.contains(Range::fromStartSize(0, m_fileSize)) ^ (m_downloadedSize >= m_fileSize))); if (m_bufferRanges.contains(Range::fromStartSize(0, m_fileSize))) { qDebug() << "MediaDownload: Media finished"; m_isFinished = true; bool ok = metaObject()->invokeMethod(this, "finished", Qt::QueuedConnection); Q_ASSERT(ok); ok = metaObject()->invokeMethod(this, "stopped", Qt::QueuedConnection); Q_ASSERT(ok); Q_UNUSED(ok); } else { /* Launch a new task to fill in gaps. Prioritize anything that is missing and is closest * to the current read position. */ Range missingRange = m_bufferRanges.nextMissingRange(Range::fromStartEnd(m_readPos, m_fileSize)); Q_ASSERT(missingRange.isValid()); m_writePos = missingRange.start(); startRequest(missingRange.start(), missingRange.size()); } }
void HttpRequest::httpFinished() { QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (reply->error()) { qFatal("Network error"); exit(-1); } else if (!redirectionTarget.isNull()) { url = url.resolved(redirectionTarget.toUrl()); reply->deleteLater(); startRequest(); return; } reply->deleteLater(); qnam->deleteLater(); if (saveToFile) { emit downloadComplete(file->fileName()); file->deleteLater(); } else { emit downloadComplete(QString(*data)); delete data; } httpRequestComplete = true; emit downloadComplete(); }
bool simpleGet(MprTestGroup *gp, cchar *uri, int expectStatus) { HttpConn *conn; int status; if (expectStatus <= 0) { expectStatus = 200; } if (startRequest(gp, "GET", uri) < 0) { return 0; } conn = getConn(gp); httpFinalizeOutput(conn); if (httpWait(conn, HTTP_STATE_COMPLETE, -1) < 0) { return MPR_ERR_CANT_READ; } status = httpGetStatus(gp->conn); tassert(status == expectStatus); if (status != expectStatus) { mprLog("appweb test get", 0, "HTTP response code %d, expected %d", status, expectStatus); return 0; } tassert(httpGetError(gp->conn) != 0); gp->content = httpReadString(gp->conn); tassert(gp->content != NULL); httpDestroyConn(gp->conn); gp->conn = 0; return 1; }
void MusicDataDownloadThread::downLoadFinished() { if(!m_file) { deleteAll(); return; } m_timer.stop(); m_file->flush(); m_file->close(); QVariant redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if(m_reply->error()) { m_file->remove(); } else if(!redirectionTarget.isNull()) { m_redirection = true; m_reply->deleteLater(); m_file->open(QIODevice::WriteOnly); m_file->resize(0); startRequest(m_reply->url().resolved(redirectionTarget.toUrl())); return; } else { emit downLoadDataChanged("Data"); M_LOGGER_INFO("data download has finished!"); } deleteAll(); }
void xtNetworkRequestManager::requestCompleted() { _response = _nwrep->readAll(); //we don't really care here but store it anyways _nwrep->close(); QVariant possibleRedirect = _nwrep->attribute(QNetworkRequest::RedirectionTargetAttribute); if(DEBUG){ qDebug() << "redirect=" << possibleRedirect.isValid(); qDebug() << "replyError=" << _nwrep->errorString(); qDebug() << "replyErrorCode=" << _nwrep->error(); } if(_nwrep->error() != QNetworkReply::NoError){ qDebug() << "network reply error on request" << _nwrep->error() << _nwrep->errorString(); _nwrep->deleteLater(); _mutex->unlock(); } if(_nwrep->error() == QNetworkReply::NoError && !possibleRedirect.isValid()){ //success and no redirect _nwrep->deleteLater(); _mutex->unlock(); } else { QUrl newUrl = _url.resolved(possibleRedirect.toUrl()); _nwrep->deleteLater(); startRequest(newUrl); } }
bool MediaDownload::seek(unsigned offset) { QMutexLocker l(&m_bufferLock); if (m_hasError) return false; if (offset > m_fileSize) { qDebug() << "MediaDownload: seek offset" << offset << "is past the end of filesize" << m_fileSize; return false; } if (m_readPos == offset) return true; m_readPos = offset; Range missingRange = m_bufferRanges.nextMissingRange(Range::fromStartEnd(m_readPos - qMin(m_readPos, seekMinimumSkip), m_fileSize)); if (missingRange.isValid()) { if (missingRange.start() >= m_writePos && missingRange.start() - m_writePos < seekMinimumSkip) { /* We're already downloading at the correct position; nothing to do */ } else { qDebug() << "MediaDownload: launching new request after seek"; m_writePos = missingRange.start(); startRequest(missingRange.start(), missingRange.size()); } } m_bufferWait.wakeAll(); return true; }
void HttpWindow::downloadFile() { const QString urlSpec = "http://www.youtubeinmp3.com/fetch/?video=" + urlLineEdit->text().trimmed(); if (urlSpec.isEmpty()) return; const QUrl newUrl = QUrl::fromUserInput(urlSpec); if (!newUrl.isValid()) { QMessageBox::information(this, tr("Error"), tr("Invalid URL: %1: %2").arg(urlSpec, newUrl.errorString())); return; } QString fileName = newUrl.fileName(); if (fileName.isEmpty()) fileName = defaultFileLineEdit->text().trimmed(); if (fileName.isEmpty()) fileName = defaultFileName; QString downloadDirectory = QDir::cleanPath(downloadDirectoryLineEdit->text().trimmed()); if (!downloadDirectory.isEmpty() && QFileInfo(downloadDirectory).isDir()) fileName.prepend(downloadDirectory + '/'); if (QFile::exists(fileName)) { if (QMessageBox::question(this, tr("Overwrite Existing File"), tr("There already exists a file called %1 in " "the current directory. Overwrite?").arg(fileName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No) return; QFile::remove(fileName); } file = openFileForWrite(fileName); if (!file) return; downloadButton->setEnabled(false); // schedule the request //Download QQueue if (songBeingDownloaded == true)//song is being downloaded currently songsThatNeedToBeDownloaded.enqueue(newUrl); else startRequest(newUrl); /** else if (!songsThatNeedToBeDownloaded.isEmpty()) { songsThatNeedToBeDownloaded.enqueue(newUrl); while (!songsThatNeedToBeDownloaded.isEmpty() && songBeingDownloaded == false) { QUrl tempURL = songsThatNeedToBeDownloaded.dequeue(); startRequest(tempURL); } } else startRequest(newUrl); */ }
//获取网页图片函数 void MainWindow::getUrlPic() { QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间 QString urlTmp = "http://192.168.1.222:8088/wlis3/ValidationCodeServlet?t="; urlTmp.append(time.toString()); qDebug() << "urlTmp" << urlTmp; url = QUrl(urlTmp); startRequest(url); //进行链接请求 }
void Updater::checkForUpdates(bool silent) { mSilent = silent; // schedule the request httpRequestAborted = false; startRequest(); }
void Geolocation::getCurrentPosition(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options) { if (!m_frame) return; RefPtr<GeoNotifier> notifier = startRequest(successCallback, errorCallback, options); ASSERT(notifier); m_oneShots.add(notifier); }
void Geolocation::getCurrentPosition(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options) { if (!frame()) return; RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options); startRequest(notifier.get()); m_oneShots.add(notifier); }
xtNetworkRequestManager::xtNetworkRequestManager(const QUrl & url, QMutex &mutex) { nwam = new QNetworkAccessManager; _nwrep = 0; _response = 0; _url = url; _mutex = &mutex; _mutex->lock(); _loop = new QEventLoop; startRequest(_url); }
void KConcatFetchObject::readBody(KHttpRequest *rq) { KConcatPath *cp = hot; if (cp==NULL) { stage_rdata_end(rq,STREAM_WRITE_SUCCESS); return; } hot = hot->next; startRequest(rq,cp); }
void Geolocation::getCurrentPosition(PositionCallback* successCallback, PositionErrorCallback* errorCallback, const PositionOptions& options) { if (!frame()) return; GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCallback, options); startRequest(notifier); m_oneShots.add(notifier); }
void Geolocation::getCurrentPosition(Ref<PositionCallback>&& successCallback, RefPtr<PositionErrorCallback>&& errorCallback, PositionOptions&& options) { if (!frame()) return; auto notifier = GeoNotifier::create(*this, WTFMove(successCallback), WTFMove(errorCallback), WTFMove(options)); startRequest(notifier.ptr()); m_oneShots.add(WTFMove(notifier)); }
void NativeWindowRenderer::destroyRenderInput(RenderInput* input) { ALOGD("destroy render input %d", input->mTextureId); GLuint textureId = input->mTextureId; delete input; startRequest(CMD_DELETE_TEXTURE); mThreadTextureId = textureId; sendRequest(); mActiveInputs--; }
RenderInput* NativeWindowRenderer::createRenderInput() { ALOGD("new render input %d", mNextTextureId); RenderInput* input = new RenderInput(this, mNextTextureId); startRequest(CMD_RESERVE_TEXTURE); mThreadTextureId = mNextTextureId; sendRequest(); mNextTextureId++; mActiveInputs++; return input; }
void YunClient::getUpdateVersionList() { if (QDateTime::fromString(lineedit_start->text(), "yyyy-MM-dd") > QDateTime::fromString(lineedit_end->text(), "yyyy-MM-dd")){ QMessageBox::warning(this, "提示", "开始时间不能大于结束时间"); return; } request_type = get_version_list; QByteArray url = getUrl("/ml/rs/mediaReleaseVersions/"); startRequest(url); }
int Geolocation::watchPosition(PassRefPtr<PositionCallback> successCallback, PassRefPtr<PositionErrorCallback> errorCallback, PassRefPtr<PositionOptions> options) { if (!frame()) return 0; RefPtr<GeoNotifier> notifier = GeoNotifier::create(this, successCallback, errorCallback, options); startRequest(notifier.get()); int watchID = m_scriptExecutionContext->newUniqueID(); m_watchers.set(watchID, notifier.release()); return watchID; }
ScriptPromise PushRegistrationManager::registerPush(ExecutionContext* executionContext) { ScriptPromise promise = ScriptPromise::createPending(executionContext); RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(promise, executionContext); PushRegisterCallback* callback = new PushRegisterCallback(resolver, executionContext); RefPtrWillBeRawPtr<PushNotifier> notifier = PushNotifier::create(this, callback, executionContext); startRequest(notifier.get(), executionContext); return promise; }
void HttpWindow::httpFinished() { if (httpRequestAborted) { if (file) { file->close(); file->remove(); delete file; file = 0; } reply->deleteLater(); #ifndef Q_WS_MAEMO_5 progressDialog->hide(); #endif return; } #ifndef Q_WS_MAEMO_5 progressDialog->hide(); #endif file->flush(); file->close(); QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (reply->error()) { file->remove(); QMessageBox::information(this, tr("HTTP"), tr("Download failed: %1.") .arg(reply->errorString())); downloadButton->setEnabled(true); } else if (!redirectionTarget.isNull()) { QUrl newUrl = url.resolved(redirectionTarget.toUrl()); if (QMessageBox::question(this, tr("HTTP"), tr("Redirect to %1 ?").arg(newUrl.toString()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { url = newUrl; reply->deleteLater(); file->open(QIODevice::WriteOnly); file->resize(0); startRequest(url); return; } } else { QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); statusLabel->setText(tr("Downloaded %1 to %2.").arg(fileName).arg(QDir::currentPath())); downloadButton->setEnabled(true); } reply->deleteLater(); reply = 0; delete file; file = 0; }
//! [5] //! [6] void HttpDownloader::httpFinished() { // All data have been written to the file, so close it m_file->flush(); m_file->close(); const QVariant redirectionTarget = m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (m_reply->error()) { // If there was an error, show an error message in a message box m_messageBoxController.exec(tr("HTTP"), tr("Download failed: %1.").arg(m_reply->errorString()), tr("Ok"), QString()); setStartDownloadPossible(true); } else if (!redirectionTarget.isNull()) { // If we got a redirect response (3XX), retrieve the redirect URL ... const QUrl newUrl = m_url.resolved(redirectionTarget.toUrl()); // ... and ask the user whether the redirected page should be downloaded instead const MessageBoxController::Result result = m_messageBoxController.exec(tr("HTTP"), tr("Redirect to %1 ?").arg(newUrl.toString()), tr("Yes"), tr("No")); if (result == MessageBoxController::Button1) { // If the redirected page should be downloaded, reset the URL ... m_url = newUrl; // ... delete the old network reply object ... m_reply->deleteLater(); // ... reset the target file ... m_file->open(QIODevice::WriteOnly); m_file->resize(0); // ... and trigger a new download request with the new URL. startRequest(); return; } else { setStartDownloadPossible(true); } } else { // If the download was successful, update the status message const QFileInfo actualDir(*m_file); m_statusText = tr("Downloaded %1 to %2.").arg(m_fileName).arg(actualDir.absolutePath()); emit statusTextChanged(); setStartDownloadPossible(true); } // Delete the network reply object m_reply->deleteLater(); m_reply = 0; // Clean up the target file object delete m_file; m_file = 0; }
void ConfigGui::httpDownloadFinished() { // when canceled if (httpRequestAborted) { if (file) { file->close(); file->remove(); delete file; file = 0; } reply->deleteLater(); //progressBar->hide(); return; } // download finished normally //progressBar->hide(); file->flush(); file->close(); // get redirection url QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (reply->error()) { file->remove(); QMessageBox::information(this, tr("HTTP"), tr("Download failed: %1.") .arg(reply->errorString())); updateButton->setEnabled(true); } else if (!redirectionTarget.isNull()) { QUrl newUrl = url.resolved(redirectionTarget.toUrl()); if (QMessageBox::question(this, tr("HTTP"), tr("Redirect to %1 ?").arg(newUrl.toString()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { url = newUrl; reply->deleteLater(); file->open(QIODevice::WriteOnly); file->resize(0); startRequest(url); return; } } else { //QString fileName = QFileInfo(QUrl(URLLineEdit->text()).path()).fileName(); //ui->statusLabel->setText(tr("Downloaded %1 to %2.").arg(fileName).arg(QDir::currentPath())); updateButton->setEnabled(true); fileLineEdit->setText(QFileInfo(*file).absoluteFilePath()); } reply->deleteLater(); reply = 0; delete file; file = 0; }
void HttpWindow::downloadFile() { QString newt; city = urlLineEdit->text(); newt = "https://qt-project.org/"; //maintenant plus besoin du lien, il faut juste choisir la ville entre Paris et sherbrooke.. a améliorer if(city.compare("sherbrooke")==0){ newt = "http://api.openweathermap.org/data/2.5/forecast?id=6146143&appid=b9e492fcafc4d9069398dfcd894d391c"; } if(city.compare("paris")==0){ newt = "http://api.openweathermap.org/data/2.5/forecast?id=6942553&appid=b9e492fcafc4d9069398dfcd894d391c"; } url = newt; QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); if (fileName.isEmpty()) fileName = "index.html"; if (QFile::exists(fileName)) { if (QMessageBox::question(this, tr("HTTP"), tr("There already exists a file called %1 in " "the current directory. Overwrite?").arg(fileName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No) return; QFile::remove(fileName); } file = new QFile(fileName); if (!file->open(QIODevice::WriteOnly)) { QMessageBox::information(this, tr("HTTP"), tr("Unable to save the file %1: %2.") .arg(fileName).arg(file->errorString())); delete file; file = 0; return; } #ifndef Q_WS_MAEMO_5 progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); #endif downloadButton->setEnabled(false); // schedule the request httpRequestAborted = false; startRequest(url); }
void HttpWindow::downloadFile() { statusLabel->setText("Waiting for download pic ..."); statusLabel->show(); changeUrl(bing_url); urlLineEdit->setText(bing_url); url = urlLineEdit->text(); QFile::remove(index_filename); QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); if (fileName.isEmpty()) fileName = "D:/index.html"; else fileName = "D:/bing.jpg"; if (QFile::exists(fileName)) { if (QMessageBox::question(this, tr("HTTP"), tr("There already exists a file called %1 in " "the current directory. Overwrite?").arg(fileName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::No) return; QFile::remove(fileName); } file = new QFile(fileName); if (!file->open(QIODevice::WriteOnly)) { QMessageBox::information(this, tr("HTTP"), tr("Unable to save the file %1: %2.") .arg(fileName).arg(file->errorString())); delete file; file = 0; return; } #ifndef Q_WS_MAEMO_5 progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); #endif downloadButton->setEnabled(false); // schedule the request httpRequestAborted = false; startRequest(url); }
void ThreadedProcessor::processRequest(TransformRequest *request) { quintptr source = request->getptid(); if (isSourceRunning(source)) { if (waitingRequests.contains(source)) { qDebug() << "One request is already waiting for execution, replacing it"; delete waitingRequests.take(request->getptid()); } waitingRequests.insert(source,request); } else { startRequest(request); } }
void TDownlad::run() { //url = QString("http://www.my42.eu/~guss/updates/updater/update.lst"); qDebug()<<"file: " <<path + "/" + url.path().section('/', -1); if(hash == this->CalcSha1(path + "/" + url.path().section('/', -1)) ) { emit done(); return; } else { QTimer tmp2; tmp2.start(500); QEventLoop loop2; connect(&tmp2, SIGNAL(timeout()), &loop2, SLOT(quit())); loop2.exec(); QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); if (fileName.isEmpty()) fileName = "noname"; if (QFile::exists(fileName)) { QFile::remove(fileName); } qDebug() << "dir: " << path << "file: " << fileName; if (path != "" && !QDir(QString(".")).exists(path)) { QDir(QString(".")).mkpath(path); } QString tmp(fileName); if (path != "") tmp.insert(0, path + "/"); file = new QFile(tmp); if (!file->open(QIODevice::WriteOnly)) { delete file; file = 0; qDebug("erreur open fichier"); return; } // schedule the request httpRequestAborted = false; startRequest(url); QEventLoop loop; connect(http, SIGNAL(done(bool)), &loop, SLOT(quit())); loop.exec(); qDebug("end loop thread"); } return; }