From 7e5f81ea81d2f06522920e2eeedf2343c05b66f3 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 10 Dec 2020 12:35:16 +0100 Subject: [PATCH] Allow to control availability of folders in the settings dialog It felt odd to be able to control the encryption status in the settings dialog but not the availability. Also availability was controllable on the root, so let's make it widely available. Signed-off-by: Kevin Ottens --- src/gui/accountsettings.cpp | 46 +++++++++++++++++++++++++++++++++++++ src/gui/accountsettings.h | 1 + 2 files changed, 47 insertions(+) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 69eca9563..e524f9dda 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -403,6 +403,39 @@ void AccountSettings::slotSubfolderContextMenuRequested(const QModelIndex& index ac = menu.addAction(tr("Edit Ignored Files")); connect(ac, &QAction::triggered, this, &AccountSettings::slotEditCurrentLocalIgnoredFiles); + const auto folder = info->_folder; + if (folder && folder->virtualFilesEnabled()) { + auto availabilityMenu = menu.addMenu(tr("Availability")); + + // Has '/' suffix convention for paths here but VFS and + // sync engine expects no such suffix + Q_ASSERT(info->_path.endsWith('/')); + const auto remotePath = info->_path.chopped(1); + + // It might be an E2EE mangled path, so let's try to demangle it + const auto journal = folder->journalDb(); + SyncJournalFileRecord rec; + journal->getFileRecordByE2eMangledName(remotePath, &rec); + + const auto path = rec.isValid() ? rec._path : remotePath; + + auto availability = folder->vfs().availability(path); + if (availability) { + ac = availabilityMenu->addAction(Utility::vfsCurrentAvailabilityText(*availability)); + ac->setEnabled(false); + } + + ac = availabilityMenu->addAction(Utility::vfsPinActionText()); + ac->setEnabled(!availability || *availability != VfsItemAvailability::AlwaysLocal); + connect(ac, &QAction::triggered, this, [this, folder, path] { slotSetSubFolderAvailability(folder, path, PinState::AlwaysLocal); }); + + ac = availabilityMenu->addAction(Utility::vfsFreeSpaceActionText()); + ac->setEnabled(!availability + || !(*availability == VfsItemAvailability::OnlineOnly + || *availability == VfsItemAvailability::AllDehydrated)); + connect(ac, &QAction::triggered, this, [this, folder, path] { slotSetSubFolderAvailability(folder, path, PinState::OnlineOnly); }); + } + menu.exec(QCursor::pos()); } @@ -815,6 +848,19 @@ void AccountSettings::slotSetCurrentFolderAvailability(PinState state) folder->scheduleThisFolderSoon(); } +void AccountSettings::slotSetSubFolderAvailability(Folder *folder, const QString &path, PinState state) +{ + Q_ASSERT(folder && folder->virtualFilesEnabled()); + Q_ASSERT(!path.endsWith('/')); + + // Update the pin state on all items + folder->vfs().setPinState(path, state); + + // Trigger sync + folder->schedulePathForLocalDiscovery(path); + folder->scheduleThisFolderSoon(); +} + void AccountSettings::showConnectionLabel(const QString &message, QStringList errors) { const QString errStyle = QLatin1String("color:#ffffff; background-color:#bb4d4d;padding:5px;" diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index c9f152cc3..ef37c44b7 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -89,6 +89,7 @@ protected slots: void slotEnableVfsCurrentFolder(); void slotDisableVfsCurrentFolder(); void slotSetCurrentFolderAvailability(PinState state); + void slotSetSubFolderAvailability(Folder *folder, const QString &path, PinState state); void slotFolderWizardAccepted(); void slotFolderWizardRejected(); void slotDeleteAccount(); -- 2.30.2