HTTP example: Fix missing translation and improve others

As a drive-by: print the path with native separators

Task-number: QTBUG-108874
Pick-to: 6.5
Change-Id: I73164acb159d1a45960e16d5f57996e8c27257f7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Mårten Nordheim 2023-01-11 18:19:39 +01:00
parent 7c90881a8e
commit c89c37b52f

View File

@ -1,4 +1,4 @@
// Copyright (C) 2020 The Qt Company Ltd.
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "httpwindow.h"
@ -42,7 +42,7 @@ HttpWindow::HttpWindow(QWidget *parent)
, statusLabel(new QLabel(tr("Please enter the URL of a file you want to download.\n\n"), this))
, urlLineEdit(new QLineEdit(defaultUrl))
, downloadButton(new QPushButton(tr("Download")))
, launchCheckBox(new QCheckBox("Launch file"))
, launchCheckBox(new QCheckBox(tr("Launch file")))
, defaultFileLineEdit(new QLineEdit(defaultFileName))
, downloadDirectoryLineEdit(new QLineEdit)
{
@ -142,19 +142,18 @@ void HttpWindow::downloadFile()
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%2."
" Overwrite?")
.arg(fileName,
useDirectory
? QString()
: QStringLiteral(" in the current directory")),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No)
== QMessageBox::No) {
QString alreadyExists = useDirectory
? tr("There already exists a file called %1. Overwrite?")
: tr("There already exists a file called %1 in the current directory. "
"Overwrite?");
QMessageBox::StandardButton response = QMessageBox::question(this,
tr("Overwrite Existing File"),
alreadyExists.arg(QDir::toNativeSeparators(fileName)),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (response == QMessageBox::No)
return;
}
QFile::remove(fileName);
}