void FQTermHttp::getLink(const QUrl& url, bool preview) { QUrl u=url; isExisting_ = false; isPreview_ = preview; previewEmitted = false; lastPercent_ = 0; if (u.isRelative() || u.scheme() == "file") { emit previewImage(cacheFileName_, false, true); emit done(this); return ; } if (QFile::exists(getPath(USER_CONFIG) + "hosts.cfg")) { config_ = new FQTermConfig(getPath(USER_CONFIG) + "hosts.cfg"); QString strTmp = config_->getItemValue("hosts", u.host().toLocal8Bit()); if (!strTmp.isEmpty()) { QString strUrl = u.toString(); strUrl.replace(QRegExp(u.host(), Qt::CaseInsensitive), strTmp); u = strUrl; } } if (!(netreply_ && netreply_->hasRawHeader("Location"))) { cacheFileName_ = QFileInfo(u.path()).fileName(); } if(netreply_){ netreply_->blockSignals(true); netreply_.take()->deleteLater(); } netreply_.reset(nam_->get(QNetworkRequest(u))); FQ_VERIFY(connect(netreply_.data(), SIGNAL(finished()), this, SLOT(httpDone()))); FQ_VERIFY(connect(netreply_.data(), SIGNAL(downloadProgress(qint64, qint64)),this, SLOT(httpRead(qint64, qint64)))); FQ_VERIFY(connect(netreply_.data(), SIGNAL(error( QNetworkReply::NetworkError)), this, SLOT(httpError(QNetworkReply::NetworkError)))); FQ_VERIFY(connect(netreply_.data(), SIGNAL(metaDataChanged()), this, SLOT(httpResponse()))); }
void GetBase::getBaseHttp() { progressDialog = new QProgressDialog(this); fileHttp = new QFile("Yarn.dat"); fileHttp->open(QIODevice::WriteOnly); url = "http://91.102.219.74/QtProject/Yarn/Base/Yarn.dat"; //url = "http://91.102.219.74/QtProject/Yarn/Yarn.exe"; reply = http.get(QNetworkRequest(url)); connect(reply,SIGNAL(readyRead()),this,SLOT(httpReadyRead())); connect(reply,SIGNAL(finished()),this,SLOT(httpDone())); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(updateDataReadProgress(qint64,qint64))); connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this, SLOT(updateDataReadProgress(qint64,qint64))); progressDialog->setLabelText(tr("Downloading DataBase ...")); progressDialog->setEnabled(true); progressDialog->exec(); }
void HttpGet::getFileFinish() { m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash; QString indexFile = m_cachedir.absolutePath() + "/rbutil-cache/cache.txt"; if(m_usecache) { // check if the file is present in cache QFileInfo cachefile = QFileInfo(m_cachefile); if(cachefile.isReadable() && cachefile.size() > 0 && cachefile.lastModified() > m_serverTimestamp) { qDebug() << "[HTTP] Cache: up-to-date file found:" << m_cachefile; getRequest = -1; QFile c(m_cachefile); if(!outputToBuffer) { qDebug() << "[HTTP] Cache: copying file to output" << outputFile->fileName(); c.open(QIODevice::ReadOnly); outputFile->open(QIODevice::ReadWrite); outputFile->write(c.readAll()); outputFile->close(); c.close(); } else { qDebug() << "[HTTP] Cache: reading file into buffer"; c.open(QIODevice::ReadOnly); dataBuffer = c.readAll(); c.close(); } m_response = 200; // fake "200 OK" HTTP response m_cached = true; httpDone(false); // we're done now. Handle http "done" signal. return; } else { // unlink old cache file if(cachefile.isReadable()) { QFile(m_cachefile).remove(); qDebug() << "[HTTP] Cache: outdated, timestamp:" << cachefile.lastModified(); } qDebug() << "[HTTP] Cache: caching as" << m_cachefile; // update cache index file QFile idxFile(indexFile); idxFile.open(QIODevice::ReadOnly); QByteArray currLine; do { QByteArray currLine = idxFile.readLine(1000); if(currLine.startsWith(m_hash.toUtf8())) break; } while(!currLine.isEmpty()); idxFile.close(); if(currLine.isEmpty()) { idxFile.open(QIODevice::Append); QString outline = m_hash + "\t" + m_header.value("Host") + "\t" + m_path + "\t" + m_query + "\n"; idxFile.write(outline.toUtf8()); idxFile.close(); } } } else { qDebug() << "[HTTP] cache DISABLED"; } // schedule GET request m_header.setRequest("GET", m_path + m_query); if(outputToBuffer) { qDebug() << "[HTTP] downloading to buffer."; getRequest = http.request(m_header); } else { qDebug() << "[HTTP] downloading to file:" << qPrintable(outputFile->fileName()); getRequest = http.request(m_header, 0, outputFile); } qDebug() << "[HTTP] GET scheduled: " << getRequest; return; }