diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index a271bc814..88c9ad6d3 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -128,7 +128,7 @@ set(SOURCES src/components/sip-addresses/SipAddressesProxyModel.cpp src/components/sip-addresses/SipAddressObserver.cpp src/components/sound-player/SoundPlayer.cpp - src/components/telephone-numbers/TelephoneNumbers.cpp + src/components/telephone-numbers/TelephoneNumbersModel.cpp src/components/text-to-speech/TextToSpeech.cpp src/components/timeline/TimelineModel.cpp src/externals/single-application/SingleApplication.cpp @@ -176,7 +176,7 @@ set(HEADERS src/components/sip-addresses/SipAddressesProxyModel.hpp src/components/sip-addresses/SipAddressObserver.hpp src/components/sound-player/SoundPlayer.hpp - src/components/telephone-numbers/TelephoneNumbers.hpp + src/components/telephone-numbers/TelephoneNumbersModel.hpp src/components/text-to-speech/TextToSpeech.hpp src/components/timeline/TimelineModel.hpp src/externals/single-application/SingleApplication.hpp diff --git a/linphone-desktop/assets/languages/en.ts b/linphone-desktop/assets/languages/en.ts index 9bc31b279..b9ddc418c 100644 --- a/linphone-desktop/assets/languages/en.ts +++ b/linphone-desktop/assets/languages/en.ts @@ -150,6 +150,22 @@ emailActivationFailed Please verify that you have validated your account or try again. + + phoneNumberStatusInvalid + Invalid phone number! + + + phoneNumberStatusTooShort + Too short! + + + phoneNumberStatusTooLong + Too short! + + + phoneNumberStatusInvalidCountryCode + Invalid country code! + AuthenticationRequest @@ -605,6 +621,14 @@ Server url not configured. displayNameLabel Display name (optional) + + confirmAction + CREATE + + + quitWarning + Your account has been created but is not yet validated. If you quit this view, you should add manually your account and validate it within 24 hours. + DroppableTextArea diff --git a/linphone-desktop/assets/languages/fr.ts b/linphone-desktop/assets/languages/fr.ts index 9c9c97c2b..9f29ad488 100644 --- a/linphone-desktop/assets/languages/fr.ts +++ b/linphone-desktop/assets/languages/fr.ts @@ -150,6 +150,22 @@ emailActivationFailed Merci de vérifier que vous avez validé votre compte ou réessayez plus tard. + + phoneNumberStatusInvalid + Numéro de tél. invalide ! + + + phoneNumberStatusTooShort + Trop court ! + + + phoneNumberStatusTooLong + Trop long ! + + + phoneNumberStatusInvalidCountryCode + Indicatif tél. invalide ! + AuthenticationRequest @@ -605,6 +621,14 @@ Url du serveur non configurée. displayNameLabel Nom d'affichage (optionnel) + + confirmAction + CRÉER + + + quitWarning + Votre compte a été crée mais il n'a pas été validé. Si vous quittez cette vue, vous devrez ajouter manuellement votre compte et le valider dans les 24 heures. + DroppableTextArea diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index 2940ecfb0..c76a9c4a4 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -353,7 +353,7 @@ void App::registerTypes () { registerType("ContactsListProxyModel"); registerType("SipAddressesProxyModel"); registerType("SoundPlayer"); - registerType("TelephoneNumbers"); + registerType("TelephoneNumbersModel"); registerSingletonType("AudioCodecsModel"); registerSingletonType("Clipboard"); diff --git a/linphone-desktop/src/components/Components.hpp b/linphone-desktop/src/components/Components.hpp index 3d7456452..c7a1ececc 100644 --- a/linphone-desktop/src/components/Components.hpp +++ b/linphone-desktop/src/components/Components.hpp @@ -40,7 +40,7 @@ #include "settings/AccountSettingsModel.hpp" #include "sip-addresses/SipAddressesProxyModel.hpp" #include "sound-player/SoundPlayer.hpp" -#include "telephone-numbers/TelephoneNumbers.hpp" +#include "telephone-numbers/TelephoneNumbersModel.hpp" #include "text-to-speech/TextToSpeech.hpp" #include "timeline/TimelineModel.hpp" diff --git a/linphone-desktop/src/components/assistant/AssistantModel.cpp b/linphone-desktop/src/components/assistant/AssistantModel.cpp index acb82b3ed..d7efb874a 100644 --- a/linphone-desktop/src/components/assistant/AssistantModel.cpp +++ b/linphone-desktop/src/components/assistant/AssistantModel.cpp @@ -180,6 +180,7 @@ void AssistantModel::login () { } void AssistantModel::reset () { + mCountryCode = ""; mAccountCreator->reset(); emit emailChanged("", ""); @@ -246,15 +247,43 @@ void AssistantModel::setPassword (const QString &password) { // ----------------------------------------------------------------------------- +QString AssistantModel::getCountryCode () const { + return mCountryCode; +} + +void AssistantModel::setCountryCode (const QString &countryCode) { + mCountryCode = countryCode; + emit countryCodeChanged(countryCode); +} + +// ----------------------------------------------------------------------------- + QString AssistantModel::getPhoneNumber () const { return ::Utils::coreStringToAppString(mAccountCreator->getPhoneNumber()); } void AssistantModel::setPhoneNumber (const QString &phoneNumber) { - // shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); + shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); QString error; - // TODO: use the future wrapped function: `set_phone_number`. + switch (mAccountCreator->setPhoneNumber(::Utils::appStringToCoreString(phoneNumber), ::Utils::appStringToCoreString(mCountryCode))) { + case linphone::AccountCreatorPhoneNumberStatusOk: + break; + case linphone::AccountCreatorPhoneNumberStatusInvalid: + error = tr("phoneNumberStatusInvalid"); + break; + case linphone::AccountCreatorPhoneNumberStatusTooShort: + error = tr("phoneNumberStatusTooShort"); + break; + case linphone::AccountCreatorPhoneNumberStatusTooLong: + error = tr("phoneNumberStatusTooLong"); + break; + case linphone::AccountCreatorPhoneNumberStatusInvalidCountryCode: + error = tr("phoneNumberStatusInvalidCountryCode"); + break; + default: + break; + } emit phoneNumberChanged(phoneNumber, error); } diff --git a/linphone-desktop/src/components/assistant/AssistantModel.hpp b/linphone-desktop/src/components/assistant/AssistantModel.hpp index 598c24b57..29f951a91 100644 --- a/linphone-desktop/src/components/assistant/AssistantModel.hpp +++ b/linphone-desktop/src/components/assistant/AssistantModel.hpp @@ -35,6 +35,7 @@ class AssistantModel : public QObject { Q_PROPERTY(QString email READ getEmail WRITE setEmail NOTIFY emailChanged); Q_PROPERTY(QString password READ getPassword WRITE setPassword NOTIFY passwordChanged); + Q_PROPERTY(QString countryCode READ getCountryCode WRITE setCountryCode NOTIFY countryCodeChanged); Q_PROPERTY(QString phoneNumber READ getPhoneNumber WRITE setPhoneNumber NOTIFY phoneNumberChanged); Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY usernameChanged); Q_PROPERTY(QString displayName READ getDisplayName WRITE setDisplayName NOTIFY displayNameChanged); @@ -52,6 +53,7 @@ public: signals: void emailChanged (const QString &email, const QString &error); void passwordChanged (const QString &password, const QString &error); + void countryCodeChanged (const QString &countryCode); void phoneNumberChanged (const QString &phoneNumber, const QString &error); void usernameChanged (const QString &username, const QString &error); void displayNameChanged (const QString &displayName, const QString &error); @@ -69,6 +71,9 @@ private: QString getPassword () const; void setPassword (const QString &password); + QString getCountryCode () const; + void setCountryCode (const QString &countryCode); + QString getPhoneNumber () const; void setPhoneNumber (const QString &phoneNumber); @@ -83,6 +88,7 @@ private: QString mapAccountCreatorUsernameStatusToString (linphone::AccountCreatorUsernameStatus status) const; + QString mCountryCode; QString mConfigFilename; std::shared_ptr mAccountCreator; diff --git a/linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.cpp b/linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.cpp similarity index 89% rename from linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.cpp rename to linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.cpp index c08663440..095ed8ff1 100644 --- a/linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.cpp +++ b/linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.cpp @@ -1,5 +1,5 @@ /* - * TelephoneNumbers.cpp + * TelephoneNumbersModel.cpp * Copyright (C) 2017 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -20,11 +20,13 @@ * Author: Ronan Abhamon */ -#include "TelephoneNumbers.hpp" +#include "TelephoneNumbersModel.hpp" + +using namespace std; // ============================================================================= -const QList > TelephoneNumbers::mCountryCodes = { +const QList > TelephoneNumbersModel::mCountryCodes = { { QLocale::Afghanistan, "93" }, { QLocale::Albania, "355" }, { QLocale::Algeria, "213" }, @@ -252,19 +254,19 @@ const QList > TelephoneNumbers::mCountryCodes = // ----------------------------------------------------------------------------- -TelephoneNumbers::TelephoneNumbers (QObject *parent) : QAbstractListModel(parent) {} +TelephoneNumbersModel::TelephoneNumbersModel (QObject *parent) : QAbstractListModel(parent) {} -int TelephoneNumbers::rowCount (const QModelIndex &) const { +int TelephoneNumbersModel::rowCount (const QModelIndex &) const { return mCountryCodes.count(); } -QHash TelephoneNumbers::roleNames () const { +QHash TelephoneNumbersModel::roleNames () const { QHash roles; roles[Qt::DisplayRole] = "$phoneNumber"; return roles; } -QVariant TelephoneNumbers::data (const QModelIndex &index, int role) const { +QVariant TelephoneNumbersModel::data (const QModelIndex &index, int role) const { int row = index.row(); if (!index.isValid() || row < 0 || row >= mCountryCodes.count()) @@ -272,11 +274,24 @@ QVariant TelephoneNumbers::data (const QModelIndex &index, int role) const { if (role == Qt::DisplayRole) { const QPair &countryCode = mCountryCodes[row]; - QVariantMap map; + QVariantMap map; map["countryCode"] = countryCode.second; - map["countryName"] = QLocale::countryToString(countryCode.first); + map["countryName"] = QStringLiteral("%1 (+%2)") + .arg(QLocale::countryToString(countryCode.first)) + .arg(countryCode.second); + return map; } return QVariant(); } + +int TelephoneNumbersModel::getDefaultIndex () const { + QLocale::Country country = QLocale().country(); + const auto it = find_if( + mCountryCodes.cbegin(), mCountryCodes.cend(), [&country](const QPair &pair) { + return country == pair.first; + } + ); + return it != mCountryCodes.cend() ? static_cast(distance(mCountryCodes.cbegin(), it)) : 0; +} diff --git a/linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.hpp b/linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.hpp similarity index 76% rename from linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.hpp rename to linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.hpp index 5d427277f..7a9b3ae9d 100644 --- a/linphone-desktop/src/components/telephone-numbers/TelephoneNumbers.hpp +++ b/linphone-desktop/src/components/telephone-numbers/TelephoneNumbersModel.hpp @@ -1,5 +1,5 @@ /* - * TelephoneNumbers.hpp + * TelephoneNumbersModel.hpp * Copyright (C) 2017 Belledonne Communications, Grenoble, France * * This program is free software; you can redistribute it and/or @@ -20,18 +20,22 @@ * Author: Ronan Abhamon */ -#ifndef TELEPHONE_NUMBERS_H_ -#define TELEPHONE_NUMBERS_H_ +#ifndef TELEPHONE_NUMBERS_MODEL_H_ +#define TELEPHONE_NUMBERS_MODEL_H_ #include #include // ============================================================================= -class TelephoneNumbers : public QAbstractListModel { +class TelephoneNumbersModel : public QAbstractListModel { + Q_OBJECT; + + Q_PROPERTY(int defaultIndex READ getDefaultIndex CONSTANT); + public: - TelephoneNumbers (QObject *parent = Q_NULLPTR); - ~TelephoneNumbers () = default; + TelephoneNumbersModel (QObject *parent = Q_NULLPTR); + ~TelephoneNumbersModel () = default; int rowCount (const QModelIndex &index = QModelIndex()) const override; @@ -39,7 +43,9 @@ public: QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const override; private: + int getDefaultIndex () const; + static const QList > mCountryCodes; }; -#endif // ifndef TELEPHONE_NUMBERS_H_ +#endif // ifndef TELEPHONE_NUMBERS_MODEL_H_ diff --git a/linphone-desktop/ui/modules/Common/Form/ComboBox.js b/linphone-desktop/ui/modules/Common/Form/ComboBox.js index b0bc3c638..14fdc882a 100644 --- a/linphone-desktop/ui/modules/Common/Form/ComboBox.js +++ b/linphone-desktop/ui/modules/Common/Form/ComboBox.js @@ -34,6 +34,27 @@ function getSelectedEntryIcon () { ) || '' } +function getSelectedEntryText () { + if (comboBox.currentIndex < 0) { + return '' + } + + var text = comboBox.displayText + if (text.length > 0) { + return text + } + + // With a `QAbstractListModel`, `text` is empty. QML bug? + var model = comboBox.model + if (model.data) { + var item = model.data(model.index(comboBox.currentIndex, 0)) + var textRole = comboBox.textRole + return textRole.length > 0 ? item[textRole] : item + } + + return '' +} + function getEntryIcon (item) { var iconRole = comboBox.iconRole if (iconRole == null || iconRole.length === 0) { diff --git a/linphone-desktop/ui/modules/Common/Form/ComboBox.qml b/linphone-desktop/ui/modules/Common/Form/ComboBox.qml index 4a423bad3..db1e2cd02 100644 --- a/linphone-desktop/ui/modules/Common/Form/ComboBox.qml +++ b/linphone-desktop/ui/modules/Common/Form/ComboBox.qml @@ -53,7 +53,7 @@ ComboBox { font.pointSize: ComboBoxStyle.contentItem.text.fontSize rightPadding: comboBox.indicator.width + comboBox.spacing - text: comboBox.displayText + text: Logic.getSelectedEntryText() } } diff --git a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml index af1e0f773..e07c63259 100644 --- a/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml +++ b/linphone-desktop/ui/views/App/Main/Assistant/CreateLinphoneSipAccountWithPhoneNumber.qml @@ -9,55 +9,101 @@ AssistantAbstractView { id: view property alias usernameError: username.error + property alias phoneNumberError: phoneNumber.error + + function setCountryCode (index) { + var model = country.model + assistantModel.countryCode = model.data(model.index(index, 0)).countryCode + } title: qsTr('createLinphoneSipAccountTitle') - Form { + mainAction: requestBlock.execute + mainActionEnabled: phoneNumber.text.length + && username.text.length + && !phoneNumberError.length + && !usernameError.length + && !requestBlock.loading + mainActionLabel: qsTr('confirmAction') + + Column { anchors.fill: parent - dealWithErrors: true - orientation: Qt.Vertical + Form { + dealWithErrors: true + orientation: Qt.Vertical + width: parent.width - FormLine { - FormGroup { - label: qsTr('countryLabel') + FormLine { + FormGroup { + label: qsTr('countryLabel') - ComboBox { - id: country + ComboBox { + id: country + + currentIndex: model.defaultIndex + model: TelephoneNumbersModel {} + textRole: 'countryName' + + onActivated: { + view.setCountryCode(index) + var text = phoneNumber.text + if (text.length > 0) { + assistantModel.phoneNumber = text + } + } + } + } + } + + FormLine { + FormGroup { + label: qsTr('phoneNumberLabel') + + TextField { + id: phoneNumber + + inputMethodHints: Qt.ImhDialableCharactersOnly + + onTextChanged: assistantModel.phoneNumber = text + } + } + } + + FormLine { + FormGroup { + label: qsTr('usernameLabel') + + TextField { + id: username + + onTextChanged: assistantModel.username = text + } + } + } + + FormLine { + FormGroup { + label: qsTr('displayNameLabel') + + TextField { + onTextChanged: assistantModel.displayName = text + } } } } - FormLine { - FormGroup { - label: qsTr('phoneNumberLabel') + RequestBlock { + id: requestBlock - TextField { - id: phoneNumber - } + action: function () { + window.lockView({ + descriptionText: qsTr('quitWarning') + }) + assistantModel.create() } - } - FormLine { - FormGroup { - label: qsTr('usernameLabel') - - TextField { - id: username - - onTextChanged: assistantModel.username = text - } - } - } - - FormLine { - FormGroup { - label: qsTr('displayNameLabel') - - TextField { - onTextChanged: assistantModel.displayName = text - } - } + width: parent.width } } @@ -70,12 +116,19 @@ AssistantAbstractView { configFilename: 'create-linphone-sip-account.rc' + Component.onCompleted: view.setCountryCode(country.model.defaultIndex) + + onPhoneNumberChanged: phoneNumberError = error onUsernameChanged: usernameError = error onCreateStatusChanged: { requestBlock.stop(error) if (!error.length) { - // TODO. + assistant.pushView('ActivateLinphoneSipAccountWithPhoneNumber', { + assistantModel: assistantModel + }) + } else { + window.unlockView() } } } diff --git a/linphone-desktop/ui/views/App/Main/Dialogs/ManageAccounts.qml b/linphone-desktop/ui/views/App/Main/Dialogs/ManageAccounts.qml index 6fc28f21e..d22263668 100644 --- a/linphone-desktop/ui/views/App/Main/Dialogs/ManageAccounts.qml +++ b/linphone-desktop/ui/views/App/Main/Dialogs/ManageAccounts.qml @@ -40,7 +40,7 @@ DialogPlus { ComboBox { currentIndex: Utils.findIndex(OwnPresenceModel.statuses, function (status) { - return status.presenceStatus == OwnPresenceModel.presenceStatus + return status.presenceStatus === OwnPresenceModel.presenceStatus }) model: OwnPresenceModel.statuses