Skip to content

Commit

Permalink
vfs: Add vfs migration options to folder context menu
Browse files Browse the repository at this point in the history
This allows enabling and disabling vfs.

To distinguish this operation from setting the root pin state, the
availability setting is adjusted as well to be similar to the
menu that shows in the shell extensions.
  • Loading branch information
ckamm authored and ogoffart committed Jan 18, 2019
1 parent 44a579d commit ad81454
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
*
* If a path has no explicit PinState "Inherited" is returned.
*
* The path should not have a trailing slash.
* It's valid to use the root path "".
*
* Returns none on db error.
Expand All @@ -291,6 +292,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
* If the exact path has no entry or has an Inherited state,
* the state of the closest parent path is returned.
*
* The path should not have a trailing slash.
* It's valid to use the root path "".
*
* Never returns PinState::Inherited. If the root is "Inherited"
Expand All @@ -303,6 +305,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
/**
* Sets a path's pin state.
*
* The path should not have a trailing slash.
* It's valid to use the root path "".
*/
void setPinStateForPath(const QByteArray &path, PinState state);
Expand All @@ -311,6 +314,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
* Wipes pin states for a path and below.
*
* Used when the user asks a subtree to have a particular pin state.
* The path should not have a trailing slash.
* The path "" wipes every entry.
*/
void wipePinStateForPathAndBelow(const QByteArray &path);
Expand All @@ -319,6 +323,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
* Returns list of all paths with their pin state as in the db.
*
* Returns nothing on db error.
* Note that this will have an entry for "".
*/
Optional<QVector<QPair<QByteArray, PinState>>> rawPinStates();

Expand Down
140 changes: 114 additions & 26 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,35 +336,27 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
ac = menu->addAction(tr("Remove folder sync connection"));
connect(ac, &QAction::triggered, this, &AccountSettings::slotRemoveCurrentFolder);

if ((Theme::instance()->showVirtualFilesOption() && folder->supportsVirtualFiles()) || folder->newFilesAreVirtual()) {
ac = menu->addAction(tr("Create virtual files for new files (Experimental)"));
if (folder->supportsVirtualFiles()) {
auto availabilityMenu = menu->addMenu(tr("Availability"));
ac = availabilityMenu->addAction(tr("Local"));
ac->setCheckable(true);
ac->setChecked(!folder->newFilesAreVirtual());
connect(ac, &QAction::triggered, this, [this]() { slotSetCurrentFolderAvailability(PinState::AlwaysLocal); });

ac = availabilityMenu->addAction(tr("Online only"));
ac->setCheckable(true);
ac->setChecked(folder->newFilesAreVirtual());
connect(ac, &QAction::toggled, this, [folder, this](bool checked) {
if (!checked) {
if (folder)
folder->setNewFilesAreVirtual(false);
// Make sure the size is recomputed as the virtual file indicator changes
ui->_folderList->doItemsLayout();
return;
}
OwncloudWizard::askExperimentalVirtualFilesFeature([folder, this](bool enable) {
if (enable && folder)
folder->setNewFilesAreVirtual(enable);

// Also wipe selective sync settings
bool ok = false;
auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});
for (const auto &entry : oldBlacklist) {
folder->journalDb()->avoidReadFromDbOnNextSync(entry);
}
FolderMan::instance()->scheduleFolder(folder);
connect(ac, &QAction::triggered, this, [this]() { slotSetCurrentFolderAvailability(PinState::OnlineOnly); });

// Make sure the size is recomputed as the virtual file indicator changes
ui->_folderList->doItemsLayout();
});
});
ac = menu->addAction(tr("Disable virtual file support..."));
connect(ac, &QAction::triggered, this, &AccountSettings::slotDisableVfsCurrentFolder);
}

if (Theme::instance()->showVirtualFilesOption()
&& !folder->supportsVirtualFiles()
&& bestAvailableVfsMode() != Vfs::Off) {
ac = menu->addAction(tr("Enable virtual file support (experimental)..."));
connect(ac, &QAction::triggered, this, &AccountSettings::slotEnableVfsCurrentFolder);
}


Expand Down Expand Up @@ -541,6 +533,102 @@ void AccountSettings::slotOpenCurrentLocalSubFolder()
QDesktopServices::openUrl(url);
}

void AccountSettings::slotEnableVfsCurrentFolder()
{
FolderMan *folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
return;

OwncloudWizard::askExperimentalVirtualFilesFeature([folder, this](bool enable) {
if (!enable || !folder)
return;

qCInfo(lcAccountSettings) << "Enabling vfs support for folder" << folder->path();

// Wipe selective sync blacklist
bool ok = false;
auto oldBlacklist = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &ok);
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});
for (const auto &entry : oldBlacklist) {
folder->journalDb()->avoidReadFromDbOnNextSync(entry);
}

// Change the folder vfs mode and load the plugin
folder->setSupportsVirtualFiles(true);

// Wipe pin states to be sure
folder->journalDb()->wipePinStateForPathAndBelow("");
folder->journalDb()->setPinStateForPath("", PinState::OnlineOnly);

FolderMan::instance()->scheduleFolder(folder);

// Update the ui: no selective sync, vfs indicator; size changed
ui->_folderList->doItemsLayout();
});
}

void AccountSettings::slotDisableVfsCurrentFolder()
{
FolderMan *folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
return;

auto msgBox = new QMessageBox(
QMessageBox::Question,
tr("Disable virtual file support?"),
tr("This action will disable virtual file support. As a consequence contents of folders that "
"are currently marked as 'available online only' will be downloaded."
"\n\n"
"The only advantage of disabling virtual file support is that the selective sync feature "
"will become available again."));
msgBox->addButton(tr("Disable support"), QMessageBox::AcceptRole);
msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole);
connect(msgBox, &QMessageBox::finished, msgBox, [this, msgBox, folder](int result) {
msgBox->deleteLater();
if (result != QMessageBox::AcceptRole || !folder)
return;

qCInfo(lcAccountSettings) << "Disabling vfs support for folder" << folder->path();

// Also wipes virtual files, schedules remote discovery
folder->setSupportsVirtualFiles(false);

// Wipe pin states and selective sync db
folder->journalDb()->wipePinStateForPathAndBelow("");
folder->journalDb()->setPinStateForPath("", PinState::AlwaysLocal);
folder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, {});

FolderMan::instance()->scheduleFolder(folder);

// Update the ui: no selective sync, vfs indicator; size changed
ui->_folderList->doItemsLayout();
});
msgBox->open();
}

void AccountSettings::slotSetCurrentFolderAvailability(PinState state)
{
FolderMan *folderMan = FolderMan::instance();
QPointer<Folder> folder = folderMan->folder(selectedFolderAlias());
QModelIndex selected = ui->_folderList->selectionModel()->currentIndex();
if (!selected.isValid() || !folder)
return;

// similar to socket api: set pin state, wipe sub pin-states and sync
folder->journalDb()->wipePinStateForPathAndBelow("");
folder->journalDb()->setPinStateForPath("", state);

if (state == PinState::AlwaysLocal) {
folder->downloadVirtualFile("");
} else {
folder->dehydrateFile("");
}
}

void AccountSettings::showConnectionLabel(const QString &message, QStringList errors)
{
const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;"
Expand Down
3 changes: 3 additions & 0 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ protected slots:
void slotRemoveCurrentFolder();
void slotOpenCurrentFolder(); // sync folder
void slotOpenCurrentLocalSubFolder(); // selected subfolder in sync folder
void slotEnableVfsCurrentFolder();
void slotDisableVfsCurrentFolder();
void slotSetCurrentFolderAvailability(PinState state);
void slotFolderWizardAccepted();
void slotFolderWizardRejected();
void slotDeleteAccount();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,9 @@ void Folder::setSupportsVirtualFiles(bool enabled)
_vfs->unregisterFolder();

_vfs.reset(createVfsFromPlugin(newMode).release());
startVfs();

_definition.virtualFilesMode = newMode;
startVfs();
if (newMode != Vfs::Off)
_saveInFoldersWithPlaceholders = true;
saveToSettings();
Expand Down

0 comments on commit ad81454

Please sign in to comment.