Skip to content

Commit

Permalink
Merge pull request #5013 from nextcloud/bugfix/webflow-user-strings
Browse files Browse the repository at this point in the history
Improve "pretty user name"-related strings, display in webflow credentials
  • Loading branch information
claucambra authored Oct 19, 2022
2 parents a8abfb6 + 0bce174 commit f2f7d82
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 21 deletions.
22 changes: 13 additions & 9 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
#include "ui_mnemonicdialog.h"

namespace {
static const char urlC[] = "url";
static const char authTypeC[] = "authType";
static const char userC[] = "user";
static const char httpUserC[] = "http_user";
static const char davUserC[] = "dav_user";
static const char caCertsKeyC[] = "CaCertificates";
static const char accountsC[] = "Accounts";
static const char versionC[] = "version";
static const char serverVersionC[] = "serverVersion";
constexpr auto urlC = "url";
constexpr auto authTypeC = "authType";
constexpr auto userC = "user";
constexpr auto displayNameC = "displayName";
constexpr auto httpUserC = "http_user";
constexpr auto davUserC = "dav_user";
constexpr auto caCertsKeyC = "CaCertificates";
constexpr auto accountsC = "Accounts";
constexpr auto versionC = "version";
constexpr auto serverVersionC = "serverVersion";

// The maximum versions that this client can read
static const int maxAccountsVersion = 2;
Expand Down Expand Up @@ -222,7 +223,9 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s
settings.setValue(QLatin1String(versionC), maxAccountVersion);
settings.setValue(QLatin1String(urlC), acc->_url.toString());
settings.setValue(QLatin1String(davUserC), acc->_davUser);
settings.setValue(QLatin1String(displayNameC), acc->_displayName);
settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion);

if (acc->_credentials) {
if (saveCredentials) {
// Only persist the credentials if the parameter is set, on migration from 1.8.x
Expand Down Expand Up @@ -321,6 +324,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings)

// We want to only restore settings for that auth type and the user value
acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));
acc->_displayName = settings.value(QLatin1String(displayNameC), "").toString();
QString authTypePrefix = authType + "_";
for (const auto &key : settings.childKeys()) {
if (!key.startsWith(authTypePrefix))
Expand Down
4 changes: 2 additions & 2 deletions src/gui/creds/webflowcredentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(_user, _account->displayName());
.arg(_account->prettyName(), _account->url().toDisplayString());
_askDialog->setInfo(msg);

_askDialog->show();
Expand All @@ -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(_user);
.arg(_account->prettyName());
_askDialog->setError(msg);

if (!_askDialog->isUsingFlow2()) {
Expand Down
5 changes: 1 addition & 4 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ const float buttonSizeRatio = 1.618f; // golden ratio
*/
QString shortDisplayNameForSettings(OCC::Account *account, int width)
{
QString user = account->davDisplayName();
if (user.isEmpty()) {
user = account->credentials()->user();
}
QString user = account->prettyName();
QString host = account->url().host();
int port = account->url().port();
if (port > 0 && port != 80 && port != 443) {
Expand Down
7 changes: 1 addition & 6 deletions src/gui/tray/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,7 @@ void User::logout() const

QString User::name() const
{
// If davDisplayName is empty (can be several reasons, simplest is missing login at startup), fall back to username
QString name = _account->account()->davDisplayName();
if (name == "") {
name = _account->account()->credentials()->user();
}
return name;
return _account->account()->prettyName();
}

QString User::server(bool shortened) const
Expand Down
14 changes: 14 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void Account::setDavUser(const QString &newDavUser)
return;
_davUser = newDavUser;
emit wantsAccountSaved(this);
emit prettyNameChanged();
}

#ifndef TOKEN_AUTH_ONLY
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -113,6 +114,11 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject
/// 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;
Expand Down Expand Up @@ -319,6 +325,7 @@ public slots:

void accountChangedAvatar();
void accountChangedDisplayName();
void prettyNameChanged();

/// Used in RemoteWipe
void appPasswordRetrieved(QString);
Expand Down

0 comments on commit f2f7d82

Please sign in to comment.