FolderStatusModel LSCOL job now gets the is-encrypted property
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 7 Dec 2020 18:12:21 +0000 (19:12 +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/folderstatusmodel.cpp
src/gui/folderstatusmodel.h

index 0ebab24b894d39d53051adb24bc7b18a9a8a6151..2543a48d7b1c198207073b329335fd9290e09232 100644 (file)
@@ -32,6 +32,7 @@ Q_LOGGING_CATEGORY(lcFolderStatus, "nextcloud.gui.folder.model", QtInfoMsg)
 
 static const char propertyParentIndexC[] = "oc_parentIndex";
 static const char propertyPermissionMap[] = "oc_permissionMap";
+static const char propertyEncryptionMap[] = "nc_encryptionMap";
 
 static QString removeTrailingSlash(const QString &s)
 {
@@ -581,10 +582,14 @@ void FolderStatusModel::fetchMore(const QModelIndex &parent)
 
     auto *job = new LsColJob(_accountState->account(), path, this);
     info->_fetchingJob = job;
-    job->setProperties(QList<QByteArray>() << "resourcetype"
-                                           << "http://owncloud.org/ns:size"
-                                           << "http://owncloud.org/ns:permissions"
-                                           << "http://owncloud.org/ns:fileid");
+    auto props = QList<QByteArray>() << "resourcetype"
+                                     << "http://owncloud.org/ns:size"
+                                     << "http://owncloud.org/ns:permissions"
+                                     << "http://owncloud.org/ns:fileid";
+    if (_accountState->account()->capabilities().clientSideEncryptionAvailable()) {
+        props << "http://nextcloud.org/ns:is-encrypted";
+    }
+    job->setProperties(props);
 
     job->setTimeout(60 * 1000);
     connect(job, &LsColJob::directoryListingSubfolders,
@@ -593,6 +598,8 @@ void FolderStatusModel::fetchMore(const QModelIndex &parent)
         this, &FolderStatusModel::slotLscolFinishedWithError);
     connect(job, &LsColJob::directoryListingIterated,
         this, &FolderStatusModel::slotGatherPermissions);
+    connect(job, &LsColJob::directoryListingIterated,
+            this, &FolderStatusModel::slotGatherEncryptionStatus);
 
     job->start();
 
@@ -625,6 +632,20 @@ void FolderStatusModel::slotGatherPermissions(const QString &href, const QMap<QS
     job->setProperty(propertyPermissionMap, permissionMap);
 }
 
+void FolderStatusModel::slotGatherEncryptionStatus(const QString &href, const QMap<QString, QString> &properties)
+{
+    auto it = properties.find("is-encrypted");
+    if (it == properties.end())
+        return;
+
+    auto job = sender();
+    auto encryptionMap = job->property(propertyEncryptionMap).toMap();
+    job->setProperty(propertyEncryptionMap, QVariant()); // avoid a detach of the map while it is modified
+    ASSERT(!href.endsWith(QLatin1Char('/')), "LsColXMLParser::parse should remove the trailing slash before calling us.");
+    encryptionMap[href] = *it;
+    job->setProperty(propertyEncryptionMap, encryptionMap);
+}
+
 void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
 {
     auto job = qobject_cast<LsColJob *>(sender());
@@ -676,6 +697,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
         }
     }
     const auto permissionMap = job->property(propertyPermissionMap).toMap();
+    const auto encryptionMap = job->property(propertyEncryptionMap).toMap();
 
     QStringList sortedSubfolders = list;
     if (!sortedSubfolders.isEmpty())
@@ -697,6 +719,7 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
         newInfo._pathIdx = parentInfo->_pathIdx;
         newInfo._pathIdx << newSubs.size();
         newInfo._isExternal = permissionMap.value(removeTrailingSlash(path)).toString().contains("M");
+        newInfo._isEncrypted = encryptionMap.value(removeTrailingSlash(path)).toString() == QStringLiteral("1");
         newInfo._path = relativePath;
 
         SyncJournalFileRecord rec;
index ecc13c2091077de98ef84ea7ffe7ddbdc4d1f10e..147411ca94988f1cd9c032be1664df964821f626 100644 (file)
@@ -66,6 +66,7 @@ public:
         QVector<SubFolderInfo> _subs;
         qint64 _size = 0;
         bool _isExternal = false;
+        bool _isEncrypted = false;
 
         bool _fetched = false; // If we did the LSCOL for this folder already
         QPointer<LsColJob> _fetchingJob; // Currently running LsColJob
@@ -126,6 +127,7 @@ public slots:
 private slots:
     void slotUpdateDirectories(const QStringList &);
     void slotGatherPermissions(const QString &name, const QMap<QString, QString> &properties);
+    void slotGatherEncryptionStatus(const QString &href, const QMap<QString, QString> &properties);
     void slotLscolFinishedWithError(QNetworkReply *r);
     void slotFolderSyncStateChange(Folder *f);
     void slotFolderScheduleQueueChanged();