login with non linphone sip account

This commit is contained in:
Gaelle Braud 2024-08-21 13:56:40 +02:00
parent 1e234cdc25
commit 204d7d66c8
8 changed files with 132 additions and 50 deletions

View file

@ -59,7 +59,11 @@ void LoginPage::setErrorMessage(const QString &error) {
emit errorMessageChanged(); emit errorMessageChanged();
} }
void LoginPage::login(const QString &username, const QString &password) { void LoginPage::login(const QString &username,
const QString &password,
QString displayName,
QString domain,
LinphoneEnums::TransportType transportType) {
App::postModelAsync([=]() { App::postModelAsync([=]() {
QString *error = new QString(tr("Le couple identifiant mot de passe ne correspond pas")); QString *error = new QString(tr("Le couple identifiant mot de passe ne correspond pas"));
// Create on Model thread. // Create on Model thread.
@ -103,7 +107,8 @@ void LoginPage::login(const QString &username, const QString &password) {
connect(accountManager, &AccountManager::destroyed, [error]() { delete error; }); connect(accountManager, &AccountManager::destroyed, [error]() { delete error; });
if (!accountManager->login(username, password, error)) { if (!accountManager->login(username, password, displayName, domain, LinphoneEnums::toLinphone(transportType),
error)) {
emit accountManager->registrationStateChanged(linphone::RegistrationState::Failed); emit accountManager->registrationStateChanged(linphone::RegistrationState::Failed);
} }
}); });

View file

@ -22,6 +22,7 @@
#define LOGINPAGE_H_ #define LOGINPAGE_H_
#include "tool/AbstractObject.hpp" #include "tool/AbstractObject.hpp"
#include "tool/LinphoneEnums.hpp"
#include <QObject> #include <QObject>
#include <linphone++/linphone.hh> #include <linphone++/linphone.hh>
@ -35,7 +36,11 @@ public:
Q_PROPERTY(linphone::RegistrationState registrationState READ getRegistrationState NOTIFY registrationStateChanged) Q_PROPERTY(linphone::RegistrationState registrationState READ getRegistrationState NOTIFY registrationStateChanged)
Q_PROPERTY(QString errorMessage READ getErrorMessage NOTIFY errorMessageChanged) Q_PROPERTY(QString errorMessage READ getErrorMessage NOTIFY errorMessageChanged)
Q_INVOKABLE void login(const QString &username, const QString &password); Q_INVOKABLE void login(const QString &username,
const QString &password,
QString displayName = QString(),
QString domain = QString(),
LinphoneEnums::TransportType transportType = LinphoneEnums::TransportType::Udp);
linphone::RegistrationState getRegistrationState() const; linphone::RegistrationState getRegistrationState() const;
void setRegistrationState(linphone::RegistrationState status); void setRegistrationState(linphone::RegistrationState status);

View file

@ -54,7 +54,12 @@ std::shared_ptr<linphone::Account> AccountManager::createAccount(const QString &
return core->createAccount(core->createAccountParams()); return core->createAccount(core->createAccountParams());
} }
bool AccountManager::login(QString username, QString password, QString *errorMessage) { bool AccountManager::login(QString username,
QString password,
QString displayName,
QString domain,
linphone::TransportType transportType,
QString *errorMessage) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto core = CoreModel::getInstance()->getCore(); auto core = CoreModel::getInstance()->getCore();
auto factory = linphone::Factory::get(); auto factory = linphone::Factory::get();
@ -74,6 +79,9 @@ bool AccountManager::login(QString username, QString password, QString *errorMes
username = Utils::getUsername(username); username = Utils::getUsername(username);
identity->setUsername(Utils::appStringToCoreString(username)); identity->setUsername(Utils::appStringToCoreString(username));
if (!displayName.isEmpty()) identity->setDisplayName(Utils::appStringToCoreString(displayName));
identity->setTransport(transportType);
if (!domain.isEmpty()) identity->setDomain(Utils::appStringToCoreString(domain));
if (params->setIdentityAddress(identity)) { if (params->setIdentityAddress(identity)) {
qWarning() << log() qWarning() << log()
.arg(QStringLiteral("Unable to set identity address: `%1`.")) .arg(QStringLiteral("Unable to set identity address: `%1`."))

View file

@ -36,7 +36,12 @@ public:
AccountManager(QObject *parent = nullptr); AccountManager(QObject *parent = nullptr);
~AccountManager(); ~AccountManager();
bool login(QString username, QString password, QString *errorMessage = nullptr); bool login(QString username,
QString password,
QString displayName = QString(),
QString domain = QString(),
linphone::TransportType transportType = linphone::TransportType::Udp,
QString *errorMessage = nullptr);
std::shared_ptr<linphone::Account> createAccount(const QString &assistantFile); std::shared_ptr<linphone::Account> createAccount(const QString &assistantFile);
enum RegisterType { PhoneNumber = 0, Email = 1 }; enum RegisterType { PhoneNumber = 0, Email = 1 };

View file

@ -303,7 +303,8 @@ void LinphoneEnums::fromString(const QString &transportType, LinphoneEnums::Tran
if (transportType.toUpper() == QLatin1String("TCP")) *transport = TransportType::Tcp; if (transportType.toUpper() == QLatin1String("TCP")) *transport = TransportType::Tcp;
else if (transportType.toUpper() == QLatin1String("UDP")) *transport = TransportType::Udp; else if (transportType.toUpper() == QLatin1String("UDP")) *transport = TransportType::Udp;
else if (transportType.toUpper() == QLatin1String("TLS")) *transport = TransportType::Tls; else if (transportType.toUpper() == QLatin1String("TLS")) *transport = TransportType::Tls;
else *transport = TransportType::Dtls; else if (transportType.toUpper() == QLatin1String("DTLS")) *transport = TransportType::Dtls;
else *transport = TransportType::Udp;
} }
linphone::VideoSourceScreenSharingType linphone::VideoSourceScreenSharingType

View file

@ -16,20 +16,9 @@ ColumnLayout {
enableErrorText: true enableErrorText: true
contentItem: TextField { contentItem: TextField {
id: usernameEdit id: usernameEdit
isError: username.errorTextVisible
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
Layout.preferredHeight: 49 * DefaultStyle.dp Layout.preferredHeight: 49 * DefaultStyle.dp
Binding on backgroundBorderColor {
when: errorText.opacity != 0
value: DefaultStyle.danger_500main
}
Binding on backgroundBorderColor {
when: username.errorTextItem.opacity != 0
value: DefaultStyle.danger_500main
}
Binding on color {
when: errorText.opacity != 0
value: DefaultStyle.danger_500main
}
} }
} }
Item { Item {
@ -41,21 +30,10 @@ ColumnLayout {
enableErrorText: true enableErrorText: true
contentItem: TextField { contentItem: TextField {
id: passwordEdit id: passwordEdit
isError: password.errorTextVisible
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
Layout.preferredHeight: 49 * DefaultStyle.dp Layout.preferredHeight: 49 * DefaultStyle.dp
hidden: true hidden: true
Binding on backgroundBorderColor {
when: errorText.opacity != 0
value: DefaultStyle.danger_500main
}
Binding on backgroundBorderColor {
when: password.errorTextItem.opacity != 0
value: DefaultStyle.danger_500main
}
Binding on color {
when: errorText.opacity != 0
value: DefaultStyle.danger_500main
}
} }
} }

View file

@ -12,7 +12,7 @@ Control.TextField {
rightPadding: eyeButton.visible ? 5 * DefaultStyle.dp + eyeButton.width + eyeButton.rightMargin : 15 * DefaultStyle.dp rightPadding: eyeButton.visible ? 5 * DefaultStyle.dp + eyeButton.width + eyeButton.rightMargin : 15 * DefaultStyle.dp
echoMode: (hidden && !eyeButton.checked) ? TextInput.Password : TextInput.Normal echoMode: (hidden && !eyeButton.checked) ? TextInput.Password : TextInput.Normal
verticalAlignment: TextInput.AlignVCenter verticalAlignment: TextInput.AlignVCenter
color: DefaultStyle.main2_600 color: isError ? DefaultStyle.danger_500main : DefaultStyle.main2_600
placeholderTextColor: DefaultStyle.placeholders placeholderTextColor: DefaultStyle.placeholders
font { font {
family: DefaultStyle.defaultFont family: DefaultStyle.defaultFont
@ -24,6 +24,7 @@ Control.TextField {
property bool controlIsDown: false property bool controlIsDown: false
property bool hidden: false property bool hidden: false
property bool isError: false
property bool backgroundVisible: true property bool backgroundVisible: true
property color backgroundColor: DefaultStyle.grey_100 property color backgroundColor: DefaultStyle.grey_100
property color backgroundBorderColor: DefaultStyle.grey_200 property color backgroundBorderColor: DefaultStyle.grey_200
@ -47,7 +48,9 @@ Control.TextField {
anchors.fill: parent anchors.fill: parent
radius: 79 * DefaultStyle.dp radius: 79 * DefaultStyle.dp
color: mainItem.backgroundColor color: mainItem.backgroundColor
border.color: activeFocus border.color: mainItem.isError
? DefaultStyle.danger_500main
: mainItem.activeFocus
? DefaultStyle.main1_500_main ? DefaultStyle.main1_500_main
: mainItem.backgroundBorderColor : mainItem.backgroundBorderColor
} }

View file

@ -142,36 +142,45 @@ LoginLayout {
Component { Component {
id: secondItem id: secondItem
ColumnLayout { ColumnLayout {
spacing: 0 spacing: 2 * DefaultStyle.dp
ColumnLayout { ColumnLayout {
spacing: 16 * DefaultStyle.dp spacing: 16 * DefaultStyle.dp
FormItemLayout { FormItemLayout {
label: qsTr("Username")
mandatory: true
contentItem: TextField {
id: username id: username
label: qsTr("Nom d'utilisateur")
mandatory: true
enableErrorText: true
contentItem: TextField {
id: usernameEdit
isError: username.errorTextVisible
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
} }
} }
FormItemLayout { FormItemLayout {
label: qsTr("Password")
mandatory: true
contentItem: TextField {
id: password id: password
label: qsTr("Mot de passe")
mandatory: true
enableErrorText: true
contentItem: TextField {
id: passwordEdit
isError: password.errorTextVisible
hidden: true hidden: true
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
} }
} }
FormItemLayout { FormItemLayout {
label: qsTr("Domain")
mandatory: true
contentItem: TextField {
id: domain id: domain
label: qsTr("Domaine")
mandatory: true
enableErrorText: true
contentItem: TextField {
id: domainEdit
isError: domain.errorTextVisible
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
} }
} }
FormItemLayout { FormItemLayout {
label: qsTr("Display Name") label: qsTr("Nom d'affichage")
contentItem: TextField { contentItem: TextField {
id: displayName id: displayName
Layout.preferredWidth: 360 * DefaultStyle.dp Layout.preferredWidth: 360 * DefaultStyle.dp
@ -180,9 +189,17 @@ LoginLayout {
FormItemLayout { FormItemLayout {
label: qsTr("Transport") label: qsTr("Transport")
contentItem: ComboBox { contentItem: ComboBox {
id: transportCbox
height: 49 * DefaultStyle.dp height: 49 * DefaultStyle.dp
width: 360 * DefaultStyle.dp width: 360 * DefaultStyle.dp
model:[ "TCP", "UDP", "TLS", "DTLS"] textRole: "text"
valueRole: "value"
model: [
{text: "TCP", value: LinphoneEnums.TransportType.Tcp},
{text: "UDP", value: LinphoneEnums.TransportType.Udp},
{text: "TLS", value: LinphoneEnums.TransportType.Tls},
{text: "DTLS", value: LinphoneEnums.TransportType.Dtls}
]
} }
} }
} }
@ -191,10 +208,11 @@ LoginLayout {
id: errorText id: errorText
Connections { Connections {
target: LoginPageCpp target: LoginPageCpp
function onErrorMessageChanged() {
errorText.text = LoginPageCpp.errorMessage
}
function onRegistrationStateChanged() { function onRegistrationStateChanged() {
if (LoginPageCpp.registrationState === LinphoneEnums.RegistrationState.Failed) { if (LoginPageCpp.registrationState === LinphoneEnums.RegistrationState.Ok) {
errorText.text = qsTr("Connection has failed. Please verify your credentials")
} else if (LoginPageCpp.registrationState === LinphoneEnums.RegistrationState.Ok) {
mainItem.connectionSucceed() mainItem.connectionSucceed()
} }
} }
@ -202,16 +220,75 @@ LoginLayout {
} }
Button { Button {
id: connectionButton
Layout.topMargin: 32 * DefaultStyle.dp Layout.topMargin: 32 * DefaultStyle.dp
leftPadding: 20 * DefaultStyle.dp leftPadding: 20 * DefaultStyle.dp
rightPadding: 20 * DefaultStyle.dp rightPadding: 20 * DefaultStyle.dp
topPadding: 11 * DefaultStyle.dp topPadding: 11 * DefaultStyle.dp
bottomPadding: 11 * DefaultStyle.dp bottomPadding: 11 * DefaultStyle.dp
text: qsTr("Log in") contentItem: StackLayout {
onClicked: { id: connectionButtonContent
console.debug("[SIPLoginPage] User: Log in") currentIndex: 0
LoginPageCpp.login(username.inputText, password.inputText); Text {
text: qsTr("Connexion")
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font {
pixelSize: 18 * DefaultStyle.dp
weight: 600 * DefaultStyle.dp
} }
color: DefaultStyle.grey_0
}
BusyIndicator {
implicitWidth: parent.height
implicitHeight: parent.height
Layout.alignment: Qt.AlignCenter
indicatorColor: DefaultStyle.grey_0
}
Connections {
target: LoginPageCpp
function onRegistrationStateChanged() {
if (LoginPageCpp.registrationState != LinphoneEnums.RegistrationState.Progress) {
connectionButton.enabled = true
connectionButtonContent.currentIndex = 0
}
}
function onErrorMessageChanged() {
connectionButton.enabled = true
connectionButtonContent.currentIndex = 0
}
}
}
function trigger() {
username.errorMessage = ""
password.errorMessage = ""
domain.errorMessage = ""
errorText.text = ""
if (usernameEdit.text.length == 0 || passwordEdit.text.length == 0 || domainEdit.text.length == 0) {
if (usernameEdit.text.length == 0)
username.errorMessage = qsTr("Veuillez saisir un nom d'utilisateur")
if (passwordEdit.text.length == 0)
password.errorMessage = qsTr("Veuillez saisir un mot de passe")
if (domainEdit.text.length == 0)
domain.errorMessage = qsTr("Veuillez saisir un nom de domaine")
return
}
console.debug("[SIPLoginPage] User: Log in")
LoginPageCpp.login(usernameEdit.text, passwordEdit.text, displayName.text, domainEdit.text, transportCbox.currentValue);
connectionButton.enabled = false
connectionButtonContent.currentIndex = 1
}
Shortcut {
sequences: ["Return", "Enter"]
onActivated: if(domain.activeFocus) connectionButton.trigger()
else if(username.activeFocus) password.forceActiveFocus()
else if(password.activeFocus) domain.forceActiveFocus()
}
onPressed: connectionButton.trigger()
} }
Item { Item {
Layout.fillHeight: true Layout.fillHeight: true