Resurrect the display of subfolders for VFS sync folders
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 9 Dec 2020 15:54:49 +0000 (16:54 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:24 +0000 (10:59 +0100)
This got removed from the settings since in that case selective sync
isn't supported. Unfortunately that's also necessary to display them to
allow encrypting folders via the context menu.

So we display the subfolders again but in the case of VFS we disable the
ability to (un)check them. They just have an icon, a name and a context
menu.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/gui/folderstatusmodel.cpp

index e0dfd2321be447cd1300856caa2ae113f17b45f7..d2e906c0e9c257b4a16a83fe9972ad98d3be4472 100644 (file)
@@ -105,6 +105,10 @@ Qt::ItemFlags FolderStatusModel::flags(const QModelIndex &index) const
     if (!_accountState) {
         return {};
     }
+
+    const auto info = infoForIndex(index);
+    const auto supportsSelectiveSync = info && info->_folder && info->_folder->supportsSelectiveSync();
+
     switch (classify(index)) {
     case AddButton: {
         Qt::ItemFlags ret;
@@ -119,7 +123,11 @@ Qt::ItemFlags FolderStatusModel::flags(const QModelIndex &index) const
     case RootFolder:
         return Qt::ItemIsEnabled;
     case SubFolder:
-        return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
+        if (supportsSelectiveSync) {
+            return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
+        } else {
+            return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+        }
     }
     return {};
 }
@@ -146,6 +154,8 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
     }
     case SubFolder: {
         const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs.at(index.row());
+        const auto supportsSelectiveSync = x._folder && x._folder->supportsSelectiveSync();
+
         switch (role) {
         case Qt::DisplayRole:
             //: Example text: "File.txt (23KB)"
@@ -153,7 +163,11 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
         case Qt::ToolTipRole:
             return QString(QLatin1String("<qt>") + Utility::escape(x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size))) + QLatin1String("</qt>"));
         case Qt::CheckStateRole:
-            return x._checked;
+            if (supportsSelectiveSync) {
+                return x._checked;
+            } else {
+                return QVariant();
+            }
         case Qt::DecorationRole: {
             if (x._isEncrypted) {
                 return QIcon(QLatin1String(":/client/theme/lock-https.svg"));
@@ -294,6 +308,7 @@ bool FolderStatusModel::setData(const QModelIndex &index, const QVariant &value,
 {
     if (role == Qt::CheckStateRole) {
         auto info = infoForIndex(index);
+        Q_ASSERT(info->_folder && info->_folder->supportsSelectiveSync());
         auto checked = static_cast<Qt::CheckState>(value.toInt());
 
         if (info && info->_checked != checked) {
@@ -543,9 +558,6 @@ bool FolderStatusModel::hasChildren(const QModelIndex &parent) const
     if (!info)
         return false;
 
-    if (info->_folder && !info->_folder->supportsSelectiveSync())
-        return false;
-
     if (!info->_fetched)
         return true;
 
@@ -571,10 +583,6 @@ bool FolderStatusModel::canFetchMore(const QModelIndex &parent) const
         // Keep showing the error to the user, it will be hidden when the account reconnects
         return false;
     }
-    if (info->_folder && !info->_folder->supportsSelectiveSync()) {
-        // Selective sync is hidden in that case
-        return false;
-    }
     return true;
 }
 
@@ -666,9 +674,6 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
     if (!parentInfo) {
         return;
     }
-    if (!parentInfo->_folder->supportsSelectiveSync()) {
-        return;
-    }
     ASSERT(parentInfo->_fetchingJob == job);
     ASSERT(parentInfo->_subs.isEmpty());