Folder: Add selective sync / ui related flags

supportsSelectiveSync(): clearer than !supportsVirtualFiles() and allows
  extra logic

isVfsOnOffSwitchPending(): Somewhat awkward way of dealing with the
  phase between a user requesting vfs state to be switched and it
  actually happening
This commit is contained in:
Christian Kamm 2019-01-14 15:46:40 +01:00 committed by Kevin Ottens
parent b91839b760
commit 5728256763
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
4 changed files with 25 additions and 5 deletions

View file

@ -418,7 +418,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac = menu->addAction(tr("Edit Ignored Files")); ac = menu->addAction(tr("Edit Ignored Files"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentIgnoredFiles); connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentIgnoredFiles);
if (!_ui->_folderList->isExpanded(index) && !folder->supportsVirtualFiles()) { if (!_ui->_folderList->isExpanded(index) && folder->supportsSelectiveSync()) {
ac = menu->addAction(tr("Choose what to sync")); ac = menu->addAction(tr("Choose what to sync"));
ac->setEnabled(folderConnected); ac->setEnabled(folderConnected);
connect(ac, &QAction::triggered, this, &AccountSettings::doExpand); connect(ac, &QAction::triggered, this, &AccountSettings::doExpand);

View file

@ -658,6 +658,11 @@ void Folder::setNewFilesAreVirtual(bool enabled)
_journal.setPinStateForPath("", enabled ? PinState::OnlineOnly : PinState::AlwaysLocal); _journal.setPinStateForPath("", enabled ? PinState::OnlineOnly : PinState::AlwaysLocal);
} }
bool Folder::supportsSelectiveSync() const
{
return !supportsVirtualFiles() && !isVfsOnOffSwitchPending();
}
void Folder::saveToSettings() const void Folder::saveToSettings() const
{ {
// Remove first to make sure we don't get duplicates // Remove first to make sure we don't get duplicates
@ -1206,7 +1211,7 @@ void Folder::registerFolderWatcher()
bool Folder::supportsVirtualFiles() const bool Folder::supportsVirtualFiles() const
{ {
return _definition.virtualFilesMode != Vfs::Off; return _definition.virtualFilesMode != Vfs::Off && !isVfsOnOffSwitchPending();
} }
void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, bool *cancel) void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, bool *cancel)

View file

@ -270,6 +270,13 @@ public:
bool newFilesAreVirtual() const; bool newFilesAreVirtual() const;
void setNewFilesAreVirtual(bool enabled); void setNewFilesAreVirtual(bool enabled);
/** Whether user desires a switch that couldn't be executed yet, see member */
bool isVfsOnOffSwitchPending() const { return _vfsOnOffPending; }
void setVfsOnOffSwitchPending(bool pending) { _vfsOnOffPending = pending; }
/** Whether this folder should show selective sync ui */
bool supportsSelectiveSync() const;
signals: signals:
void syncStateChange(); void syncStateChange();
void syncStarted(); void syncStarted();
@ -456,6 +463,14 @@ private:
*/ */
bool _saveInFoldersWithPlaceholders = false; bool _saveInFoldersWithPlaceholders = false;
/** Whether a vfs mode switch is pending
*
* When the user desires that vfs be switched on/off but it hasn't been
* executed yet (syncs are still running), some options should be hidden,
* disabled or different.
*/
bool _vfsOnOffPending = false;
/** /**
* Watches this folder's local directory for changes. * Watches this folder's local directory for changes.
* *

View file

@ -370,7 +370,7 @@ int FolderStatusModel::rowCount(const QModelIndex &parent) const
auto info = infoForIndex(parent); auto info = infoForIndex(parent);
if (!info) if (!info)
return 0; return 0;
if (info->_folder && info->_folder->supportsVirtualFiles()) if (info->_folder && !info->_folder->supportsSelectiveSync())
return 0; return 0;
if (info->hasLabel()) if (info->hasLabel())
return 1; return 1;
@ -527,7 +527,7 @@ bool FolderStatusModel::hasChildren(const QModelIndex &parent) const
if (!info) if (!info)
return false; return false;
if (info->_folder && info->_folder->supportsVirtualFiles()) if (info->_folder && !info->_folder->supportsSelectiveSync())
return false; return false;
if (!info->_fetched) if (!info->_fetched)
@ -555,7 +555,7 @@ 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->supportsVirtualFiles()) { if (info->_folder && !info->_folder->supportsSelectiveSync()) {
// Selective sync is hidden in that case // Selective sync is hidden in that case
return false; return false;
} }