vfs: Make switching vfs on/off work again
authorChristian Kamm <mail@ckamm.de>
Tue, 13 Nov 2018 12:31:39 +0000 (13:31 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:23 +0000 (10:58 +0100)
src/gui/folder.cpp
src/gui/folder.h

index 1d9bbc0f35a8d409633540a242dc2f936d996780..bb1c1c880d969a7ebde7f35d7c10e1554906f6c7 100644 (file)
@@ -133,26 +133,8 @@ Folder::Folder(const FolderDefinition &definition,
     }
 
     // Initialize the vfs plugin
-    if (_definition.virtualFilesMode != Vfs::Off) {
-        ENFORCE(_vfs);
-        ENFORCE(_vfs->mode() == _definition.virtualFilesMode);
-
-        _vfs->setParent(this);
-
-        VfsSetupParams vfsParams;
-        vfsParams.filesystemPath = path();
-        vfsParams.remotePath = remotePath();
-        vfsParams.account = _accountState->account();
-        vfsParams.journal = &_journal;
-        vfsParams.providerName = Theme::instance()->appNameGUI();
-        vfsParams.providerVersion = Theme::instance()->version();
-
-        connect(_vfs, &OCC::Vfs::beginHydrating, this, &Folder::slotHydrationStarts);
-        connect(_vfs, &OCC::Vfs::doneHydrating, this, &Folder::slotHydrationDone);
-
-        _vfs->registerFolder(vfsParams); // Do this always?
-        _vfs->start(vfsParams);
-    }
+    if (_definition.virtualFilesMode != Vfs::Off)
+        startVfs();
 }
 
 Folder::~Folder()
@@ -485,6 +467,28 @@ void Folder::createGuiLog(const QString &filename, LogStatus status, int count,
     }
 }
 
+void Folder::startVfs()
+{
+    ENFORCE(_vfs);
+    ENFORCE(_vfs->mode() == _definition.virtualFilesMode);
+
+    _vfs->setParent(this);
+
+    VfsSetupParams vfsParams;
+    vfsParams.filesystemPath = path();
+    vfsParams.remotePath = remotePath();
+    vfsParams.account = _accountState->account();
+    vfsParams.journal = &_journal;
+    vfsParams.providerName = Theme::instance()->appNameGUI();
+    vfsParams.providerVersion = Theme::instance()->version();
+
+    connect(_vfs, &OCC::Vfs::beginHydrating, this, &Folder::slotHydrationStarts);
+    connect(_vfs, &OCC::Vfs::doneHydrating, this, &Folder::slotHydrationDone);
+
+    _vfs->registerFolder(vfsParams); // Do this always?
+    _vfs->start(vfsParams);
+}
+
 int Folder::slotDiscardDownloadProgress()
 {
     // Delete from journal and from filesystem.
@@ -592,10 +596,24 @@ void Folder::downloadVirtualFile(const QString &_relativepath)
 
 void Folder::setUseVirtualFiles(bool enabled)
 {
-    // ### must wipe virtual files, unload old plugin, load new one?
-    //_definition.useVirtualFiles = enabled;
-    if (enabled)
+    if (enabled && _definition.virtualFilesMode == Vfs::Off) {
+        _definition.virtualFilesMode = bestAvailableVfsMode();
+
+        _vfs = createVfsFromPlugin(_definition.virtualFilesMode, this);
+        startVfs();
+
         _saveInFoldersWithPlaceholders = true;
+    }
+    if (!enabled && _definition.virtualFilesMode != Vfs::Off) {
+        // TODO: Must wait for current sync to finish!
+        SyncEngine::wipeVirtualFiles(path(), _journal, _vfs);
+
+        _vfs->stop();
+        _vfs->unregisterFolder();
+        delete _vfs;
+
+        _definition.virtualFilesMode = Vfs::Off;
+    }
     saveToSettings();
 }
 
index ed6e1a314659fdb8b2e5ef1938e8cd60cbde6254..ec62080ce2ea5b36eb950d3b00aa6bdb32c45f00 100644 (file)
@@ -381,6 +381,8 @@ private:
     void createGuiLog(const QString &filename, LogStatus status, int count,
         const QString &renameTarget = QString());
 
+    void startVfs();
+
     AccountStatePtr _accountState;
     FolderDefinition _definition;
     QString _canonicalLocalPath; // As returned with QFileInfo:canonicalFilePath.  Always ends with "/"