From aaf06535d20e9a2610412905b182c95230a61d1f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 20 Aug 2024 16:22:37 +0800 Subject: [PATCH] Provide different message and explanation strings in invalid filename dialog depending on invalid mode Signed-off-by: Claudio Cambra --- src/gui/invalidfilenamedialog.cpp | 40 ++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/gui/invalidfilenamedialog.cpp b/src/gui/invalidfilenamedialog.cpp index 844f5b5e4bdf2..f26a5161abcda 100644 --- a/src/gui/invalidfilenamedialog.cpp +++ b/src/gui/invalidfilenamedialog.cpp @@ -64,7 +64,12 @@ QString illegalCharacterListToString(const QVector &illegalCharacters) namespace OCC { -InvalidFilenameDialog::InvalidFilenameDialog(AccountPtr account, Folder *folder, QString filePath, FileLocation fileLocation, QWidget *parent) +InvalidFilenameDialog::InvalidFilenameDialog(AccountPtr account, + Folder *folder, + QString filePath, + FileLocation fileLocation, + InvalidMode invalidMode, + QWidget *parent) : QDialog(parent) , _ui(new Ui::InvalidFilenameDialog) , _account(account) @@ -89,8 +94,37 @@ InvalidFilenameDialog::InvalidFilenameDialog(AccountPtr account, Folder *folder, _ui->descriptionLabel->setTextFormat(Qt::PlainText); _ui->errorLabel->setTextFormat(Qt::PlainText); - _ui->descriptionLabel->setText(tr("The file \"%1\" could not be synced because the name contains characters which are not allowed on this system.").arg(_originalFileName)); - _ui->explanationLabel->setText(tr("The following characters are not allowed on the system: * \" | & ? , ; : \\ / ~ < > leading/trailing spaces")); + switch (invalidMode) { + case InvalidMode::SystemInvalid: + _ui->descriptionLabel->setText(tr("The file \"%1\" could not be synced because the name contains characters which are not allowed on this system.").arg(_originalFileName)); + _ui->explanationLabel->setText(tr("The following characters are not allowed on the system: * \" | & ? , ; : \\ / ~ < > leading/trailing spaces")); + break; + case InvalidMode::ServerInvalid: + _ui->descriptionLabel->setText(tr("The file \"%1\" could not be synced because the name contains characters which are not allowed on the server.").arg(_originalFileName)); + + const auto caps = _account->capabilities(); + const auto forbiddenCharacters = caps.forbiddenFilenameCharacters(); + const auto forbiddenBasenames = caps.forbiddenFilenameBasenames(); + const auto forbiddenFilenames = caps.forbiddenFilenames(); + const auto forbiddenExtensions = caps.forbiddenFilenameExtensions(); + + auto explanations = QStringList(); + + if (!forbiddenCharacters.isEmpty()) { + explanations.append(tr("The following characters are not allowed: %1").arg(forbiddenCharacters.join(" "))); + } + if (!forbiddenBasenames.isEmpty()) { + explanations.append(tr("The following basenames are not allowed: %1").arg(forbiddenBasenames.join(" "))); + } + if (!forbiddenFilenames.isEmpty()) { + explanations.append(tr("The following filenames are not allowed: %1").arg(forbiddenFilenames.join(" "))); + } + if (!forbiddenExtensions.isEmpty()) { + explanations.append(tr("The following file extensions are not allowed: %1").arg(forbiddenExtensions.join(" "))); + } + _ui->explanationLabel->setText(explanations.join("\n")); + break; + } _ui->filenameLineEdit->setText(filePathFileInfo.fileName()); connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);