Allow to control availability of folders in the settings dialog
authorKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 10 Dec 2020 11:35:16 +0000 (12:35 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:24 +0000 (10:59 +0100)
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 <kevin.ottens@nextcloud.com>
src/gui/accountsettings.cpp
src/gui/accountsettings.h

index 69eca95631de8753a4cacb8b32de70c77880e71a..e524f9dda75e38b6acc9db8b9c668cba2ac55414 100644 (file)
@@ -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;"
index c9f152cc33fae092b070376f1b7bf4d1b69cb42d..ef37c44b75dc89c95e6ccaba836c1d7e76e54492 100644 (file)
@@ -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();