mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-20 21:02:02 +03:00
28 lines
845 B
C++
28 lines
845 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 ellided 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;
|
||
|
}
|
||
|
|
||
|
}
|