From c89c37b52f31e10a82cae2ecfac957184f9dab51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Wed, 11 Jan 2023 18:19:39 +0100 Subject: [PATCH] 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 --- examples/network/http/httpwindow.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index 242c3df73e1..5edc2838f6c 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -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); }