From 074edf12812659ef230a5b68db7064f227b898d3 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 11 Apr 2017 15:00:45 +0200 Subject: [PATCH] feat(ui/views/App/Main/Assistant): handle linphone account creation --- linphone-desktop/assets/languages/en.ts | 23 ++++ linphone-desktop/assets/languages/fr.ts | 23 ++++ linphone-desktop/resources.qrc | 2 + .../components/assistant/AssistantModel.cpp | 106 +++++++++++++----- .../components/assistant/AssistantModel.hpp | 25 ++++- linphone-desktop/src/utils.cpp | 3 +- .../ui/views/App/Main/Assistant.qml | 10 +- .../ActivateLinphoneSipAccountWithEmail.qml | 57 ++++++++++ .../Main/Assistant/AssistantAbstractView.qml | 4 + .../CreateLinphoneSipAccountWithEmail.qml | 10 +- ...reateLinphoneSipAccountWithPhoneNumber.qml | 2 +- .../UseLinphoneSipAccountWithUsername.qml | 4 +- ...tivateLinphoneSipAccountWithEmailStyle.qml | 15 +++ linphone-desktop/ui/views/App/Styles/qmldir | 37 +++--- 14 files changed, 256 insertions(+), 65 deletions(-) create mode 100644 linphone-desktop/ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml create mode 100644 linphone-desktop/ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml diff --git a/linphone-desktop/assets/languages/en.ts b/linphone-desktop/assets/languages/en.ts index 16b10589f..e5ad43858 100644 --- a/linphone-desktop/assets/languages/en.ts +++ b/linphone-desktop/assets/languages/en.ts @@ -1,6 +1,21 @@ + + ActivateLinphoneSipAccountWithEmail + + activateLinphoneSipAccount + CREATE A LINPHONE ACCOUNT + + + confirmAction + ACTIVATE + + + activationSteps + To activate your account: Follow the instructions that we sent you at %1, then click on the button below. + + App @@ -120,6 +135,14 @@ accountAlreadyExists Account already exists. + + smsActivationFailed + + + + emailActivationFailed + Please verify that you have validated your account or try again. + Calls diff --git a/linphone-desktop/assets/languages/fr.ts b/linphone-desktop/assets/languages/fr.ts index 9c6408d7b..80a8256e7 100644 --- a/linphone-desktop/assets/languages/fr.ts +++ b/linphone-desktop/assets/languages/fr.ts @@ -1,6 +1,21 @@ + + ActivateLinphoneSipAccountWithEmail + + activateLinphoneSipAccount + CRÉER UN COMPTE LINPHONE + + + confirmAction + ACTIVER + + + activationSteps + Pour activer votre compte : Suivez les instructions que vous avez reçues à %1, puis cliquez sur le bouton plus bas. + + App @@ -120,6 +135,14 @@ accountAlreadyExists Le compte existe déjà. + + smsActivationFailed + + + + emailActivationFailed + Merci de vérifier que vous avez validé votre compte ou réessayez plus tard. + Calls diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc index 75247aabd..0c38424f7 100644 --- a/linphone-desktop/resources.qrc +++ b/linphone-desktop/resources.qrc @@ -333,6 +333,7 @@ ui/views/App/Calls/Incall.qml ui/views/App/Calls/IncomingCall.qml ui/views/App/Calls/OutgoingCall.qml + ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml ui/views/App/Main/Assistant/AssistantAbstractView.qml ui/views/App/Main/Assistant/AssistantHome.qml ui/views/App/Main/Assistant/CreateLinphoneSipAccount.qml @@ -368,6 +369,7 @@ ui/views/App/SplashScreen/SplashScreen.qml ui/views/App/Styles/Calls/CallStyle.qml ui/views/App/Styles/Calls/CallsWindowStyle.qml + ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml ui/views/App/Styles/Main/Assistant/AssistantAbstractViewStyle.qml ui/views/App/Styles/Main/Assistant/AssistantHomeStyle.qml ui/views/App/Styles/Main/Assistant/CreateLinphoneSipAccountStyle.qml diff --git a/linphone-desktop/src/components/assistant/AssistantModel.cpp b/linphone-desktop/src/components/assistant/AssistantModel.cpp index 322f409f8..f026a7f0b 100644 --- a/linphone-desktop/src/components/assistant/AssistantModel.cpp +++ b/linphone-desktop/src/components/assistant/AssistantModel.cpp @@ -70,18 +70,39 @@ public: } } - // void onActivateAccount ( - // const shared_ptr &creator, - // linphone::AccountCreatorStatus status, - // const string &resp - // ) override {} - // - // void onIsAccountActivated ( - // const shared_ptr &creator, - // linphone::AccountCreatorStatus status, - // const string &resp - // ) override {} - // + void onActivateAccount ( + const shared_ptr &, + linphone::AccountCreatorStatus status, + const string & + ) override { + if ( + status == linphone::AccountCreatorStatusAccountActivated || + status == linphone::AccountCreatorStatusAccountAlreadyActivated + ) + emit m_assistant->activateStatusChanged(""); + else { + if (status == linphone::AccountCreatorStatusRequestFailed) + emit m_assistant->activateStatusChanged(tr("requestFailed")); + else + emit m_assistant->activateStatusChanged(tr("smsActivationFailed")); + } + } + + void onIsAccountActivated ( + const shared_ptr &, + 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 ( // const shared_ptr &creator, // linphone::AccountCreatorStatus status, @@ -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) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; @@ -154,6 +205,10 @@ void AssistantModel::setEmail (const QString &email) { emit emailChanged(email, error); } +QString AssistantModel::getPassword () const { + return ::Utils::linphoneStringToQString(m_account_creator->getPassword()); +} + void AssistantModel::setPassword (const QString &password) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; @@ -180,6 +235,10 @@ void AssistantModel::setPassword (const QString &password) { emit passwordChanged(password, error); } +QString AssistantModel::getPhoneNumber () const { + return ::Utils::linphoneStringToQString(m_account_creator->getPhoneNumber()); +} + void AssistantModel::setPhoneNumber (const QString &phone_number) { // shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; @@ -189,6 +248,10 @@ void AssistantModel::setPhoneNumber (const QString &phone_number) { emit phoneNumberChanged(phone_number, error); } +QString AssistantModel::getUsername () const { + return ::Utils::linphoneStringToQString(m_account_creator->getUsername()); +} + void AssistantModel::setUsername (const QString &username) { shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; @@ -213,22 +276,3 @@ void AssistantModel::setUsername (const QString &username) { 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("", ""); -} diff --git a/linphone-desktop/src/components/assistant/AssistantModel.hpp b/linphone-desktop/src/components/assistant/AssistantModel.hpp index f9415e141..20650070f 100644 --- a/linphone-desktop/src/components/assistant/AssistantModel.hpp +++ b/linphone-desktop/src/components/assistant/AssistantModel.hpp @@ -33,16 +33,18 @@ class AssistantModel : public QObject { 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: AssistantModel (QObject *parent = Q_NULLPTR); - Q_INVOKABLE void setEmail (const QString &email); - 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 activate (); Q_INVOKABLE void create (); Q_INVOKABLE void login (); + Q_INVOKABLE void reset (); signals: @@ -51,10 +53,23 @@ signals: void phoneNumberChanged (const QString &phone_number, const QString &error); void usernameChanged (const QString &username, const QString &error); + void activateStatusChanged (const QString &error); void createStatusChanged (const QString &error); void loginStatusChanged (const QString &error); 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 m_account_creator; std::shared_ptr m_handlers; }; diff --git a/linphone-desktop/src/utils.cpp b/linphone-desktop/src/utils.cpp index c2d5b9431..637b348a0 100644 --- a/linphone-desktop/src/utils.cpp +++ b/linphone-desktop/src/utils.cpp @@ -27,12 +27,11 @@ char *Utils::rstrstr (const char *a, const char *b) { size_t a_len = strlen(a); size_t b_len = strlen(b); - const char *s; if (b_len > a_len) 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)) return const_cast(s); } diff --git a/linphone-desktop/ui/views/App/Main/Assistant.qml b/linphone-desktop/ui/views/App/Main/Assistant.qml index 7dccc13ce..e03eee5c5 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant.qml @@ -12,15 +12,21 @@ Item { id: 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( - Utils.isString(view) ? viewsPath + view + '.qml' : view + Utils.isString(view) ? viewsPath + view + '.qml' : view, + properties ) } + function getView (index) { + return stack.get(index) + } + function popView () { stack.pop() } diff --git a/linphone-desktop/ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml b/linphone-desktop/ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml new file mode 100644 index 000000000..f80626fb3 --- /dev/null +++ b/linphone-desktop/ui/views/App/Main/Assistant/ActivateLinphoneSipAccountWithEmail.qml @@ -0,0 +1,57 @@ +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') + } + } + } +} diff --git a/linphone-desktop/ui/views/App/Main/Assistant/AssistantAbstractView.qml b/linphone-desktop/ui/views/App/Main/Assistant/AssistantAbstractView.qml index 47c40fb23..a90226be2 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant/AssistantAbstractView.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant/AssistantAbstractView.qml @@ -19,6 +19,8 @@ Item { property alias description: description.text property alias title: title.text + property bool backEnabled: true + default property alias _content: content.data // --------------------------------------------------------------------------- @@ -94,6 +96,8 @@ Item { TextButtonA { text: qsTr('back') + visible: view.backEnabled + onClicked: assistant.popView() } diff --git a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithEmail.qml b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithEmail.qml index 55bdf2e79..47a9773a7 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithEmail.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithEmail.qml @@ -42,7 +42,7 @@ AssistantAbstractView { TextField { id: username - onTextChanged: assistantModel.setUsername(text) + onTextChanged: assistantModel.username = text } } } @@ -54,7 +54,7 @@ AssistantAbstractView { TextField { id: email - onTextChanged: assistantModel.setEmail(text) + onTextChanged: assistantModel.email = text } } } @@ -66,7 +66,7 @@ AssistantAbstractView { TextField { id: password - onTextChanged: assistantModel.setPassword(text) + onTextChanged: assistantModel.password = text } } } @@ -108,7 +108,9 @@ AssistantAbstractView { onCreateStatusChanged: { requestBlock.stop(error) if (!error.length) { - // TODO. + assistant.pushView('ActivateLinphoneSipAccountWithEmail', { + assistantModel: assistantModel + }) } } } diff --git a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml index 1cb54eb78..2fde8f524 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml @@ -45,7 +45,7 @@ AssistantAbstractView { TextField { id: username - onTextChanged: assistantModel.setUsername(text) + onTextChanged: assistantModel.username = text } } } diff --git a/linphone-desktop/ui/views/App/Main/Assistant/UseLinphoneSipAccountWithUsername.qml b/linphone-desktop/ui/views/App/Main/Assistant/UseLinphoneSipAccountWithUsername.qml index cfcd3a2b6..6fa7eef88 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant/UseLinphoneSipAccountWithUsername.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant/UseLinphoneSipAccountWithUsername.qml @@ -21,7 +21,7 @@ Form { TextField { id: username - onTextChanged: assistantModel.setUsername(text) + onTextChanged: assistantModel.username = text } } } @@ -33,7 +33,7 @@ Form { TextField { id: password - onTextChanged: assistantModel.setPassword(text) + onTextChanged: assistantModel.password = text } } } diff --git a/linphone-desktop/ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml b/linphone-desktop/ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml new file mode 100644 index 000000000..3179749bd --- /dev/null +++ b/linphone-desktop/ui/views/App/Styles/Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml @@ -0,0 +1,15 @@ +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 + } +} diff --git a/linphone-desktop/ui/views/App/Styles/qmldir b/linphone-desktop/ui/views/App/Styles/qmldir index c84f82f75..c93606564 100644 --- a/linphone-desktop/ui/views/App/Styles/qmldir +++ b/linphone-desktop/ui/views/App/Styles/qmldir @@ -4,24 +4,25 @@ module App.Styles # Views styles ----------------------------------------------------------------- -singleton CallStyle 1.0 Calls/CallStyle.qml -singleton CallsWindowStyle 1.0 Calls/CallsWindowStyle.qml +singleton CallStyle 1.0 Calls/CallStyle.qml +singleton CallsWindowStyle 1.0 Calls/CallsWindowStyle.qml -singleton AssistantAbstractViewStyle 1.0 Main/Assistant/AssistantAbstractViewStyle.qml -singleton AssistantHomeStyle 1.0 Main/Assistant/AssistantHomeStyle.qml -singleton CreateLinphoneSipAccountStyle 1.0 Main/Assistant/CreateLinphoneSipAccountStyle.qml -singleton UseLinphoneSipAccountStyle 1.0 Main/Assistant/UseLinphoneSipAccountStyle.qml +singleton ActivateLinphoneSipAccountWithEmailStyle 1.0 Main/Assistant/ActivateLinphoneSipAccountWithEmailStyle.qml +singleton AssistantAbstractViewStyle 1.0 Main/Assistant/AssistantAbstractViewStyle.qml +singleton AssistantHomeStyle 1.0 Main/Assistant/AssistantHomeStyle.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 ContactEditStyle 1.0 Main/ContactEditStyle.qml -singleton ContactsStyle 1.0 Main/ContactsStyle.qml -singleton ConversationStyle 1.0 Main/ConversationStyle.qml -singleton HomeStyle 1.0 Main/HomeStyle.qml -singleton InviteFriendsStyle 1.0 Main/InviteFriendsStyle.qml -singleton MainWindowMenuBarStyle 1.0 Main/MainWindowMenuBarStyle.qml -singleton MainWindowStyle 1.0 Main/MainWindowStyle.qml -singleton ManageAccountsStyle 1.0 Main/ManageAccountsStyle.qml +singleton AssistantStyle 1.0 Main/AssistantStyle.qml +singleton ContactEditStyle 1.0 Main/ContactEditStyle.qml +singleton ContactsStyle 1.0 Main/ContactsStyle.qml +singleton ConversationStyle 1.0 Main/ConversationStyle.qml +singleton HomeStyle 1.0 Main/HomeStyle.qml +singleton InviteFriendsStyle 1.0 Main/InviteFriendsStyle.qml +singleton MainWindowMenuBarStyle 1.0 Main/MainWindowMenuBarStyle.qml +singleton MainWindowStyle 1.0 Main/MainWindowStyle.qml +singleton ManageAccountsStyle 1.0 Main/ManageAccountsStyle.qml -singleton SettingsWindowStyle 1.0 Settings/SettingsWindowStyle.qml -singleton SettingsSipAccountsEditStyle 1.0 Settings/SettingsSipAccountsEditStyle.qml -singleton SplashScreenStyle 1.0 SplashScreen/SplashScreenStyle.qml +singleton SettingsWindowStyle 1.0 Settings/SettingsWindowStyle.qml +singleton SettingsSipAccountsEditStyle 1.0 Settings/SettingsSipAccountsEditStyle.qml +singleton SplashScreenStyle 1.0 SplashScreen/SplashScreenStyle.qml