Folder: Add selective sync / ui related flags
authorChristian Kamm <mail@ckamm.de>
Mon, 14 Jan 2019 14:46:40 +0000 (15:46 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:34 +0000 (10:58 +0100)
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

src/gui/accountsettings.cpp
src/gui/folder.cpp
src/gui/folder.h
src/gui/folderstatusmodel.cpp

index b8f55cb7b3b13de8b3e59585dadfff9fbb7ef861..cfe3a1c8efa21c0509875ba4dceed015c8eb030d 100644 (file)
@@ -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);
index d0999e11d48d553f20629ee790badb363c1e69db..db9c2c296181887ae3ec79ef97d9ae740805977e 100644 (file)
@@ -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)
index 5b5a7ecb50390b4e9a25044989712ad836412813..0eb45286a4632025dd4303a28711a8e8592fbc69 100644 (file)
@@ -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.
      *
index 83dcdb51430fb1dcd86c42bf021b20fe990a39cf..af010f99a3743af98cdb59e929c69ba16956d65c 100644 (file)
@@ -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;
     }