mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 19:58:56 +03:00
Use display-name from the ocs call in the settings dialog
This commit is contained in:
parent
95b90271b6
commit
315e38e814
8 changed files with 70 additions and 28 deletions
|
@ -638,7 +638,11 @@ void AccountSettings::slotAccountStateChanged()
|
|||
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) {
|
||||
|
|
|
@ -361,23 +361,4 @@ std::unique_ptr<QSettings> 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
|
||||
|
|
|
@ -113,11 +113,6 @@ public:
|
|||
/** 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
|
||||
|
|
|
@ -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<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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Account> _sharedThis;
|
||||
QString _id;
|
||||
QString _davUser;
|
||||
QString _displayName;
|
||||
QImage _avatarImg;
|
||||
QMap<QString, QVariant> _settingsMap;
|
||||
QUrl _url;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue