From 4fde05b8b6b495949bdf0a47aef9d61cfd514e47 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Mon, 7 Dec 2020 19:37:21 +0100 Subject: [PATCH] FolderStatusModel now uses the LSCOL job result for encryption status Signed-off-by: Kevin Ottens --- src/gui/accountsettings.cpp | 4 ++-- src/gui/folderstatusmodel.cpp | 21 ++++++++++++++++----- src/gui/folderstatusmodel.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 0341fd661..bff0bd369 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -375,8 +375,8 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index if (acc->capabilities().clientSideEncryptionAvailable()) { // Verify if the folder is empty before attempting to encrypt. - bool isEncrypted = acc->e2e()->isFolderEncrypted(info->_path); - bool isParentEncrypted = acc->e2e()->isAnyParentFolderEncrypted(info->_path); + bool isEncrypted = info->_isEncrypted; + bool isParentEncrypted = _model->isAnyAncestorEncrypted(index); if (!isEncrypted && !isParentEncrypted) { ac = menu.addAction(tr("Encrypt")); diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 2543a48d7..e0dfd2321 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -155,12 +155,9 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const case Qt::CheckStateRole: return x._checked; case Qt::DecorationRole: { - Q_ASSERT(x._folder->remotePath().startsWith('/')); - const auto rootPath = x._folder->remotePath().mid(1); - const auto absoluteRemotePath = rootPath.isEmpty() ? x._path : rootPath + '/' + x._path; - if (_accountState->account()->e2e()->isFolderEncrypted(absoluteRemotePath)) { + if (x._isEncrypted) { return QIcon(QLatin1String(":/client/theme/lock-https.svg")); - } else if (x._size > 0 && _accountState->account()->e2e()->isAnyParentFolderEncrypted(absoluteRemotePath)) { + } else if (x._size > 0 && isAnyAncestorEncrypted(index)) { return QIcon(QLatin1String(":/client/theme/lock-broken.svg")); } return QFileIconProvider().icon(x._isExternal ? QFileIconProvider::Network : QFileIconProvider::Folder); @@ -418,6 +415,20 @@ FolderStatusModel::SubFolderInfo *FolderStatusModel::infoForIndex(const QModelIn } } +bool FolderStatusModel::isAnyAncestorEncrypted(const QModelIndex &index) const +{ + auto parentIndex = parent(index); + while (parentIndex.isValid()) { + const auto info = infoForIndex(parentIndex); + if (info->_isEncrypted) { + return true; + } + parentIndex = parent(parentIndex); + } + + return false; +} + QModelIndex FolderStatusModel::indexForPath(Folder *f, const QString &path) const { if (!f) { diff --git a/src/gui/folderstatusmodel.h b/src/gui/folderstatusmodel.h index 147411ca9..ddf470d86 100644 --- a/src/gui/folderstatusmodel.h +++ b/src/gui/folderstatusmodel.h @@ -107,6 +107,7 @@ public: FetchLabel }; ItemType classify(const QModelIndex &index) const; SubFolderInfo *infoForIndex(const QModelIndex &index) const; + bool isAnyAncestorEncrypted(const QModelIndex &index) const; // If the selective sync check boxes were changed bool isDirty() { return _dirty; } -- 2.30.2