Display the user's 'pretty' name in the webflow credentials
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 6 Oct 2022 17:45:24 +0000 (19:45 +0200)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 19 Oct 2022 11:31:44 +0000 (13:31 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/creds/webflowcredentials.cpp
src/libsync/account.cpp
src/libsync/account.h

index b2e28dafd82e065f283bdea934c3c663c8d0605e..6b388cd88d83f0cbe2207144081ddba5dac71011 100644 (file)
@@ -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()) {
index f3f8c1f108569f407e21f649320efe3c3d2feab2..7f640416dbf26ffd1e9a9ccf551ce9b5ad950e39 100644 (file)
@@ -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
index 635caeac8a90b92310451e64ffd3f3139090f10b..d96597deeb275ac2849c13c188754ffe2633c04f 100644 (file)
@@ -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);