path.remove(webdavFolder);
// Don't allow to select subfolders of encrypted subfolders
- if (_account->capabilities().clientSideEncryptionAvailable() &&
- _account->e2e()->isAnyParentFolderEncrypted(path)) {
+ const auto isAnyAncestorEncrypted = std::any_of(std::cbegin(_encryptedPaths), std::cend(_encryptedPaths), [=](const QString &encryptedPath) {
+ return path.size() > encryptedPath.size() && path.startsWith(encryptedPath);
+ });
+ if (isAnyAncestorEncrypted) {
continue;
}
root->setExpanded(true);
}
+void FolderWizardRemotePath::slotGatherEncryptedPaths(const QString &path, const QMap<QString, QString> &properties)
+{
+ const auto it = properties.find("is-encrypted");
+ if (it == properties.cend() || *it != QStringLiteral("1")) {
+ return;
+ }
+
+ const auto webdavFolder = QUrl(_account->davUrl()).path();
+ Q_ASSERT(path.startsWith(webdavFolder));
+ _encryptedPaths << path.mid(webdavFolder.size());
+}
+
void FolderWizardRemotePath::slotRefreshFolders()
{
+ _encryptedPaths.clear();
runLsColJob("/");
_ui.folderTreeWidget->clear();
_ui.folderEntry->clear();
QString dir = item->data(0, Qt::UserRole).toString();
// We don't want to allow creating subfolders in encrypted folders outside of the sync logic
- const auto encrypted = _account->capabilities().clientSideEncryptionAvailable() &&
- _account->e2e()->isFolderEncrypted(dir + '/');
+ const auto encrypted = _encryptedPaths.contains(dir);
_ui.addFolderButton->setEnabled(!encrypted);
if (!dir.startsWith(QLatin1Char('/'))) {
LsColJob *FolderWizardRemotePath::runLsColJob(const QString &path)
{
auto *job = new LsColJob(_account, path, this);
- job->setProperties(QList<QByteArray>() << "resourcetype");
+ auto props = QList<QByteArray>() << "resourcetype";
+ if (_account->capabilities().clientSideEncryptionAvailable()) {
+ props << "http://nextcloud.org/ns:is-encrypted";
+ }
+ job->setProperties(props);
connect(job, &LsColJob::directoryListingSubfolders,
this, &FolderWizardRemotePath::slotUpdateDirectories);
connect(job, &LsColJob::finishedWithError,
this, &FolderWizardRemotePath::slotHandleLsColNetworkError);
+ connect(job, &LsColJob::directoryListingIterated,
+ this, &FolderWizardRemotePath::slotGatherEncryptedPaths);
job->start();
return job;
void slotHandleMkdirNetworkError(QNetworkReply *);
void slotHandleLsColNetworkError(QNetworkReply *);
void slotUpdateDirectories(const QStringList &);
+ void slotGatherEncryptedPaths(const QString &, const QMap<QString, QString> &);
void slotRefreshFolders();
void slotItemExpanded(QTreeWidgetItem *);
void slotCurrentItemChanged(QTreeWidgetItem *);
bool _warnWasVisible;
AccountPtr _account;
QTimer _lscolTimer;
+ QStringList _encryptedPaths;
};
/**
void SelectiveSyncWidget::refreshFolders()
{
+ _encryptedPaths.clear();
+
auto *job = new LsColJob(_account, _folderPath, this);
- job->setProperties(QList<QByteArray>() << "resourcetype"
- << "http://owncloud.org/ns:size");
+ auto props = QList<QByteArray>() << "resourcetype"
+ << "http://owncloud.org/ns:size";
+ if (_account->capabilities().clientSideEncryptionAvailable()) {
+ props << "http://nextcloud.org/ns:is-encrypted";
+ }
+ job->setProperties(props);
connect(job, &LsColJob::directoryListingSubfolders,
this, &SelectiveSyncWidget::slotUpdateDirectories);
connect(job, &LsColJob::finishedWithError,
this, &SelectiveSyncWidget::slotLscolFinishedWithError);
+ connect(job, &LsColJob::directoryListingIterated,
+ this, &SelectiveSyncWidget::slotGatherEncryptedPaths);
job->start();
_folderTree->clear();
_loading->show();
path.remove(pathToRemove);
// Don't allow to select subfolders of encrypted subfolders
- if (_account->capabilities().clientSideEncryptionAvailable() &&
- _account->e2e()->isAnyParentFolderEncrypted(_rootName + '/' + path)) {
+ const auto isAnyAncestorEncrypted = std::any_of(std::cbegin(_encryptedPaths), std::cend(_encryptedPaths), [=](const QString &encryptedPath) {
+ return path.size() > encryptedPath.size() && path.startsWith(encryptedPath);
+ });
+ if (isAnyAncestorEncrypted) {
continue;
}
_loading->resize(_loading->sizeHint()); // because it's not in a layout
}
+void SelectiveSyncWidget::slotGatherEncryptedPaths(const QString &path, const QMap<QString, QString> &properties)
+{
+ const auto it = properties.find("is-encrypted");
+ if (it == properties.cend() || *it != QStringLiteral("1")) {
+ return;
+ }
+
+ const auto webdavFolder = QUrl(_account->davUrl()).path();
+ Q_ASSERT(path.startsWith(webdavFolder));
+ // This dialog use the postfix / convention for folder paths
+ _encryptedPaths << path.mid(webdavFolder.size()) + '/';
+}
+
void SelectiveSyncWidget::slotItemExpanded(QTreeWidgetItem *item)
{
QString dir = item->data(0, Qt::UserRole).toString();
void slotItemExpanded(QTreeWidgetItem *);
void slotItemChanged(QTreeWidgetItem *, int);
void slotLscolFinishedWithError(QNetworkReply *);
+ void slotGatherEncryptedPaths(const QString &, const QMap<QString, QString> &);
private:
void refreshFolders();
// During account setup we want to filter out excluded folders from the
// view without having a Folder.SyncEngine.ExcludedFiles instance.
ExcludedFiles _excludedFiles;
+
+ QStringList _encryptedPaths;
};
/**