Utility::escape(safeUrl.toString()));
QString serverWithUser = server;
if (AbstractCredentials *cred = account->credentials()) {
- serverWithUser = tr("%1 as <i>%2</i>").arg(server, Utility::escape(cred->user()));
+ QString user = account->davDisplayName();
+ if (user.isEmpty()) {
+ user = cred->user();
+ }
+ serverWithUser = tr("%1 as <i>%2</i>").arg(server, Utility::escape(user));
}
if (state == AccountState::Connected) {
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
/** Returns a new settings object for this account, already in the right groups. */
std::unique_ptr<QSettings> 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
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);
_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);
}
}
}
+void SettingsDialog::slotAccountDisplayNameChanged()
+{
+ Account *account = static_cast<Account *>(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) {
void slotSwitchPage(QAction *action);
void slotRefreshActivity(AccountState *accountState);
void slotAccountAvatarChanged();
+ void slotAccountDisplayNameChanged();
protected:
void reject() Q_DECL_OVERRIDE;
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;
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(':'));
return dn;
}
+QString Account::davDisplayName() const
+{
+ return _displayName;
+}
+
+void Account::setDavDisplayName(const QString &newDisplayName)
+{
+ _displayName = newDisplayName;
+ emit accountChangedDisplayName();
+}
+
QString Account::id() const
{
return _id;
QString davUser() const;
void setDavUser(const QString &newDavUser);
+ QString davDisplayName() const;
+ void setDavDisplayName(const QString &newDisplayName);
+
QImage avatar() const;
void setAvatar(const QImage &img);
/** 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);
void serverVersionChanged(Account *account, const QString &newVersion, const QString &oldVersion);
void accountChangedAvatar();
+ void accountChangedDisplayName();
protected Q_SLOTS:
void slotCredentialsFetched();
QWeakPointer<Account> _sharedThis;
QString _id;
QString _davUser;
+ QString _displayName;
QImage _avatarImg;
QMap<QString, QVariant> _settingsMap;
QUrl _url;
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)