Skip to content

Commit

Permalink
Provide different message and explanation strings in invalid filename…
Browse files Browse the repository at this point in the history
… dialog depending on invalid mode

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra authored and mgallien committed Aug 21, 2024
1 parent f07b492 commit aaf0653
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/gui/invalidfilenamedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit aaf0653

Please sign in to comment.