From fe009ca235a50adefede8291c3f28b7f61fc8e63 Mon Sep 17 00:00:00 2001 From: Xavier Michelon Date: Tue, 17 Jan 2023 11:29:28 +0100 Subject: [PATCH] GODT-2258: change login label and suggest email instead of username. --- .../bridge-gui/bridge-gui/qml/AccountDelegate.qml | 2 +- internal/frontend/bridge-gui/bridge-gui/qml/Bridge.qml | 10 +++++----- .../bridge-gui/bridge-gui/qml/ContentWrapper.qml | 5 +++-- .../frontend/bridge-gui/bridge-gui/qml/MainWindow.qml | 2 +- internal/frontend/bridge-gui/bridge-gui/qml/SignIn.qml | 4 ++-- .../bridge-gui/bridgepp/bridgepp/User/User.cpp | 8 ++++++++ .../frontend/bridge-gui/bridgepp/bridgepp/User/User.h | 1 + 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/AccountDelegate.qml b/internal/frontend/bridge-gui/bridge-gui/qml/AccountDelegate.qml index aa2f5aef..081f06f8 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/AccountDelegate.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/AccountDelegate.qml @@ -64,7 +64,7 @@ Item { } function primaryEmail() { - return (root.user && (root.user.addresses.length > 0)) ? root.user.addresses[0] : "" + return root.user ? root.user.primaryEmailOrUsername() : "" } // width expected to be set by parent object diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/Bridge.qml b/internal/frontend/bridge-gui/bridge-gui/qml/Bridge.qml index 85fa4ddd..3cea2f15 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/Bridge.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/Bridge.qml @@ -117,7 +117,7 @@ QtObject { // fit above _y = iconRect.top - height if (isInInterval(_y, screenRect.top, screenRect.bottom - height)) { - // position preferebly in the horizontal center but bound to the screen rect + // position preferably in the horizontal center but bound to the screen rect _x = bound(iconRect.left + (iconRect.width - width)/2, screenRect.left, screenRect.right - width) return Qt.point(_x, _y) } @@ -125,7 +125,7 @@ QtObject { // fit below _y = iconRect.bottom if (isInInterval(_y, screenRect.top, screenRect.bottom - height)) { - // position preferebly in the horizontal center but bound to the screen rect + // position preferably in the horizontal center but bound to the screen rect _x = bound(iconRect.left + (iconRect.width - width)/2, screenRect.left, screenRect.right - width) return Qt.point(_x, _y) } @@ -133,7 +133,7 @@ QtObject { // fit to the left _x = iconRect.left - width if (isInInterval(_x, screenRect.left, screenRect.right - width)) { - // position preferebly in the vertical center but bound to the screen rect + // position preferably in the vertical center but bound to the screen rect _y = bound(iconRect.top + (iconRect.height - height)/2, screenRect.top, screenRect.bottom - height) return Qt.point(_x, _y) } @@ -141,12 +141,12 @@ QtObject { // fit to the right _x = iconRect.right if (isInInterval(_x, screenRect.left, screenRect.right - width)) { - // position preferebly in the vertical center but bound to the screen rect + // position preferably in the vertical center but bound to the screen rect _y = bound(iconRect.top + (iconRect.height - height)/2, screenRect.top, screenRect.bottom - height) return Qt.point(_x, _y) } - // Fallback: position satatus window right above icon and let window manager decide. + // Fallback: position status window right above icon and let window manager decide. console.warn("Can't position status window: screenRect =", screenRect, "iconRect =", iconRect) _x = bound(iconRect.left + (iconRect.width - width)/2, screenRect.left, screenRect.right - width) _y = bound(iconRect.top + (iconRect.height - height)/2, screenRect.top, screenRect.bottom - height) diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml index 9407c7cd..c2edcc8e 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/ContentWrapper.qml @@ -188,7 +188,7 @@ Item { if (user.state !== EUserState.SignedOut) { rightContent.showAccount() } else { - signIn.username = user.username + signIn.username = user.primaryEmailOrUsername() rightContent.showSignIn() } } @@ -255,7 +255,8 @@ Item { return Backend.users.get(accounts.currentIndex) } onShowSignIn: { - signIn.username = this.user.username + var user = this.user + signIn.username = user ? user.primaryEmailOrUsername() : "" rightContent.showSignIn() } onShowSetupGuide: function(user, address) { diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml index 7237f2dd..3be7437f 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/MainWindow.qml @@ -116,7 +116,7 @@ ApplicationWindow { } if ((Backend.users.count === 1) && (u.state === EUserState.SignedOut)) { - showSignIn(u.username) + showSignIn(u.primaryEmailOrUsername()) return 0 } diff --git a/internal/frontend/bridge-gui/bridge-gui/qml/SignIn.qml b/internal/frontend/bridge-gui/bridge-gui/qml/SignIn.qml index cc08fe6c..d3d9bef8 100644 --- a/internal/frontend/bridge-gui/bridge-gui/qml/SignIn.qml +++ b/internal/frontend/bridge-gui/bridge-gui/qml/SignIn.qml @@ -204,7 +204,7 @@ FocusScope { TextField { colorScheme: root.colorScheme id: usernameTextField - label: qsTr("Username or email") + label: qsTr("Email or username") focus: true Layout.fillWidth: true Layout.topMargin: 24 @@ -221,7 +221,7 @@ FocusScope { validator: function(str) { if (str.length === 0) { - return qsTr("Enter username or email") + return qsTr("Enter email or username") } return } diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.cpp b/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.cpp index 31874c4b..382a5d50 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.cpp +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.cpp @@ -55,6 +55,14 @@ void User::update(User const &user) { } +//**************************************************************************************************************************************************** +/// \return The user's primary email. If not known, return turn username +//**************************************************************************************************************************************************** +QString User::primaryEmailOrUsername() const { + return addresses_.isEmpty() ? username_ : addresses_.front(); +} + + //**************************************************************************************************************************************************** /// \param[in] makeItActive Should split mode be made active. //**************************************************************************************************************************************************** diff --git a/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.h b/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.h index c1c186ac..14a82249 100644 --- a/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.h +++ b/internal/frontend/bridge-gui/bridgepp/bridgepp/User/User.h @@ -73,6 +73,7 @@ public: // member functions. User &operator=(User const &) = delete; ///< Disabled assignment operator. User &operator=(User &&) = delete; ///< Disabled move assignment operator. void update(User const &user); ///< Update the user. + Q_INVOKABLE QString primaryEmailOrUsername() const; ///< Return the user primary email, or, if unknown its username. public slots: // slots for QML generated calls