nextcloud-desktop/src/gui/settingsdialogcommon.cpp
Felix Eckhofer 28da954aad
Fix typo
Signed-off-by: Felix Eckhofer <felix@eckhofer.com>
2019-10-01 08:25:24 +02:00

28 lines
No EOL
844 B
C++

namespace SettingsDialogCommon
{
/** display name with two lines that is displayed in the settings
* If width is bigger than 0, the string will be elided so it does not exceed that width
*/
QString shortDisplayNameForSettings(Account* account, int width)
{
QString user = account->davDisplayName();
if (user.isEmpty()) {
user = account->credentials()->user();
}
QString host = account->url().host();
int port = account->url().port();
if (port > 0 && port != 80 && port != 443) {
host.append(QLatin1Char(':'));
host.append(QString::number(port));
}
if (width > 0) {
QFont f;
QFontMetrics fm(f);
host = fm.elidedText(host, Qt::ElideMiddle, width);
user = fm.elidedText(user, Qt::ElideRight, width);
}
return user + QLatin1String("\n") + host;
}
}