From: Christian Kamm Date: Mon, 14 Jan 2019 14:46:40 +0000 (+0100) Subject: Folder: Add selective sync / ui related flags X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~21^2~468^2~330 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=57282567631612dbc4612c63f91036fa77515884;p=nextcloud-desktop.git 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 --- diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index b8f55cb7b..cfe3a1c8e 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -418,7 +418,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) ac = menu->addAction(tr("Edit Ignored Files")); 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->setEnabled(folderConnected); connect(ac, &QAction::triggered, this, &AccountSettings::doExpand); diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index d0999e11d..db9c2c296 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -658,6 +658,11 @@ void Folder::setNewFilesAreVirtual(bool enabled) _journal.setPinStateForPath("", enabled ? PinState::OnlineOnly : PinState::AlwaysLocal); } +bool Folder::supportsSelectiveSync() const +{ + return !supportsVirtualFiles() && !isVfsOnOffSwitchPending(); +} + void Folder::saveToSettings() const { // Remove first to make sure we don't get duplicates @@ -1206,7 +1211,7 @@ void Folder::registerFolderWatcher() bool Folder::supportsVirtualFiles() const { - return _definition.virtualFilesMode != Vfs::Off; + return _definition.virtualFilesMode != Vfs::Off && !isVfsOnOffSwitchPending(); } void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction dir, bool *cancel) diff --git a/src/gui/folder.h b/src/gui/folder.h index 5b5a7ecb5..0eb45286a 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -270,6 +270,13 @@ public: bool newFilesAreVirtual() const; 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: void syncStateChange(); void syncStarted(); @@ -456,6 +463,14 @@ private: */ 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. * diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 83dcdb514..af010f99a 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -370,7 +370,7 @@ int FolderStatusModel::rowCount(const QModelIndex &parent) const auto info = infoForIndex(parent); if (!info) return 0; - if (info->_folder && info->_folder->supportsVirtualFiles()) + if (info->_folder && !info->_folder->supportsSelectiveSync()) return 0; if (info->hasLabel()) return 1; @@ -527,7 +527,7 @@ bool FolderStatusModel::hasChildren(const QModelIndex &parent) const if (!info) return false; - if (info->_folder && info->_folder->supportsVirtualFiles()) + if (info->_folder && !info->_folder->supportsSelectiveSync()) return false; 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 return false; } - if (info->_folder && info->_folder->supportsVirtualFiles()) { + if (info->_folder && !info->_folder->supportsSelectiveSync()) { // Selective sync is hidden in that case return false; }