Provide different message and explanation strings in invalid filename dialog dependin...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 20 Aug 2024 08:22:37 +0000 (16:22 +0800)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Wed, 21 Aug 2024 07:51:39 +0000 (09:51 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/invalidfilenamedialog.cpp

index 844f5b5e4bdf286bbe72ec62f2d4de0c59dc7727..f26a5161abcdac7b291d52e60985e4cead02c96a 100644 (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);
 
-    _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);