From 5ab13b2adc827a2ee6f9164b863aa0ebfed480a0 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Thu, 4 Nov 2021 11:20:16 +0100 Subject: [PATCH] add an option to enforce use of virtual files sync folder Signed-off-by: Matthieu Gallien --- NEXTCLOUD.cmake | 1 + config.h.in | 1 + src/common/vfs.cpp | 1 + src/gui/accountsettings.cpp | 1 + src/gui/folder.cpp | 7 ++++++- src/gui/folder.h | 2 ++ src/gui/folderman.cpp | 21 ++++++++++++++++++++ src/gui/folderman.h | 2 ++ src/gui/folderwizard.cpp | 5 +++++ src/gui/wizard/owncloudadvancedsetuppage.cpp | 5 +++++ src/libsync/theme.cpp | 6 ++++++ src/libsync/theme.h | 2 ++ 12 files changed, 53 insertions(+), 1 deletion(-) diff --git a/NEXTCLOUD.cmake b/NEXTCLOUD.cmake index ce246e8e8..d34e682af 100644 --- a/NEXTCLOUD.cmake +++ b/NEXTCLOUD.cmake @@ -34,6 +34,7 @@ option( BUILD_UPDATER "Build updater" OFF ) option( WITH_PROVIDERS "Build with providers list" ON ) +option( ENFORCE_VIRTUAL_FILES_SYNC_FOLDER "Enforce use of virtual files sync folder when available" OFF ) ## Theming options set(NEXTCLOUD_BACKGROUND_COLOR "#0082c9" CACHE STRING "Default Nextcloud background color") diff --git a/config.h.in b/config.h.in index 1c7d921cd..e9eff6c92 100644 --- a/config.h.in +++ b/config.h.in @@ -32,6 +32,7 @@ #cmakedefine APPLICATION_OCSP_STAPLING_ENABLED "@APPLICATION_OCSP_STAPLING_ENABLED@" #cmakedefine APPLICATION_FORBID_BAD_SSL "@APPLICATION_FORBID_BAD_SSL@" #define APPLICATION_DOTVIRTUALFILE_SUFFIX "." APPLICATION_VIRTUALFILE_SUFFIX +#cmakedefine01 ENFORCE_VIRTUAL_FILES_SYNC_FOLDER #cmakedefine ZLIB_FOUND @ZLIB_FOUND@ diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index 71ff5dae0..593c4c3bc 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" #include "vfs.h" #include "plugin.h" #include "version.h" diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 43dab82a5..76cf0cc39 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -593,6 +593,7 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) ac = menu->addAction(tr("Disable virtual file support …")); connect(ac, &QAction::triggered, this, &AccountSettings::slotDisableVfsCurrentFolder); + ac->setDisabled(Theme::instance()->enforceVirtualFilesSyncFolder()); } if (Theme::instance()->showVirtualFilesOption() diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 3a33d4542..decbb927b 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -671,7 +671,7 @@ void Folder::setVirtualFilesEnabled(bool enabled) startVfs(); if (newMode != Vfs::Off) { _saveInFoldersWithPlaceholders = true; - SyncEngine::switchToVirtualFiles(path(), _journal, *_vfs); + switchToVirtualFiles(); } saveToSettings(); } @@ -688,6 +688,11 @@ void Folder::setRootPinState(PinState state) slotNextSyncFullLocalDiscovery(); } +void Folder::switchToVirtualFiles() +{ + SyncEngine::switchToVirtualFiles(path(), _journal, *_vfs); +} + bool Folder::supportsSelectiveSync() const { return !virtualFilesEnabled() && !isVfsOnOffSwitchPending(); diff --git a/src/gui/folder.h b/src/gui/folder.h index 6efdd1eb0..3bb96b2da 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -287,6 +287,8 @@ public: bool isVfsOnOffSwitchPending() const { return _vfsOnOffPending; } void setVfsOnOffSwitchPending(bool pending) { _vfsOnOffPending = pending; } + void switchToVirtualFiles(); + /** Whether this folder should show selective sync ui */ bool supportsSelectiveSync() const; diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 5a3881480..73ad0c553 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -292,6 +292,11 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath()); } + const auto switchToVfs = isSwitchToVfsNeeded(folderDefinition); + if (switchToVfs) { + folderDefinition.virtualFilesMode = bestAvailableVfsMode(); + } + auto vfs = createVfsFromPlugin(folderDefinition.virtualFilesMode); if (!vfs) { // TODO: Must do better error handling @@ -300,6 +305,9 @@ void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, Folder *f = addFolderInternal(std::move(folderDefinition), account.data(), std::move(vfs)); if (f) { + if (switchToVfs) { + f->switchToVirtualFiles(); + } // Migrate the old "usePlaceholders" setting to the root folder pin state if (settings.value(QLatin1String(versionC), 1).toInt() == 1 && settings.value(QLatin1String("usePlaceholders"), false).toBool()) { @@ -837,6 +845,19 @@ bool FolderMan::pushNotificationsFilesReady(Account *account) return pushFilesAvailable && pushNotifications && pushNotifications->isReady(); } +bool FolderMan::isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const +{ + auto result = false; + if (ENFORCE_VIRTUAL_FILES_SYNC_FOLDER && + folderDefinition.virtualFilesMode != bestAvailableVfsMode() && + folderDefinition.virtualFilesMode == Vfs::Off && + OCC::Theme::instance()->showVirtualFilesOption()) { + result = true; + } + + return result; +} + void FolderMan::slotEtagPollTimerTimeout() { qCInfo(lcFolderMan) << "Etag poll timer timeout"; diff --git a/src/gui/folderman.h b/src/gui/folderman.h index c3a1b1466..5a6c234e7 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -324,6 +324,8 @@ private: bool pushNotificationsFilesReady(Account *account); + bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const; + QSet _disabledFolders; Folder::Map _folderMap; QString _folderConfigPath; diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp index 3200f4210..b240d7235 100644 --- a/src/gui/folderwizard.cpp +++ b/src/gui/folderwizard.cpp @@ -545,6 +545,11 @@ void FolderWizardSelectiveSync::initializePage() _virtualFilesCheckBox->setChecked(bestAvailableVfsMode() == Vfs::WindowsCfApi); _virtualFilesCheckBox->setEnabled(true); _virtualFilesCheckBox->setText(tr("Use virtual files instead of downloading content immediately %1").arg(bestAvailableVfsMode() == Vfs::WindowsCfApi ? QString() : tr("(experimental)"))); + + if (Theme::instance()->enforceVirtualFilesSyncFolder()) { + _virtualFilesCheckBox->setChecked(true); + _virtualFilesCheckBox->setDisabled(true); + } } // } diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index 88b522931..0d8cb6c1a 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -59,6 +59,11 @@ OwncloudAdvancedSetupPage::OwncloudAdvancedSetupPage(OwncloudWizard *wizard) connect(_ui.pbSelectLocalFolder, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectFolder); setButtonText(QWizard::FinishButton, tr("Connect")); + if (Theme::instance()->enforceVirtualFilesSyncFolder()) { + _ui.rSyncEverything->setDisabled(true); + _ui.rSelectiveSync->setDisabled(true); + } + connect(_ui.rSyncEverything, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSyncEverythingClicked); connect(_ui.rSelectiveSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotSelectiveSyncClicked); connect(_ui.rVirtualFileSync, &QAbstractButton::clicked, this, &OwncloudAdvancedSetupPage::slotVirtualFileSyncClicked); diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index 8fd5b1a3f..ff7f58e60 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -859,6 +859,12 @@ bool Theme::showVirtualFilesOption() const return ConfigFile().showExperimentalOptions() || vfsMode == Vfs::WindowsCfApi; } +bool Theme::enforceVirtualFilesSyncFolder() const +{ + const auto vfsMode = bestAvailableVfsMode(); + return ENFORCE_VIRTUAL_FILES_SYNC_FOLDER && vfsMode != OCC::Vfs::Off; +} + QColor Theme::errorBoxTextColor() const { return QColor{"white"}; diff --git a/src/libsync/theme.h b/src/libsync/theme.h index f07c0de4a..6b9aefb25 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -565,6 +565,8 @@ public: */ virtual bool showVirtualFilesOption() const; + virtual bool enforceVirtualFilesSyncFolder() const; + /** @return color for the ErrorBox text. */ virtual QColor errorBoxTextColor() const;