FolderStatusModel now uses the LSCOL job result for encryption status
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 7 Dec 2020 18:37:21 +0000 (19:37 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:22 +0000 (10:59 +0100)
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/accountsettings.cpp
src/gui/folderstatusmodel.cpp
src/gui/folderstatusmodel.h

index 0341fd6619f7ec8f84a4ee59aabf04a42c97ca09..bff0bd3694e2218239b2f0d57a2d7986e7b98eff 100644 (file)
@@ -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"));
index 2543a48d7b1c198207073b329335fd9290e09232..e0dfd2321be447cd1300856caa2ae113f17b45f7 100644 (file)
@@ -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) {
index 147411ca94988f1cd9c032be1664df964821f626..ddf470d86804b5a2d42283a0ab207a083ceca018 100644 (file)
@@ -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; }