page: welcomepage: display the users avatar when logging in
This commit is contained in:
@@ -18,16 +18,19 @@ LoginStep {
|
||||
showBackButton: false
|
||||
|
||||
title: i18nc("@title", "Login")
|
||||
message: i18n("Enter your Matrix ID")
|
||||
message: i18n("Welcome to NeoChat!")
|
||||
|
||||
Component.onCompleted: {
|
||||
LoginHelper.matrixId = ""
|
||||
}
|
||||
|
||||
QQC2.Label {
|
||||
text: "To get started, enter your matrix ID:"
|
||||
}
|
||||
|
||||
Kirigami.FormLayout {
|
||||
QQC2.TextField {
|
||||
id: matrixIdField
|
||||
Kirigami.FormData.label: i18n("Matrix ID:")
|
||||
placeholderText: "@user:matrix.org"
|
||||
onTextChanged: {
|
||||
if(acceptableInput) {
|
||||
|
||||
@@ -44,11 +44,40 @@ Kirigami.ScrollablePage {
|
||||
}
|
||||
}
|
||||
|
||||
property var showAvatar: LoginHelper.loginAvatar != ""
|
||||
|
||||
ColumnLayout {
|
||||
Kirigami.Icon {
|
||||
source: "org.kde.neochat"
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 16
|
||||
Item {
|
||||
Layout.preferredHeight: Kirigami.Units.gridUnit * 10
|
||||
Layout.preferredWidth: Kirigami.Units.gridUnit * 8
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
|
||||
Kirigami.Icon {
|
||||
source: "org.kde.neochat"
|
||||
visible: !welcomePage.showAvatar
|
||||
Layout.fillHeight: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
implicitWidth: height
|
||||
}
|
||||
|
||||
Kirigami.Avatar {
|
||||
visible: welcomePage.showAvatar
|
||||
source: LoginHelper.loginAvatar
|
||||
name: LoginHelper.loginName
|
||||
Layout.fillHeight: true
|
||||
implicitWidth: height
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
Controls.Label {
|
||||
text: LoginHelper.loginName
|
||||
font.pointSize: 24
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
}
|
||||
}
|
||||
Controls.Label {
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <KLocalizedString>
|
||||
|
||||
using namespace Quotient;
|
||||
#include <csapi/profile.h>
|
||||
|
||||
Login::Login(QObject *parent)
|
||||
: QObject(parent)
|
||||
@@ -20,6 +21,16 @@ Login::Login(QObject *parent)
|
||||
init();
|
||||
}
|
||||
|
||||
QUrl Login::loginAvatar() const
|
||||
{
|
||||
return m_loginAvatar;
|
||||
}
|
||||
|
||||
QString Login::loginName() const
|
||||
{
|
||||
return m_loginName;
|
||||
}
|
||||
|
||||
void Login::init()
|
||||
{
|
||||
m_homeserverReachable = false;
|
||||
@@ -34,6 +45,10 @@ void Login::init()
|
||||
|
||||
connect(this, &Login::matrixIdChanged, this, [this]() {
|
||||
setHomeserverReachable(false);
|
||||
m_loginAvatar = QString();
|
||||
m_loginName = QString();
|
||||
Q_EMIT loginNameChanged();
|
||||
Q_EMIT loginAvatarChanged();
|
||||
|
||||
if (m_matrixId == "@") {
|
||||
return;
|
||||
@@ -52,6 +67,17 @@ void Login::init()
|
||||
m_supportsSso = m_connection->supportsSso();
|
||||
m_supportsPassword = m_connection->supportsPasswordAuth();
|
||||
Q_EMIT loginFlowsChanged();
|
||||
|
||||
GetUserProfileJob *job = m_connection->callApi<GetUserProfileJob>(m_matrixId);
|
||||
connect(job, &BaseJob::result, this, [this, job] {
|
||||
auto foundAvatar = job->avatarUrl();
|
||||
m_loginAvatar = QUrl(QStringLiteral("%1/_matrix/media/r0/download/%2")
|
||||
.arg(m_connection->homeserver().toString())
|
||||
.arg(foundAvatar.authority() + foundAvatar.path()));
|
||||
m_loginName = job->displayname();
|
||||
Q_EMIT loginAvatarChanged();
|
||||
Q_EMIT loginNameChanged();
|
||||
});
|
||||
});
|
||||
});
|
||||
connect(m_connection, &Connection::connected, this, [this] {
|
||||
|
||||
@@ -23,6 +23,8 @@ class Login : public QObject
|
||||
Q_PROPERTY(bool supportsPassword READ supportsPassword NOTIFY loginFlowsChanged STORED false)
|
||||
Q_PROPERTY(QUrl ssoUrl READ ssoUrl NOTIFY ssoUrlChanged)
|
||||
Q_PROPERTY(bool isLoggingIn READ isLoggingIn NOTIFY isLoggingInChanged)
|
||||
Q_PROPERTY(QUrl loginAvatar READ loginAvatar NOTIFY loginAvatarChanged STORED false)
|
||||
Q_PROPERTY(QString loginName READ loginName NOTIFY loginNameChanged STORED false)
|
||||
|
||||
public:
|
||||
explicit Login(QObject *parent = nullptr);
|
||||
@@ -52,7 +54,12 @@ public:
|
||||
Q_INVOKABLE void login();
|
||||
Q_INVOKABLE void loginWithSso();
|
||||
|
||||
QUrl loginAvatar() const;
|
||||
QString loginName() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void loginAvatarChanged();
|
||||
void loginNameChanged();
|
||||
void homeserverReachableChanged();
|
||||
void testHomeserverFinished();
|
||||
void matrixIdChanged();
|
||||
@@ -76,6 +83,8 @@ private:
|
||||
bool m_supportsPassword = false;
|
||||
Quotient::Connection *m_connection = nullptr;
|
||||
QUrl m_ssoUrl;
|
||||
QUrl m_loginAvatar;
|
||||
bool m_testing = false;
|
||||
bool m_isLoggingIn = false;
|
||||
QString m_loginName;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user