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.
This commit is contained in:
Christian Kamm 2019-04-16 09:47:55 +02:00 committed by Kevin Ottens
parent 021f994584
commit 40d9fc4f4b
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
6 changed files with 52 additions and 28 deletions

View file

@ -205,22 +205,3 @@ std::unique_ptr<Vfs> 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);
}

View file

@ -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<Vfs> createVfsFromPlugin(Vfs::Mode mode);
/// Convert availability to translated string
OCSYNC_EXPORT QString vfsItemAvailabilityToString(VfsItemAvailability availability, bool forFolder);
} // namespace OCC

View file

@ -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); });

View file

@ -21,6 +21,8 @@
#include <QMessageBox>
#include <QUrlQuery>
#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");
}

View file

@ -19,6 +19,8 @@
#include <QUrl>
#include <QWidget>
#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

View file

@ -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) {