Utils: Introduce FilePath::displayName()

To produce "<filepath> on <devicename>" which is nicer to read than
"<scheme>://<deviceid>/<filepath>" in some places.

Change-Id: Ife47bbf49382cf73dd4709d826bdeaa8730f88be
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-06-02 17:05:46 +02:00
parent 51aae3bb1f
commit 31f0ba4ef9
7 changed files with 39 additions and 2 deletions

View File

@@ -921,6 +921,29 @@ FilePath FilePath::normalizedPathName() const
return result;
}
QString FilePath::displayName(const QString &args) const
{
QString deviceName;
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.deviceDisplayName, return m_data);
deviceName = s_deviceHooks.deviceDisplayName(*this);
}
if (args.isEmpty()) {
if (deviceName.isEmpty())
return m_data;
return QCoreApplication::translate("Utils::FileUtils", "%1 on %2", "File on device")
.arg(m_data, deviceName);
}
if (deviceName.isEmpty())
return m_data + ' ' + args;
return QCoreApplication::translate("Utils::FileUtils", "%1 %2 on %3", "File and args on device")
.arg(m_data, args, deviceName);
}
/// Constructs a FilePath from \a filename
/// \a filename is not checked for validity.
FilePath FilePath::fromString(const QString &filepath)