From f3be99e5b2721779c44c0eb94b968968561fb92d Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 15 Jan 2019 10:52:44 +0100 Subject: [PATCH] vfs: Update pinning context menu to be less confusing 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 | 57 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 62fa674c7..ac1aea1a2 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -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")); + } } } -- 2.30.2