From 359627007b16864dd012dfbcb83f8086dd065f6a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 6 Oct 2022 19:45:24 +0200 Subject: Display the user's 'pretty' name in the webflow credentials Signed-off-by: Claudio Cambra --- src/gui/creds/webflowcredentials.cpp | 4 ++-- src/libsync/account.cpp | 14 ++++++++++++++ src/libsync/account.h | 7 +++++++ 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp index b2e28dafd..6b388cd88 100644 --- a/src/gui/creds/webflowcredentials.cpp +++ b/src/gui/creds/webflowcredentials.cpp @@ -164,7 +164,7 @@ void WebFlowCredentials::askFromUser() { } QString msg = tr("You have been logged out of your account %1 at %2. Please login again.") - .arg(_account->davUser(), _account->url().toDisplayString()); + .arg(_account->prettyName(), _account->url().toDisplayString()); _askDialog->setInfo(msg); _askDialog->show(); @@ -188,7 +188,7 @@ void WebFlowCredentials::slotAskFromUserCredentialsProvided(const QString &user, qCInfo(lcWebFlowCredentials()) << "Authed with the wrong user!"; QString msg = tr("Please login with the account: %1") - .arg(_account->davUser()); + .arg(_account->prettyName()); _askDialog->setError(msg); if (!_askDialog->isUsingFlow2()) { diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index f3f8c1f10..7f640416d 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -131,6 +131,7 @@ void Account::setDavUser(const QString &newDavUser) return; _davUser = newDavUser; emit wantsAccountSaved(this); + emit prettyNameChanged(); } #ifndef TOKEN_AUTH_ONLY @@ -165,6 +166,19 @@ void Account::setDavDisplayName(const QString &newDisplayName) { _displayName = newDisplayName; emit accountChangedDisplayName(); + emit prettyNameChanged(); +} + +QString Account::prettyName() const +{ + // If davDisplayName is empty (can be several reasons, simplest is missing login at startup), fall back to username + auto name = davDisplayName(); + + if (name.isEmpty()) { + name = davUser(); + } + + return name; } QColor Account::headerColor() const diff --git a/src/libsync/account.h b/src/libsync/account.h index 635caeac8..d96597dee 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -83,6 +83,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QString id MEMBER _id) Q_PROPERTY(QString davUser MEMBER _davUser) Q_PROPERTY(QString displayName MEMBER _displayName) + Q_PROPERTY(QString prettyName READ prettyName NOTIFY prettyNameChanged) Q_PROPERTY(QUrl url MEMBER _url) public: @@ -113,6 +114,11 @@ public: /// The name of the account as shown in the toolbar [[nodiscard]] QString displayName() const; + /// The name of the account that is displayed as nicely as possible, + /// e.g. the actual name of the user (John Doe). If this cannot be + /// provided, defaults to davUser (e.g. johndoe) + [[nodiscard]] QString prettyName() const; + [[nodiscard]] QColor accentColor() const; [[nodiscard]] QColor headerColor() const; [[nodiscard]] QColor headerTextColor() const; @@ -319,6 +325,7 @@ signals: void accountChangedAvatar(); void accountChangedDisplayName(); + void prettyNameChanged(); /// Used in RemoteWipe void appPasswordRetrieved(QString); -- cgit v1.2.3