From 40d9fc4f4b1b17250998dc5511873d1d6acf08ce Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Tue, 16 Apr 2019 09:47:55 +0200 Subject: [PATCH] Vfs: Adjust and centralise action text #7143 Saying "Currently available locally" sounds more like an indicator than "Availably locally" does. Centralizing translations avoids consistency issues between shell context menus and sync folder context menu. --- src/common/vfs.cpp | 19 ------------------- src/common/vfs.h | 3 --- src/gui/accountsettings.cpp | 7 ++++--- src/gui/guiutility.cpp | 31 +++++++++++++++++++++++++++++++ src/gui/guiutility.h | 14 ++++++++++++++ src/gui/socketapi.cpp | 6 +++--- 6 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index 5f170daf1..54f6cb6bd 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -205,22 +205,3 @@ std::unique_ptr OCC::createVfsFromPlugin(Vfs::Mode mode) qCInfo(lcPlugin) << "Created VFS instance from plugin" << pluginPath; return vfs; } - -QString OCC::vfsItemAvailabilityToString(VfsItemAvailability availability, bool forFolder) -{ - switch(availability) { - case VfsItemAvailability::AlwaysLocal: - return Vfs::tr("Always available locally"); - case VfsItemAvailability::AllHydrated: - return Vfs::tr("Available locally"); - case VfsItemAvailability::SomeDehydrated: - if (forFolder) { - return Vfs::tr("Some available online only"); - } else { - return Vfs::tr("Available online only"); - } - case VfsItemAvailability::OnlineOnly: - return Vfs::tr("Available online only"); - } - ENFORCE(false); -} diff --git a/src/common/vfs.h b/src/common/vfs.h index a8765d793..59153024a 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -300,7 +300,4 @@ OCSYNC_EXPORT Vfs::Mode bestAvailableVfsMode(); /// Create a VFS instance for the mode, returns nullptr on failure. OCSYNC_EXPORT std::unique_ptr createVfsFromPlugin(Vfs::Mode mode); -/// Convert availability to translated string -OCSYNC_EXPORT QString vfsItemAvailabilityToString(VfsItemAvailability availability, bool forFolder); - } // namespace OCC diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 05dd56a4d..d4d139fe3 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -22,6 +22,7 @@ #include "folderstatusmodel.h" #include "folderstatusdelegate.h" #include "common/utility.h" +#include "guiutility.h" #include "application.h" #include "configfile.h" #include "account.h" @@ -448,15 +449,15 @@ void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos) auto availabilityMenu = menu->addMenu(tr("Availability")); auto availability = folder->vfs().availability(QString()); if (availability) { - ac = availabilityMenu->addAction(vfsItemAvailabilityToString(*availability, true)); + ac = availabilityMenu->addAction(Utility::vfsCurrentAvailabilityText(*availability, true)); ac->setEnabled(false); } - ac = availabilityMenu->addAction(tr("Make always available locally")); + ac = availabilityMenu->addAction(Utility::vfsPinActionText()); ac->setEnabled(!availability || *availability != VfsItemAvailability::AlwaysLocal); connect(ac, &QAction::triggered, this, [this]() { slotSetCurrentFolderAvailability(PinState::AlwaysLocal); }); - ac = availabilityMenu->addAction(tr("Free up local space")); + ac = availabilityMenu->addAction(Utility::vfsFreeSpaceActionText()); ac->setEnabled(!availability || *availability != VfsItemAvailability::OnlineOnly); connect(ac, &QAction::triggered, this, [this]() { slotSetCurrentFolderAvailability(PinState::OnlineOnly); }); diff --git a/src/gui/guiutility.cpp b/src/gui/guiutility.cpp index f354c39ca..751e171cc 100644 --- a/src/gui/guiutility.cpp +++ b/src/gui/guiutility.cpp @@ -21,6 +21,8 @@ #include #include +#include "common/asserts.h" + using namespace OCC; Q_LOGGING_CATEGORY(lcUtility, "nextcloud.gui.utility", QtInfoMsg) @@ -66,3 +68,32 @@ bool Utility::openEmailComposer(const QString &subject, const QString &body, QWi } return true; } + +QString Utility::vfsCurrentAvailabilityText(VfsItemAvailability availability, bool forFolder) +{ + switch(availability) { + case VfsItemAvailability::AlwaysLocal: + return QCoreApplication::translate("utility", "Currently always available locally"); + case VfsItemAvailability::AllHydrated: + return QCoreApplication::translate("utility", "Currently available locally"); + case VfsItemAvailability::SomeDehydrated: + if (forFolder) { + return QCoreApplication::translate("utility", "Currently some available online only"); + } else { + return QCoreApplication::translate("utility", "Currently available online only"); + } + case VfsItemAvailability::OnlineOnly: + return QCoreApplication::translate("utility", "Currently available online only"); + } + ENFORCE(false); +} + +QString Utility::vfsPinActionText() +{ + return QCoreApplication::translate("utility", "Make always available locally"); +} + +QString Utility::vfsFreeSpaceActionText() +{ + return QCoreApplication::translate("utility", "Free up local space"); +} diff --git a/src/gui/guiutility.h b/src/gui/guiutility.h index 55f808ac2..b25ecc937 100644 --- a/src/gui/guiutility.h +++ b/src/gui/guiutility.h @@ -19,6 +19,8 @@ #include #include +#include "common/pinstate.h" + namespace OCC { namespace Utility { @@ -35,6 +37,18 @@ namespace Utility { bool openEmailComposer(const QString &subject, const QString &body, QWidget *errorWidgetParent); + /** Returns a translated string indicating the current availability. + * + * This will be used in context menus to describe the current state. + */ + QString vfsCurrentAvailabilityText(VfsItemAvailability availability, bool forFolder); + + /** Translated text for "making items always available locally" */ + QString vfsPinActionText(); + + /** Translated text for "free up local space" (and unpinning the item) */ + QString vfsFreeSpaceActionText(); + } // namespace Utility } // namespace OCC diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 7dcccee26..f893bd4b2 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -1075,13 +1075,13 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe // TODO: Should be a submenu, should use icons auto makePinContextMenu = [&](bool makeAvailableLocally, bool freeSpace) { listener->sendMessage(QLatin1String("MENU_ITEM:CURRENT_PIN:d:") - + vfsItemAvailabilityToString(*combined, isFolderOrMultiple)); + + Utility::vfsCurrentAvailabilityText(*combined, isFolderOrMultiple)); listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_AVAILABLE_LOCALLY:") + (makeAvailableLocally ? QLatin1String(":") : QLatin1String("d:")) - + tr("Make always available locally")); + + Utility::vfsPinActionText()); listener->sendMessage(QLatin1String("MENU_ITEM:MAKE_ONLINE_ONLY:") + (freeSpace ? QLatin1String(":") : QLatin1String("d:")) - + tr("Free up local space")); + + Utility::vfsFreeSpaceActionText()); }; switch (*combined) {