diff options
Diffstat (limited to 'examples/network/http')
-rw-r--r-- | examples/network/http/httpwindow.cpp | 32 | ||||
-rw-r--r-- | examples/network/http/httpwindow.h | 4 |
2 files changed, 23 insertions, 13 deletions
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index 9640907673..ec90b8f7fe 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -55,12 +55,12 @@ #include "httpwindow.h" #include "ui_authenticationdialog.h" -#ifndef QT_NO_SSL -static const char defaultUrl[] = "https://www.qt.io/"; +#if QT_CONFIG(ssl) +const char defaultUrl[] = "https://www.qt.io/"; #else -static const char defaultUrl[] = "http://www.qt.io/"; +const char defaultUrl[] = "http://www.qt.io/"; #endif -static const char defaultFileName[] = "index.html"; +const char defaultFileName[] = "index.html"; ProgressDialog::ProgressDialog(const QUrl &url, QWidget *parent) : QProgressDialog(parent) @@ -71,6 +71,7 @@ ProgressDialog::ProgressDialog(const QUrl &url, QWidget *parent) setMinimum(0); setValue(0); setMinimumDuration(0); + setMinimumSize(QSize(400, 75)); } void ProgressDialog::networkReplyProgress(qint64 bytesRead, qint64 totalBytes) @@ -174,15 +175,22 @@ void HttpWindow::downloadFile() if (fileName.isEmpty()) fileName = defaultFileName; QString downloadDirectory = QDir::cleanPath(downloadDirectoryLineEdit->text().trimmed()); - if (!downloadDirectory.isEmpty() && QFileInfo(downloadDirectory).isDir()) + bool useDirectory = !downloadDirectory.isEmpty() && QFileInfo(downloadDirectory).isDir(); + if (useDirectory) 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) + tr("There already exists a file called %1%2." + " Overwrite?") + .arg(fileName, + useDirectory + ? QString() + : QStringLiteral(" in the current directory")), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No) + == QMessageBox::No) { return; + } QFile::remove(fileName); } @@ -252,7 +260,9 @@ void HttpWindow::httpFinished() if (QMessageBox::question(this, tr("Redirect"), tr("Redirect to %1 ?").arg(redirectedUrl.toString()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { + QFile::remove(fi.absoluteFilePath()); downloadButton->setEnabled(true); + statusLabel->setText(tr("Download failed:\nRedirect rejected.")); return; } file = openFileForWrite(fi.absoluteFilePath()); @@ -286,7 +296,7 @@ void HttpWindow::enableDownloadButton() downloadButton->setEnabled(!urlLineEdit->text().isEmpty()); } -void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator) +void HttpWindow::slotAuthenticationRequired(QNetworkReply *, QAuthenticator *authenticator) { QDialog authenticationDialog; Ui::Dialog ui; @@ -306,7 +316,7 @@ void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authe } #ifndef QT_NO_SSL -void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors) +void HttpWindow::sslErrors(QNetworkReply *, const QList<QSslError> &errors) { QString errorString; foreach (const QSslError &error, errors) { diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h index f942c33952..20ad2bb4da 100644 --- a/examples/network/http/httpwindow.h +++ b/examples/network/http/httpwindow.h @@ -92,9 +92,9 @@ private slots: void httpFinished(); void httpReadyRead(); void enableDownloadButton(); - void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *); + void slotAuthenticationRequired(QNetworkReply *, QAuthenticator *authenticator); #ifndef QT_NO_SSL - void sslErrors(QNetworkReply*,const QList<QSslError> &errors); + void sslErrors(QNetworkReply *, const QList<QSslError> &errors); #endif private: |