From 4bef96afe7517ec90dc0889cc8a66cb3b6a512b7 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 13 Nov 2018 13:31:39 +0100 Subject: [PATCH] vfs: Make switching vfs on/off work again --- src/gui/folder.cpp | 64 +++++++++++++++++++++++++++++----------------- src/gui/folder.h | 2 ++ 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 1d9bbc0f3..bb1c1c880 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -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(); } diff --git a/src/gui/folder.h b/src/gui/folder.h index ed6e1a314..ec62080ce 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -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 "/" -- 2.30.2