add an option to enforce use of virtual files sync folder

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2021-11-04 11:20:16 +01:00
parent 845e258031
commit 5ab13b2adc
12 changed files with 53 additions and 1 deletions

View file

@ -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")

View file

@ -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@

View file

@ -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"

View file

@ -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()

View file

@ -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();

View file

@ -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;

View file

@ -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";

View file

@ -324,6 +324,8 @@ private:
bool pushNotificationsFilesReady(Account *account);
bool isSwitchToVfsNeeded(const FolderDefinition &folderDefinition) const;
QSet<Folder *> _disabledFolders;
Folder::Map _folderMap;
QString _folderConfigPath;

View file

@ -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);
}
}
//
}

View file

@ -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);

View file

@ -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"};

View file

@ -565,6 +565,8 @@ public:
*/
virtual bool showVirtualFilesOption() const;
virtual bool enforceVirtualFilesSyncFolder() const;
/** @return color for the ErrorBox text. */
virtual QColor errorBoxTextColor() const;