From 77b9268cec8f6dddf99afe842cc6864107bfa51a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Wed, 27 Jun 2018 16:26:06 -0400 Subject: [PATCH] newaccountmodel: add the ability to create new accounts Change-Id: I55f2f3090bb414d46105cb18b2150044c736d881 Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> --- src/api/newaccountmodel.h | 23 ++++++++++++++++++++++- src/newaccountmodel.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index 351d90c6..3184e7ac 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 9bdb39c1..7c6d7077 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" -- GitLab