vfs: Update pinning context menu to be less confusing
authorChristian Kamm <mail@ckamm.de>
Tue, 15 Jan 2019 09:52:44 +0000 (10:52 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:35 +0000 (10:58 +0100)
Seeing "Currently available online only" for a currently hydrated file
was odd. It makes sense since current hydration status and pin state are
independent.

The new text will say something like "Currently available, but marked
online only" to better indicate that the file might be dehydrated later
since it wasn't pinned.

src/gui/socketapi.cpp

index 62fa674c7badc6e5b0392c97bfe67179d867b36d..ac1aea1a2340752eb218d1c99c3e8bc64d290120 100644 (file)
@@ -1012,8 +1012,11 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
     if (syncFolder && syncFolder->supportsVirtualFiles()) {
         bool hasAlwaysLocal = false;
         bool hasOnlineOnly = false;
+        bool hasHydratedOnlineOnly = false;
+        bool hasDehydratedOnlineOnly = false;
         for (const auto &file : files) {
-            auto path = FileData::get(file).folderRelativePathNoVfsSuffix();
+            auto fileData = FileData::get(file);
+            auto path = fileData.folderRelativePathNoVfsSuffix();
             auto pinState = syncFolder->journalDb()->effectivePinStateForPath(path.toUtf8());
             if (!pinState) {
                 // db error
@@ -1023,20 +1026,52 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
                 hasAlwaysLocal = true;
             } else if (*pinState == PinState::OnlineOnly) {
                 hasOnlineOnly = true;
+                auto record = fileData.journalRecord();
+                if (record._type == ItemTypeFile)
+                    hasHydratedOnlineOnly = true;
+                if (record.isVirtualFile())
+                    hasDehydratedOnlineOnly = true;
             }
         }
 
+        auto makePinContextMenu = [listener](QString currentState, QString availableLocally, QString onlineOnly) {
+            listener->sendMessage(QLatin1String("MENU_ITEM:CURRENT_PIN:d:") + currentState);
+            if (!availableLocally.isEmpty())
+                listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_AVAILABLE_LOCALLY::") + availableLocally);
+            if (!onlineOnly.isEmpty())
+                listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_ONLINE_ONLY::") + onlineOnly);
+        };
+
         // TODO: Should be a submenu, should use menu item checkmarks where available, should use icons
-        if (hasAlwaysLocal && !hasOnlineOnly) {
-            listener->sendMessage(QLatin1String("MENU_ITEM:CURRENT_PIN:d:") + tr("Currently available locally"));
-            listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_ONLINE_ONLY::") + tr("Make available online only"));
-        } else if (hasOnlineOnly && !hasAlwaysLocal) {
-            listener->sendMessage(QLatin1String("MENU_ITEM:CURRENT_PIN:d:") + tr("Currently available online only"));
-            listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_AVAILABLE_LOCALLY::") + tr("Make available locally"));
-        } else if (hasOnlineOnly && hasAlwaysLocal) {
-            listener->sendMessage(QLatin1String("MENU_ITEM:CURRENT_PIN:d:") + tr("Current availability is mixed"));
-            listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_AVAILABLE_LOCALLY::") + tr("Make all available locally"));
-            listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_ONLINE_ONLY::") + tr("Make all available online only"));
+        if (hasAlwaysLocal) {
+            if (!hasOnlineOnly) {
+                makePinContextMenu(
+                    tr("Currently available locally"),
+                    QString(),
+                    tr("Make available online only"));
+            } else { // local + online
+                makePinContextMenu(
+                    tr("Current availability is mixed"),
+                    tr("Make all available locally"),
+                    tr("Make all available online only"));
+            }
+        } else if (hasOnlineOnly) {
+            if (hasDehydratedOnlineOnly && !hasHydratedOnlineOnly) {
+                makePinContextMenu(
+                    tr("Currently available online only"),
+                    tr("Make available locally"),
+                    QString());
+            } else if (hasHydratedOnlineOnly && !hasDehydratedOnlineOnly) {
+                makePinContextMenu(
+                    tr("Currently available, but marked online only"),
+                    tr("Make available locally"),
+                    tr("Make available online only"));
+            } else { // hydrated + dehydrated
+                makePinContextMenu(
+                    tr("Some currently available, all marked online only"),
+                    tr("Make available locally"),
+                    tr("Make available online only"));
+            }
         }
     }