Commit 074edf12 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(ui/views/App/Main/Assistant): handle linphone account creation

parent af0b2045
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>ActivateLinphoneSipAccountWithEmail</name>
<message>
<source>activateLinphoneSipAccount</source>
<translation>CREATE A LINPHONE ACCOUNT</translation>
</message>
<message>
<source>confirmAction</source>
<translation>ACTIVATE</translation>
</message>
<message>
<source>activationSteps</source>
<translation>To activate your account: Follow the instructions that we sent you at %1, then click on the button below.</translation>
</message>
</context>
<context> <context>
<name>App</name> <name>App</name>
<message> <message>
...@@ -120,6 +135,14 @@ ...@@ -120,6 +135,14 @@
<source>accountAlreadyExists</source> <source>accountAlreadyExists</source>
<translation>Account already exists.</translation> <translation>Account already exists.</translation>
</message> </message>
<message>
<source>smsActivationFailed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>emailActivationFailed</source>
<translation>Please verify that you have validated your account or try again.</translation>
</message>
</context> </context>
<context> <context>
<name>Calls</name> <name>Calls</name>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>ActivateLinphoneSipAccountWithEmail</name>
<message>
<source>activateLinphoneSipAccount</source>
<translation>CRÉER UN COMPTE LINPHONE</translation>
</message>
<message>
<source>confirmAction</source>
<translation>ACTIVER</translation>
</message>
<message>
<source>activationSteps</source>
<translation>Pour activer votre compte : Suivez les instructions que vous avez reçues à %1, puis cliquez sur le bouton plus bas.</translation>
</message>
</context>
<context> <context>
<name>App</name> <name>App</name>
<message> <message>
...@@ -120,6 +135,14 @@ ...@@ -120,6 +135,14 @@
<source>accountAlreadyExists</source> <source>accountAlreadyExists</source>
<translation>Le compte existe déjà.</translation> <translation>Le compte existe déjà.</translation>
</message> </message>
<message>
<source>smsActivationFailed</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>emailActivationFailed</source>
<translation>Merci de vérifier que vous avez validé votre compte ou réessayez plus tard.</translation>
</message>
</context> </context>
<context> <context>
<name>Calls</name> <name>Calls</name>
......
...@@ -333,6 +333,7 @@ ...@@ -333,6 +333,7 @@
<file>ui/views/App/Calls/Incall.qml</file> <file>ui/views/App/Calls/Incall.qml</file>
<file>ui/views/App/Calls/IncomingCall.qml</file> <file>ui/views/App/Calls/IncomingCall.qml</file>
<file>ui/views/App/Calls/OutgoingCall.qml</file> <file>ui/views/App/Calls/OutgoingCall.qml</file>
<file>ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml</file>
<file>ui/views/App/Main/Assistant/AssistantAbstractView.qml</file> <file>ui/views/App/Main/Assistant/AssistantAbstractView.qml</file>
<file>ui/views/App/Main/Assistant/AssistantHome.qml</file> <file>ui/views/App/Main/Assistant/AssistantHome.qml</file>
<file>ui/views/App/Main/Assistant/CreateLinphoneSipAccount.qml</file> <file>ui/views/App/Main/Assistant/CreateLinphoneSipAccount.qml</file>
...@@ -368,6 +369,7 @@ ...@@ -368,6 +369,7 @@
<file>ui/views/App/SplashScreen/SplashScreen.qml</file> <file>ui/views/App/SplashScreen/SplashScreen.qml</file>
<file>ui/views/App/Styles/Calls/CallStyle.qml</file> <file>ui/views/App/Styles/Calls/CallStyle.qml</file>
<file>ui/views/App/Styles/Calls/CallsWindowStyle.qml</file> <file>ui/views/App/Styles/Calls/CallsWindowStyle.qml</file>
<file>ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml</file>
<file>ui/views/App/Styles/Main/Assistant/AssistantAbstractViewStyle.qml</file> <file>ui/views/App/Styles/Main/Assistant/AssistantAbstractViewStyle.qml</file>
<file>ui/views/App/Styles/Main/Assistant/AssistantHomeStyle.qml</file> <file>ui/views/App/Styles/Main/Assistant/AssistantHomeStyle.qml</file>
<file>ui/views/App/Styles/Main/Assistant/CreateLinphoneSipAccountStyle.qml</file> <file>ui/views/App/Styles/Main/Assistant/CreateLinphoneSipAccountStyle.qml</file>
......
...@@ -70,18 +70,39 @@ public: ...@@ -70,18 +70,39 @@ public:
} }
} }
// void onActivateAccount ( void onActivateAccount (
// const shared_ptr<linphone::AccountCreator> &creator, const shared_ptr<linphone::AccountCreator> &,
// linphone::AccountCreatorStatus status, linphone::AccountCreatorStatus status,
// const string &resp const string &
// ) override {} ) override {
// if (
// void onIsAccountActivated ( status == linphone::AccountCreatorStatusAccountActivated ||
// const shared_ptr<linphone::AccountCreator> &creator, status == linphone::AccountCreatorStatusAccountAlreadyActivated
// linphone::AccountCreatorStatus status, )
// const string &resp emit m_assistant->activateStatusChanged("");
// ) override {} else {
// if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->activateStatusChanged(tr("requestFailed"));
else
emit m_assistant->activateStatusChanged(tr("smsActivationFailed"));
}
}
void onIsAccountActivated (
const shared_ptr<linphone::AccountCreator> &,
linphone::AccountCreatorStatus status,
const string &
) override {
if (status == linphone::AccountCreatorStatusAccountActivated)
emit m_assistant->activateStatusChanged("");
else {
if (status == linphone::AccountCreatorStatusRequestFailed)
emit m_assistant->activateStatusChanged(tr("requestFailed"));
else
emit m_assistant->activateStatusChanged(tr("emailActivationFailed"));
}
}
// void onLinkAccount ( // void onLinkAccount (
// const shared_ptr<linphone::AccountCreator> &creator, // const shared_ptr<linphone::AccountCreator> &creator,
// linphone::AccountCreatorStatus status, // linphone::AccountCreatorStatus status,
...@@ -136,6 +157,36 @@ AssistantModel::AssistantModel (QObject *parent) : QObject(parent) { ...@@ -136,6 +157,36 @@ AssistantModel::AssistantModel (QObject *parent) : QObject(parent) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void AssistantModel::activate () {
if (m_account_creator->getEmail().empty())
m_account_creator->activateAccount();
else
m_account_creator->isAccountActivated();
}
void AssistantModel::create () {
m_account_creator->createAccount();
}
void AssistantModel::login () {
m_account_creator->isAccountExist();
}
void AssistantModel::reset () {
m_account_creator->reset();
emit emailChanged("", "");
emit passwordChanged("", "");
emit phoneNumberChanged("", "");
emit usernameChanged("", "");
}
// -----------------------------------------------------------------------------
QString AssistantModel::getEmail () const {
return ::Utils::linphoneStringToQString(m_account_creator->getEmail());
}
void AssistantModel::setEmail (const QString &email) { void AssistantModel::setEmail (const QString &email) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig(); shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error; QString error;
...@@ -154,6 +205,10 @@ void AssistantModel::setEmail (const QString &email) { ...@@ -154,6 +205,10 @@ void AssistantModel::setEmail (const QString &email) {
emit emailChanged(email, error); emit emailChanged(email, error);
} }
QString AssistantModel::getPassword () const {
return ::Utils::linphoneStringToQString(m_account_creator->getPassword());
}
void AssistantModel::setPassword (const QString &password) { void AssistantModel::setPassword (const QString &password) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig(); shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error; QString error;
...@@ -180,6 +235,10 @@ void AssistantModel::setPassword (const QString &password) { ...@@ -180,6 +235,10 @@ void AssistantModel::setPassword (const QString &password) {
emit passwordChanged(password, error); emit passwordChanged(password, error);
} }
QString AssistantModel::getPhoneNumber () const {
return ::Utils::linphoneStringToQString(m_account_creator->getPhoneNumber());
}
void AssistantModel::setPhoneNumber (const QString &phone_number) { void AssistantModel::setPhoneNumber (const QString &phone_number) {
// shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig(); // shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error; QString error;
...@@ -189,6 +248,10 @@ void AssistantModel::setPhoneNumber (const QString &phone_number) { ...@@ -189,6 +248,10 @@ void AssistantModel::setPhoneNumber (const QString &phone_number) {
emit phoneNumberChanged(phone_number, error); emit phoneNumberChanged(phone_number, error);
} }
QString AssistantModel::getUsername () const {
return ::Utils::linphoneStringToQString(m_account_creator->getUsername());
}
void AssistantModel::setUsername (const QString &username) { void AssistantModel::setUsername (const QString &username) {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig(); shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error; QString error;
...@@ -213,22 +276,3 @@ void AssistantModel::setUsername (const QString &username) { ...@@ -213,22 +276,3 @@ void AssistantModel::setUsername (const QString &username) {
emit usernameChanged(username, error); emit usernameChanged(username, error);
} }
// -----------------------------------------------------------------------------
void AssistantModel::create () {
m_account_creator->createAccount();
}
void AssistantModel::login () {
m_account_creator->isAccountExist();
}
void AssistantModel::reset () {
m_account_creator->reset();
emit emailChanged("", "");
emit passwordChanged("", "");
emit phoneNumberChanged("", "");
emit usernameChanged("", "");
}
...@@ -33,16 +33,18 @@ class AssistantModel : public QObject { ...@@ -33,16 +33,18 @@ class AssistantModel : public QObject {
Q_OBJECT; Q_OBJECT;
Q_PROPERTY(QString email READ getEmail WRITE setEmail NOTIFY emailChanged);
Q_PROPERTY(QString password READ getPassword WRITE setPassword NOTIFY passwordChanged);
Q_PROPERTY(QString phoneNumber READ getPhoneNumber WRITE setPhoneNumber NOTIFY phoneNumberChanged);
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY usernameChanged);
public: public:
AssistantModel (QObject *parent = Q_NULLPTR); AssistantModel (QObject *parent = Q_NULLPTR);
Q_INVOKABLE void setEmail (const QString &email); Q_INVOKABLE void activate ();
Q_INVOKABLE void setPassword (const QString &password);
Q_INVOKABLE void setPhoneNumber (const QString &phone_number);
Q_INVOKABLE void setUsername (const QString &username);
Q_INVOKABLE void create (); Q_INVOKABLE void create ();
Q_INVOKABLE void login (); Q_INVOKABLE void login ();
Q_INVOKABLE void reset (); Q_INVOKABLE void reset ();
signals: signals:
...@@ -51,10 +53,23 @@ signals: ...@@ -51,10 +53,23 @@ signals:
void phoneNumberChanged (const QString &phone_number, const QString &error); void phoneNumberChanged (const QString &phone_number, const QString &error);
void usernameChanged (const QString &username, const QString &error); void usernameChanged (const QString &username, const QString &error);
void activateStatusChanged (const QString &error);
void createStatusChanged (const QString &error); void createStatusChanged (const QString &error);
void loginStatusChanged (const QString &error); void loginStatusChanged (const QString &error);
private: private:
QString getEmail () const;
void setEmail (const QString &email);
QString getPassword () const;
void setPassword (const QString &password);
QString getPhoneNumber () const;
void setPhoneNumber (const QString &phone_number);
QString getUsername () const;
void setUsername (const QString &username);
std::shared_ptr<linphone::AccountCreator> m_account_creator; std::shared_ptr<linphone::AccountCreator> m_account_creator;
std::shared_ptr<Handlers> m_handlers; std::shared_ptr<Handlers> m_handlers;
}; };
......
...@@ -27,12 +27,11 @@ ...@@ -27,12 +27,11 @@
char *Utils::rstrstr (const char *a, const char *b) { char *Utils::rstrstr (const char *a, const char *b) {
size_t a_len = strlen(a); size_t a_len = strlen(a);
size_t b_len = strlen(b); size_t b_len = strlen(b);
const char *s;
if (b_len > a_len) if (b_len > a_len)
return nullptr; return nullptr;
for (s = a + a_len - b_len; s >= a; --s) { for (const char *s = a + a_len - b_len; s >= a; --s) {
if (!strncmp(s, b, b_len)) if (!strncmp(s, b, b_len))
return const_cast<char *>(s); return const_cast<char *>(s);
} }
......
...@@ -12,15 +12,21 @@ Item { ...@@ -12,15 +12,21 @@ Item {
id: assistant id: assistant
readonly property string viewsPath: 'qrc:/ui/views/App/Main/Assistant/' readonly property string viewsPath: 'qrc:/ui/views/App/Main/Assistant/'
readonly property alias nViews: stack.depth
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function pushView (view) { function pushView (view, properties) {
stack.push( stack.push(
Utils.isString(view) ? viewsPath + view + '.qml' : view Utils.isString(view) ? viewsPath + view + '.qml' : view,
properties
) )
} }
function getView (index) {
return stack.get(index)
}
function popView () { function popView () {
stack.pop() stack.pop()
} }
......
import QtQuick 2.7
import Common 1.0
import Linphone 1.0
import App.Styles 1.0
// =============================================================================
AssistantAbstractView {
property var assistantModel
backEnabled: false
title: qsTr('activateLinphoneSipAccount')
mainAction: requestBlock.execute
mainActionEnabled: !requestBlock.loading
mainActionLabel: qsTr('confirmAction')
Column {
anchors.centerIn: parent
spacing: ActivateLinphoneSipAccountWithEmailStyle.spacing
width: parent.width
Text {
color: ActivateLinphoneSipAccountWithEmailStyle.activationSteps.color
font.pointSize: ActivateLinphoneSipAccountWithEmailStyle.activationSteps.fontSize
horizontalAlignment: Text.AlignHCenter
text: qsTr('activationSteps').replace('%1', assistantModel.email)
width: parent.width
wrapMode: Text.WordWrap
}
RequestBlock {
id: requestBlock
action: assistantModel.activate
width: parent.width
}
}
// ---------------------------------------------------------------------------
// Assistant.
// ---------------------------------------------------------------------------
Connections {
target: assistantModel
onActivateStatusChanged: {
requestBlock.stop(error)
if (!error.length) {
window.setView('Home')
}
}
}
}
...@@ -19,6 +19,8 @@ Item { ...@@ -19,6 +19,8 @@ Item {
property alias description: description.text property alias description: description.text
property alias title: title.text property alias title: title.text
property bool backEnabled: true
default property alias _content: content.data default property alias _content: content.data
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -94,6 +96,8 @@ Item { ...@@ -94,6 +96,8 @@ Item {
TextButtonA { TextButtonA {
text: qsTr('back') text: qsTr('back')
visible: view.backEnabled
onClicked: assistant.popView() onClicked: assistant.popView()
} }
......
...@@ -42,7 +42,7 @@ AssistantAbstractView { ...@@ -42,7 +42,7 @@ AssistantAbstractView {
TextField { TextField {
id: username id: username
onTextChanged: assistantModel.setUsername(text) onTextChanged: assistantModel.username = text
} }
} }
} }
...@@ -54,7 +54,7 @@ AssistantAbstractView { ...@@ -54,7 +54,7 @@ AssistantAbstractView {
TextField { TextField {
id: email id: email
onTextChanged: assistantModel.setEmail(text) onTextChanged: assistantModel.email = text
} }
} }
} }
...@@ -66,7 +66,7 @@ AssistantAbstractView { ...@@ -66,7 +66,7 @@ AssistantAbstractView {
TextField { TextField {
id: password id: password
onTextChanged: assistantModel.setPassword(text) onTextChanged: assistantModel.password = text
} }
} }
} }
...@@ -108,7 +108,9 @@ AssistantAbstractView { ...@@ -108,7 +108,9 @@ AssistantAbstractView {
onCreateStatusChanged: { onCreateStatusChanged: {
requestBlock.stop(error) requestBlock.stop(error)
if (!error.length) { if (!error.length) {
// TODO. assistant.pushView('ActivateLinphoneSipAccountWithEmail', {
assistantModel: assistantModel
})
} }
} }
} }
......
...@@ -45,7 +45,7 @@ AssistantAbstractView { ...@@ -45,7 +45,7 @@ AssistantAbstractView {
TextField { TextField {
id: username id: username
onTextChanged: assistantModel.setUsername(text) onTextChanged: assistantModel.username = text
} }
} }
} }
......
...@@ -21,7 +21,7 @@ Form { ...@@ -21,7 +21,7 @@ Form {
TextField { TextField {
id: username id: username
onTextChanged: assistantModel.setUsername(text) onTextChanged: assistantModel.username = text
} }
} }
} }
...@@ -33,7 +33,7 @@ Form { ...@@ -33,7 +33,7 @@ Form {
TextField { TextField {
id: password id: password
onTextChanged: assistantModel.setPassword(text) onTextChanged: assistantModel.password = text
} }
} }
} }
......
pragma Singleton
import QtQuick 2.7
import Common 1.0
// =============================================================================
QtObject {
property int spacing: 20
property QtObject activationSteps: QtObject {
property color color: Colors.g
property int fontSize: 10
}
}
...@@ -4,24 +4,25 @@ module App.Styles ...@@ -4,24 +4,25 @@ module App.Styles
# Views styles ----------------------------------------------------------------- # Views styles -----------------------------------------------------------------
singleton CallStyle 1.0 Calls/CallStyle.qml singleton CallStyle 1.0 Calls/CallStyle.qml
singleton CallsWindowStyle 1.0 Calls/CallsWindowStyle.qml singleton CallsWindowStyle 1.0 Calls/CallsWindowStyle.qml
singleton AssistantAbstractViewStyle 1.0 Main/Assistant/AssistantAbstractViewStyle.qml singleton ActivateLinphoneSipAccountWithEmailStyle 1.0 Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml
singleton AssistantHomeStyle 1.0 Main/Assistant/AssistantHomeStyle.qml singleton AssistantAbstractViewStyle 1.0 Main/Assistant/AssistantAbstractViewStyle.qml
singleton CreateLinphoneSipAccountStyle 1.0 Main/Assistant/CreateLinphoneSipAccountStyle.qml singleton AssistantHomeStyle 1.0 Main/Assistant/AssistantHomeStyle.qml
singleton UseLinphoneSipAccountStyle 1.0 Main/Assistant/UseLinphoneSipAccountStyle.qml singleton CreateLinphoneSipAccountStyle 1.0 Main/Assistant/CreateLinphoneSipAccountStyle.qml
singleton UseLinphoneSipAccountStyle 1.0 Main/Assistant/UseLinphoneSipAccountStyle.qml
singleton AssistantStyle 1.0 Main/AssistantStyle.qml singleton AssistantStyle 1.0 Main/AssistantStyle.qml
singleton ContactEditStyle 1.0 Main/ContactEditStyle.qml singleton ContactEditStyle 1.0 Main/ContactEditStyle.qml
singleton ContactsStyle 1.0 Main/ContactsStyle.qml singleton ContactsStyle 1.0 Main/ContactsStyle.qml
singleton ConversationStyle 1.0 Main/ConversationStyle.qml singleton ConversationStyle 1.0 Main/ConversationStyle.qml
singleton HomeStyle 1.0 Main/HomeStyle.qml singleton HomeStyle 1.0 Main/HomeStyle.qml
singleton InviteFriendsStyle 1.0 Main/InviteFriendsStyle.qml singleton InviteFriendsStyle 1.0 Main/InviteFriendsStyle.qml
singleton MainWindowMenuBarStyle 1.0 Main/MainWindowMenuBarStyle.qml singleton MainWindowMenuBarStyle 1.0 Main/MainWindowMenuBarStyle.qml
singleton MainWindowStyle 1.0 Main/MainWindowStyle.qml singleton MainWindowStyle 1.0 Main/MainWindowStyle.qml
singleton ManageAccountsStyle 1.0 Main/ManageAccountsStyle.qml singleton ManageAccountsStyle 1.0 Main/ManageAccountsStyle.qml
singleton SettingsWindowStyle 1.0 Settings/SettingsWindowStyle.qml singleton SettingsWindowStyle 1.0 Settings/SettingsWindowStyle.qml
singleton SettingsSipAccountsEditStyle 1.0 Settings/SettingsSipAccountsEditStyle.qml singleton SettingsSipAccountsEditStyle 1.0 Settings/SettingsSipAccountsEditStyle.qml
singleton SplashScreenStyle 1.0 SplashScreen/SplashScreenStyle.qml singleton SplashScreenStyle 1.0 SplashScreen/SplashScreenStyle.qml
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment