diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index 8183d4b8f..23b287244 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -638,7 +638,11 @@ void AccountSettings::slotAccountStateChanged()
Utility::escape(safeUrl.toString()));
QString serverWithUser = server;
if (AbstractCredentials *cred = account->credentials()) {
- serverWithUser = tr("%1 as %2").arg(server, Utility::escape(cred->user()));
+ QString user = account->davDisplayName();
+ if (user.isEmpty()) {
+ user = cred->user();
+ }
+ serverWithUser = tr("%1 as %2").arg(server, Utility::escape(user));
}
if (state == AccountState::Connected) {
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 580f3b31e..0b19f3f88 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -361,23 +361,4 @@ std::unique_ptr AccountState::settings()
return s;
}
-QString AccountState::shortDisplayNameForSettings(int width) const
-{
- QString 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;
-}
-
-
} // namespace OCC
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index 03f17795f..3256424af 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -113,11 +113,6 @@ public:
/** Returns a new settings object for this account, already in the right groups. */
std::unique_ptr settings();
- /** 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(int width = 0) const;
-
/** Mark the timestamp when the last successful ETag check happened for
* this account.
* The checkConnectivity() method uses the timestamp to save a call to
diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp
index a266157db..fc50dd120 100644
--- a/src/gui/settingsdialog.cpp
+++ b/src/gui/settingsdialog.cpp
@@ -236,7 +236,7 @@ void SettingsDialog::accountAdded(AccountState *s)
if (!brandingSingleAccount) {
accountAction->setToolTip(s->account()->displayName());
- accountAction->setIconText(s->shortDisplayNameForSettings(height * buttonSizeRatio));
+ accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio));
}
_toolBar->insertAction(_toolBar->actions().at(0), accountAction);
auto accountSettings = new AccountSettings(s, this);
@@ -250,6 +250,7 @@ void SettingsDialog::accountAdded(AccountState *s)
_gui, &ownCloudGui::slotFolderOpenAction);
connect(accountSettings, &AccountSettings::showIssuesList, this, &SettingsDialog::showIssuesList);
connect(s->account().data(), &Account::accountChangedAvatar, this, &SettingsDialog::slotAccountAvatarChanged);
+ connect(s->account().data(), &Account::accountChangedDisplayName, this, &SettingsDialog::slotAccountDisplayNameChanged);
slotRefreshActivity(s);
}
@@ -268,6 +269,41 @@ void SettingsDialog::slotAccountAvatarChanged()
}
}
+void SettingsDialog::slotAccountDisplayNameChanged()
+{
+ Account *account = static_cast(sender());
+ if (account && _actionForAccount.contains(account)) {
+ QAction *action = _actionForAccount[account];
+ if (action) {
+ QString displayName = account->displayName();
+ action->setText(displayName);
+ auto height = _toolBar->sizeHint().height();
+ action->setIconText(shortDisplayNameForSettings(account, height * buttonSizeRatio));
+ }
+ }
+}
+
+QString SettingsDialog::shortDisplayNameForSettings(Account* account, int width) const
+{
+ 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;
+}
+
void SettingsDialog::accountRemoved(AccountState *s)
{
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) {
diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h
index 15596a00f..7c2ffcc03 100644
--- a/src/gui/settingsdialog.h
+++ b/src/gui/settingsdialog.h
@@ -60,6 +60,7 @@ public slots:
void slotSwitchPage(QAction *action);
void slotRefreshActivity(AccountState *accountState);
void slotAccountAvatarChanged();
+ void slotAccountDisplayNameChanged();
protected:
void reject() Q_DECL_OVERRIDE;
@@ -77,6 +78,11 @@ private:
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
QAction *createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath = QString());
+ /** 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 = 0) const;
+
Ui::SettingsDialog *const _ui;
QActionGroup *_actionGroup;
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index 4c5f8a411..0c2e44dbe 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -105,7 +105,7 @@ void Account::setAvatar(const QImage &img)
QString Account::displayName() const
{
- QString dn = QString("%1@%2").arg(_credentials->user(), _url.host());
+ QString dn = QString("%1@%2").arg(davUser(), _url.host());
int port = url().port();
if (port > 0 && port != 80 && port != 443) {
dn.append(QLatin1Char(':'));
@@ -114,6 +114,17 @@ QString Account::displayName() const
return dn;
}
+QString Account::davDisplayName() const
+{
+ return _displayName;
+}
+
+void Account::setDavDisplayName(const QString &newDisplayName)
+{
+ _displayName = newDisplayName;
+ emit accountChangedDisplayName();
+}
+
QString Account::id() const
{
return _id;
diff --git a/src/libsync/account.h b/src/libsync/account.h
index 249ff403d..aa1009287 100644
--- a/src/libsync/account.h
+++ b/src/libsync/account.h
@@ -83,6 +83,9 @@ public:
QString davUser() const;
void setDavUser(const QString &newDavUser);
+ QString davDisplayName() const;
+ void setDavDisplayName(const QString &newDisplayName);
+
QImage avatar() const;
void setAvatar(const QImage &img);
@@ -209,7 +212,7 @@ public:
/** True when the server supports HTTP2 */
bool isHttp2Supported() { return _http2Supported; }
- void setHttp2Supported(bool value) { _http2Supported = value; };
+ void setHttp2Supported(bool value) { _http2Supported = value; }
void clearCookieJar();
void lendCookieJarTo(QNetworkAccessManager *guest);
@@ -246,6 +249,7 @@ signals:
void serverVersionChanged(Account *account, const QString &newVersion, const QString &oldVersion);
void accountChangedAvatar();
+ void accountChangedDisplayName();
protected Q_SLOTS:
void slotCredentialsFetched();
@@ -258,6 +262,7 @@ private:
QWeakPointer _sharedThis;
QString _id;
QString _davUser;
+ QString _displayName;
QImage _avatarImg;
QMap _settingsMap;
QUrl _url;
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index fd454e68f..2acbf74f1 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -316,6 +316,10 @@ void ConnectionValidator::slotUserFetched(const QJsonDocument &json)
job->start();
}
+ QString displayName = json.object().value("ocs").toObject().value("data").toObject().value("display-name").toString();
+ if (!displayName.isEmpty()) {
+ _account->setDavDisplayName(displayName);
+ }
}
void ConnectionValidator::slotAvatarImage(const QImage &img)