diff --git a/Linphone/model/account/AccountManager.cpp b/Linphone/model/account/AccountManager.cpp index 246943d5..3895f6c7 100644 --- a/Linphone/model/account/AccountManager.cpp +++ b/Linphone/model/account/AccountManager.cpp @@ -124,14 +124,21 @@ bool AccountManager::login(QString username, mAccountModel = Utils::makeQObject_ptr(account); mAccountModel->setSelf(mAccountModel); connect(mAccountModel.get(), &AccountModel::registrationStateChanged, this, - [this, authInfo](const std::shared_ptr &account, linphone::RegistrationState state, - const std::string &message) { - if (account == mAccountModel->getAccount() && state == linphone::RegistrationState::Failed) { - auto core = CoreModel::getInstance()->getCore(); - core->removeAuthInfo(authInfo); - core->removeAccount(account); + [this, authInfo, core](const std::shared_ptr &account, linphone::RegistrationState state, + const std::string &message) { + if (mAccountModel && account == mAccountModel->getAccount()) { + if (state == linphone::RegistrationState::Failed) { + core->removeAuthInfo(authInfo); + core->removeAccount(account); + emit mAccountModel->removeListener(); + mAccountModel = nullptr; + } else if (state == linphone::RegistrationState::Ok) { + core->setDefaultAccount(account); + emit mAccountModel->removeListener(); + mAccountModel = nullptr; + } } - emit onRegistrationStateChanged(account, state, message); + emit registrationStateChanged(state); }); auto status = core->addAccount(account); if (status == -1) { @@ -314,24 +321,3 @@ void AccountManager::linkNewAccountUsingCode(const QString &code, mAccountManagerServicesModel->linkPhoneNumberToAccountUsingCode(sipIdentityAddress, Utils::appStringToCoreString(code)); } - -void AccountManager::onRegistrationStateChanged(const std::shared_ptr &account, - linphone::RegistrationState state, - const std::string &message) { - auto core = CoreModel::getInstance()->getCore(); - switch (state) { - case linphone::RegistrationState::Failed: - core->removeAccount(account); - emit mAccountModel->removeListener(); - mAccountModel = nullptr; - break; - case linphone::RegistrationState::Ok: - core->setDefaultAccount(account); - emit mAccountModel->removeListener(); - mAccountModel = nullptr; - break; - default: { - } - } - emit registrationStateChanged(state); -} diff --git a/Linphone/model/account/AccountManager.hpp b/Linphone/model/account/AccountManager.hpp index 741318f9..41209f33 100644 --- a/Linphone/model/account/AccountManager.hpp +++ b/Linphone/model/account/AccountManager.hpp @@ -54,10 +54,6 @@ public: void linkNewAccountUsingCode(const QString &code, RegisterType registerType, const QString &sipAddress); - void onRegistrationStateChanged(const std::shared_ptr &account, - linphone::RegistrationState state, - const std::string &message); - signals: void registrationStateChanged(linphone::RegistrationState state); void newAccountCreationSucceed(QString sipAddress, RegisterType registerType, const QString ®isterAddress);