vfs: Make switching vfs on/off work again

This commit is contained in:
Christian Kamm 2018-11-13 13:31:39 +01:00 committed by Kevin Ottens
parent fa6f3cd847
commit 4bef96afe7
No known key found for this signature in database
GPG Key ID: 074BBBCB8DECC9E2
2 changed files with 43 additions and 23 deletions

View 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();
}

View 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 "/"