diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index 447e93d014141b7f707383d1e96fb06f8aed3881..c784f4fab6fad97b84f56e5efd8e4b418786beeb 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -1,7 +1,8 @@ /**************************************************************************** - * Copyright (C) 2017-2018 Savoir-faire Linux * + * Copyright (C) 2017-2018 Savoir-faire Linux * * Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> * * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> * + * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * @@ -155,13 +156,15 @@ public: * @param archivePath * @param password of the archive (unused for SIP) * @param pin of the archive (unused for SIP) + * @param uri of the account (for SIP) * @return the created account */ static std::string createNewAccount(profile::Type type, const std::string& displayName = "", const std::string& archivePath = "", const std::string& password = "", - const std::string& pin = ""); + const std::string& pin = "", + const std::string& uri = ""); /** * Set an account to the first position diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index ff20a588ccb4b7df3a6f5f8a52162f93eee90fd1..1266dbc80a45b27e3f9e714130a8db2f086492b9 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -2,6 +2,7 @@ * Copyright (C) 2017-2018 Savoir-faire Linux * * Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> * * Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> * + * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * @@ -199,7 +200,14 @@ NewAccountModel::setAccountConfig(const std::string& accountId, details[ConfProperties::TYPE] = (accountInfo.profileInfo.type == profile::Type::RING) ? QString(ProtocolNames::RING) : QString(ProtocolNames::SIP); if (accountInfo.profileInfo.type == profile::Type::RING) { details[ConfProperties::USERNAME] = toQString(accountInfo.profileInfo.uri).prepend((accountInfo.profileInfo.type == profile::Type::RING) ? "ring:" : ""); - } else { + } else if (accountInfo.profileInfo.type == profile::Type::SIP) { + MapStringString credentials; + credentials[ConfProperties::USERNAME] = toQString(confProperties.username); + credentials[ConfProperties::PASSWORD] = toQString(confProperties.password); + credentials[ConfProperties::REALM] = confProperties.realm.empty()? QString("*") : toQString(confProperties.realm); + QVector<MapStringString> credentialsVec; + credentialsVec.append(credentials); + ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec); details[ConfProperties::USERNAME] = toQString(confProperties.username); } configurationManager.setAccountDetails(QString::fromStdString(accountId), details); @@ -373,7 +381,11 @@ NewAccountModelPimpl::updateAccounts() if (accountInfo == accounts.end()) { qDebug("detected new account %s", id.toStdString().c_str()); addToAccounts(id.toStdString()); - if (accountInfo->second.profileInfo.type == profile::Type::SIP) { + auto updatedAccountInfo = accounts.find(id.toStdString()); + if (updatedAccountInfo == accounts.end()) { + return; + } + if (updatedAccountInfo->second.profileInfo.type == profile::Type::SIP) { // NOTE: At this point, a SIP account is ready, but not a Ring // account. Indeed, the keys are not generated at this point. // See slotAccountStatusChanged for more details. @@ -423,20 +435,6 @@ NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, co } accountInfo->second.fromDetails(convertMap(details)); - - // Refresh credentials for SIP accounts - if (accountInfo->second.profileInfo.type == profile::Type::SIP) { - auto& confProperties = accountInfo->second.confProperties; - MapStringString credentials; - using namespace DRing::Account; - credentials[ConfProperties::USERNAME] = toQString(confProperties.username); - credentials[ConfProperties::PASSWORD] = toQString(confProperties.password); - credentials[ConfProperties::REALM] = confProperties.realm.empty()? QString("*") : toQString(confProperties.realm); - QVector<MapStringString> credentialsVec; - credentialsVec.append(credentials); - ConfigurationManager::instance().setCredentials(accountId.c_str(), credentialsVec); - } - emit linked.accountStatusChanged(accountId); } @@ -542,14 +540,16 @@ NewAccountModelPimpl::addToAccounts(const std::string& accountId) std::string accountType = newAcc.profileInfo.type == profile::Type::RING ? DRing::Account::ProtocolNames::RING : DRing::Account::ProtocolNames::SIP; - auto accountProfileId = authority::database::getOrInsertProfile(database, + if (accountType == DRing::Account::ProtocolNames::SIP || !newAcc.profileInfo.uri.empty()) { + auto accountProfileId = authority::database::getOrInsertProfile(database, newAcc.profileInfo.uri, newAcc.profileInfo.alias, "", accountType); - // Retrieve avatar from database - newAcc.profileInfo.avatar = authority::database::getAvatarForProfileId(database, accountProfileId); + // Retrieve avatar from database + newAcc.profileInfo.avatar = authority::database::getAvatarForProfileId(database, accountProfileId); + } // Init models for this account newAcc.callModel = std::make_unique<NewCallModel>(newAcc, callbacksHandler); @@ -811,7 +811,8 @@ NewAccountModel::createNewAccount(profile::Type type, const std::string& displayName, const std::string& archivePath, const std::string& password, - const std::string& pin) + const std::string& pin, + const std::string& uri) { MapStringString details = type == profile::Type::SIP? @@ -825,6 +826,9 @@ NewAccountModel::createNewAccount(profile::Type type, details[ConfProperties::ARCHIVE_PASSWORD] = password.c_str(); details[ConfProperties::ARCHIVE_PIN] = pin.c_str(); details[ConfProperties::ARCHIVE_PATH] = archivePath.c_str(); + if (type == profile::Type::SIP) { + details[ConfProperties::USERNAME] = uri.c_str(); + } QString accountId = ConfigurationManager::instance().addAccount(details); return accountId.toStdString(); }