Provide different message and explanation strings in invalid filename dialog depending on invalid mode

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-08-20 16:22:37 +08:00 committed by Matthieu Gallien
parent f07b49288b
commit aaf06535d2

View file

@ -64,7 +64,12 @@ QString illegalCharacterListToString(const QVector<QChar> &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);
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);