From 70c2dc70a1257c77dafb30dcd58366125a5405e9 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 9 Dec 2020 16:54:49 +0100 Subject: [PATCH] Resurrect the display of subfolders for VFS sync folders 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 --- src/gui/folderstatusmodel.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index e0dfd2321..d2e906c0e 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -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(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("") + Utility::escape(x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size))) + QLatin1String("")); 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(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()); -- 2.30.2