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 <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-12-09 16:54:49 +01:00
parent 9f0e0b0f6a
commit 70c2dc70a1
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2

View file

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