diff --git a/src/api/account.h b/src/api/account.h index d45b26849a24cf87b6cff3eea77cc2187c6f1ee5..a32297020163dee68b9267bf2a9eaf2c6540f765 100644 --- a/src/api/account.h +++ b/src/api/account.h @@ -172,6 +172,31 @@ struct ConfProperties_t { MapStringString toDetails() const; }; +// Possible account export status +enum class ExportOnRingStatus { + SUCCESS = 0, + WRONG_PASSWORD = 1 , + NETWORK_ERROR = 2, + INVALID +}; + +enum class RegisterNameStatus { + SUCCESS = 0, + WRONG_PASSWORD = 1, + INVALID_NAME = 2, + ALREADY_TAKEN = 3, + NETWORK_ERROR = 4, + INVALID +}; + +enum class LookupStatus { + SUCCESS = 0, + INVALID_NAME = 1, + NOT_FOUND = 2, + ERROR = 3, + INVALID +}; + struct Info { bool freeable = false; diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index ad3437f6d45e0bd46ef1e48303e7101c47ed68ab..0e8f6f96a12a2d2982eb6e9b5ebcf6c11b5f1e62 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -31,6 +31,7 @@ // Lrc #include "typedefs.h" +#include "api/account.h" namespace lrc { @@ -45,11 +46,6 @@ namespace api class Lrc; class BehaviorController; -namespace account { - struct ConfProperties_t; - struct Info; -} - /** * @brief Class that manages account information. */ @@ -99,6 +95,13 @@ public: * @return if the file is exported with success */ bool exportToFile(const std::string& accountId, const std::string& path) const; + /** + * Call exportOnRing from the daemon + * @param accountId + * @param password + * @return if the export is initialized + */ + bool exportOnRing(const std::string& accountId, const std::string& password) const; /** * Call removeAccount from the daemon * @param accountId to remove @@ -128,6 +131,14 @@ public: * @throws out_of_range exception if account is not found */ void setAvatar(const std::string& accountId, const std::string& avatar); + /** + * Try to register a name + * @param accountId + * @param password + * @param username + * @return string like bootstrap1:port1;bootstrap2:port2;... + */ + bool registerName(const std::string& accountId, const std::string& password, const std::string& username); Q_SIGNALS: /** @@ -151,6 +162,30 @@ Q_SIGNALS: */ void profileUpdated(const std::string& accountID); + /** + * Connect this signal to know when an account is exported on the DHT + * @param accountID + * @param status + * @param pin + */ + void exportOnRingEnded(const std::string& accountID, account::ExportOnRingStatus status, const std::string& pin); + + /** + * Name registration has ended + * @param accountId + * @param status + * @param name + */ + void nameRegistrationEnded(const std::string& accountId, account::RegisterNameStatus status, const std::string& name); + + /** + * Name registration has been found + * @param accountId + * @param status + * @param name + */ + void registeredNameFound(const std::string& accountId, account::LookupStatus status, const std::string& address, const std::string& name); + private: std::unique_ptr<NewAccountModelPimpl> pimpl_; }; diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 1814fca47b0fc176bcf6b8d86ce8dc1c46055df0..817cc15f90f4b309e97205ddff52e112555031c7 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -133,6 +133,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent) &ConfigurationManagerInterface::deviceRevocationEnded, this, &CallbacksHandler::slotDeviceRevokationEnded); + + connect(&ConfigurationManager::instance(), + &ConfigurationManagerInterface::exportOnRingEnded, + this, + &CallbacksHandler::slotExportOnRingEnded); } CallbacksHandler::~CallbacksHandler() @@ -370,4 +375,10 @@ CallbacksHandler::slotDeviceRevokationEnded(const QString& accountId, emit deviceRevocationEnded(accountId.toStdString(), deviceId.toStdString(), status); } +void +CallbacksHandler::slotExportOnRingEnded(const QString& accountId, int status, const QString& pin) +{ + emit exportOnRingEnded(accountId.toStdString(), status, pin.toStdString()); +} + } // namespace lrc diff --git a/src/callbackshandler.h b/src/callbackshandler.h index 06cf3b673ee5956c1f65c74d057ddefc82faaed4..534468e1112beaeb5a07f83d0bcd428b0455dedb 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -210,6 +210,14 @@ Q_SIGNALS: const std::string& deviceId, const int status); + /** + * Emit exportOnRingEnded + * @param accountId + * @param status SUCCESS = 0, WRONG_PASSWORD = 1, NETWORK_ERROR = 2 + * @param pin + */ + void exportOnRingEnded(const std::string& accountId, int status, const std::string& pin); + private Q_SLOTS: /** * Emit newAccountMessage @@ -355,6 +363,14 @@ private Q_SLOTS: const QString& deviceId, const int status); + /** + * Emit exportOnRingEnded + * @param accountId + * @param status SUCCESS = 0, WRONG_PASSWORD = 1, NETWORK_ERROR = 2 + * @param pin + */ + void slotExportOnRingEnded(const QString& accountId, int status, const QString& pin); + private: const api::Lrc& parent; }; diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index 7465890b248a55fb3730fb75d8db78d4ab7dd71d..cccc852ba8f88c1221761a2f482fdbdecf78756e 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -28,7 +28,6 @@ #include "api/conversationmodel.h" #include "api/newcodecmodel.h" #include "api/newdevicemodel.h" -#include "api/account.h" #include "api/behaviorcontroller.h" #include "authority/databasehelper.h" #include "callbackshandler.h" @@ -86,6 +85,13 @@ public Q_SLOTS: * @param status */ void slotAccountStatusChanged(const std::string& accountID, const api::account::Status status); + /** + * Emit exportOnRingEnded. + * @param accountId + * @param status + * @param pin + */ + void slotExportOnRingEnded(const std::string& accountID, int status, const std::string& pin); /** * @param accountId * @param details @@ -191,6 +197,12 @@ NewAccountModel::exportToFile(const std::string& accountId, const std::string& p return ConfigurationManager::instance().exportToFile(accountId.c_str(), path.c_str()); } +bool +NewAccountModel::exportOnRing(const std::string& accountId, const std::string& password) const +{ + return ConfigurationManager::instance().exportOnRing(accountId.c_str(), password.c_str()); +} + void NewAccountModel::removeAccount(const std::string& accountId) const { @@ -248,6 +260,7 @@ NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked, connect(&callbacksHandler, &CallbacksHandler::accountStatusChanged, this, &NewAccountModelPimpl::slotAccountStatusChanged); connect(&callbacksHandler, &CallbacksHandler::accountDetailsChanged, this, &NewAccountModelPimpl::slotAccountDetailsChanged); + connect(&callbacksHandler, &CallbacksHandler::exportOnRingEnded, this, &NewAccountModelPimpl::slotExportOnRingEnded); // NOTE: because we still use the legacy LRC for configuration, we are still using old signals connect(&AccountModel::instance(), &AccountModel::accountRemoved, this, &NewAccountModelPimpl::slotAccountRemoved); @@ -295,6 +308,26 @@ NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, co emit linked.accountStatusChanged(accountId); } +void +NewAccountModelPimpl::slotExportOnRingEnded(const std::string& accountID, int status, const std::string& pin) +{ + account::ExportOnRingStatus convertedStatus = account::ExportOnRingStatus::INVALID; + switch (status) { + case 0: + convertedStatus = account::ExportOnRingStatus::SUCCESS; + break; + case 1: + convertedStatus = account::ExportOnRingStatus::WRONG_PASSWORD; + break; + case 2: + convertedStatus = account::ExportOnRingStatus::NETWORK_ERROR; + break; + default: + break; + } + emit linked.exportOnRingEnded(accountID, convertedStatus, pin); +} + void NewAccountModelPimpl::addToAccounts(const std::string& accountId) {