diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index 351d90c67522932316f76f71abf045c88838bff6..3184e7acb4578d43619077c2020becec1b0c602b 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -143,11 +143,32 @@ public: * @param accountId * @param password * @param username - * @return string like bootstrap1:port1;bootstrap2:port2;... + * @return if operation started */ bool registerName(const std::string& accountId, const std::string& password, const std::string& username); + /** + * Create a new Ring or SIP account + * @param type determine if the new account will be a Ring account or a SIP one + * @param displayName + * @param username + * @param archivePath + * @param password of the archive (unused for SIP) + * @param pin of the archive (unused 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 = ""); + Q_SIGNALS: + /** + * Connect this signal to know when an invalid account is here + * @param accountID + */ + void invalidAccountDetected(const std::string& accountID); /** * Connect this signal to know when the status of an account has changed. * @param accountID diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index 9bdb39c1f68a14d4cdb4574566dd5d9e9763c5ae..7c6d70774763fd0fee3b87fed39ed346bfe834ce 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -169,7 +169,11 @@ NewAccountModel::setAccountConfig(const std::string& accountId, details[ConfProperties::ALIAS] = toQString(accountInfo.profileInfo.alias); details[ConfProperties::DISPLAYNAME] = toQString(accountInfo.profileInfo.alias); details[ConfProperties::TYPE] = (accountInfo.profileInfo.type == profile::Type::RING) ? QString(ProtocolNames::RING) : QString(ProtocolNames::SIP); - details[ConfProperties::USERNAME] = toQString(accountInfo.profileInfo.uri).prepend((accountInfo.profileInfo.type == profile::Type::RING) ? "ring:" : ""); + if (accountInfo.profileInfo.type == profile::Type::RING) { + details[ConfProperties::USERNAME] = toQString(accountInfo.profileInfo.uri).prepend((accountInfo.profileInfo.type == profile::Type::RING) ? "ring:" : ""); + } else { + details[ConfProperties::USERNAME] = toQString(confProperties.username); + } configurationManager.setAccountDetails(QString::fromStdString(accountId), details); } @@ -495,6 +499,7 @@ account::Info::fromDetails(const MapStringString& details) confProperties.activeCallLimit = toInt(details[ConfProperties::ACTIVE_CALL_LIMIT]); confProperties.hostname = toStdString(details[ConfProperties::HOSTNAME]); profileInfo.uri = (profileInfo.type == profile::Type::RING and details[ConfProperties::USERNAME].contains("ring:")) ? details[ConfProperties::USERNAME].toStdString().substr(std::string("ring:").size()) : details[ConfProperties::USERNAME].toStdString(); + confProperties.username = toStdString(details[ConfProperties::USERNAME]); confProperties.routeset = toStdString(details[ConfProperties::ROUTE]); confProperties.password = toStdString(details[ConfProperties::PASSWORD]); confProperties.realm = toStdString(details[ConfProperties::REALM]); @@ -684,6 +689,29 @@ account::ConfProperties_t::toDetails() const return details; } +std::string +NewAccountModel::createNewAccount(profile::Type type, + const std::string& displayName, + const std::string& archivePath, + const std::string& password, + const std::string& pin) +{ + + MapStringString details = type == profile::Type::SIP? + ConfigurationManager::instance().getAccountTemplate("SIP") : + ConfigurationManager::instance().getAccountTemplate("RING"); + using namespace DRing::Account; + details[ConfProperties::TYPE] = type == profile::Type::SIP? "SIP" : "RING"; + details[ConfProperties::DISPLAYNAME] = displayName.c_str(); + details[ConfProperties::ALIAS] = displayName.c_str(); + details[ConfProperties::UPNP_ENABLED] = "true"; + details[ConfProperties::ARCHIVE_PASSWORD] = password.c_str(); + details[ConfProperties::ARCHIVE_PIN] = pin.c_str(); + details[ConfProperties::ARCHIVE_PATH] = archivePath.c_str(); + QString accountId = ConfigurationManager::instance().addAccount(details); + return accountId.toStdString(); +} + } // namespace lrc #include "api/moc_newaccountmodel.cpp"