void HttpWindow::downloadFile()
{
QString qsLink
= urlLineEdit
->text
();
QString qsFileName
= qfiFileInfor.
fileName();
if (qsFileName.isEmpty())
qsFileName = "index.html";
if (QFile::exists(qsFileName
)) { return;
}
QFile::remove(qsFileName
);
}
qfFileOut
= new QFile(qsFileName
);
if (!qfFileOut
->open
(QIODevice::WriteOnly)) { QMessageBox::information(this, tr
("HTTP"),tr
("Unable to save the file %1: %2.").
arg(qsFileName
).
arg(qfFileOut
->errorString
()));
delete qfFileOut;
qfFileOut = 0;
return;
}
QHttp::ConnectionMode qhconMode
= quUrl.
scheme().
toLower() == "https" ?
QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
qhHttp->setHost(qsHost, qhconMode, quUrl.port() == -1 ? 0 : quUrl.port());
if (!quUrl.userName().isEmpty())
qhHttp->setUser(quUrl.userName(), quUrl.password());
bHttpRequestAborted = false;
QByteArray qbaUrlPath
= QUrl::toPercentEncoding(qsUrlPath,
"!$&'()*+,;=:@/");
if (qbaUrlPath.isEmpty())
qbaUrlPath = "/";//_________________________________________
qhrhHeader->setValue("Connection", "Keep-Alive");
qhrhHeader->setValue("Accept-Ranges", "byte");
/*qhrhHeader->setValue("Content-Length", "1024");
qhrhHeader->setValue("Content-Type", "application/x-rar-compressed");*/
qhrhHeader->setValue("User-Agent", "Mozilla/5.0");
qhrhHeader->setValue("Range", "bytes=0-999");
qhrhHeader->setValue("Host", qsHost);
iHttpGetId = qhHttp->request(*qhrhHeader, 0, qfFileOut);//_________________________________
qpProgressDialog->setWindowTitle(tr("HTTP"));
qpProgressDialog->setLabelText(tr("Downloading %1.").arg(qsFileName));
downloadButton->setEnabled(false);
}
void HttpWindow::downloadFile()
{
QString qsLink = urlLineEdit->text();
QUrl quUrl(qsLink);
QString qsUrlPath = quUrl.path();
QFileInfo qfiFileInfor(qsUrlPath);
QString qsFileName = qfiFileInfor.fileName();
if (qsFileName.isEmpty())
qsFileName = "index.html";
if (QFile::exists(qsFileName)) {
if (QMessageBox::question(this, tr("HTTP"), tr("There already exists a file called %1 in the current directory. Overwrite?").arg(qsFileName), QMessageBox::Yes|QMessageBox::No, QMessageBox::No)== QMessageBox::No){
return;
}
QFile::remove(qsFileName);
}
qfFileOut = new QFile(qsFileName);
if (!qfFileOut->open(QIODevice::WriteOnly)) {
QMessageBox::information(this, tr("HTTP"),tr("Unable to save the file %1: %2.").arg(qsFileName).arg(qfFileOut->errorString()));
delete qfFileOut;
qfFileOut = 0;
return;
}
QString qsHost = quUrl.host();
QHttp::ConnectionMode qhconMode = quUrl.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
qhHttp->setHost(qsHost, qhconMode, quUrl.port() == -1 ? 0 : quUrl.port());
if (!quUrl.userName().isEmpty())
qhHttp->setUser(quUrl.userName(), quUrl.password());
bHttpRequestAborted = false;
QByteArray qbaUrlPath = QUrl::toPercentEncoding(qsUrlPath, "!$&'()*+,;=:@/");
if (qbaUrlPath.isEmpty())
qbaUrlPath = "/";//_________________________________________
QHttpRequestHeader *qhrhHeader = new QHttpRequestHeader("GET", qbaUrlPath);
qhrhHeader->setValue("Connection", "Keep-Alive");
qhrhHeader->setValue("Accept-Ranges", "byte");
/*qhrhHeader->setValue("Content-Length", "1024");
qhrhHeader->setValue("Content-Type", "application/x-rar-compressed");*/
qhrhHeader->setValue("User-Agent", "Mozilla/5.0");
qhrhHeader->setValue("Range", "bytes=0-999");
qhrhHeader->setValue("Host", qsHost);
iHttpGetId = qhHttp->request(*qhrhHeader, 0, qfFileOut);//_________________________________
qpProgressDialog->setWindowTitle(tr("HTTP"));
qpProgressDialog->setLabelText(tr("Downloading %1.").arg(qsFileName));
downloadButton->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
Bookmarks