From 1539584d1290bf7a9a26b5c5b58e55ec299df115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Mon, 18 Jun 2018 16:48:28 -0400 Subject: [PATCH] newaccountmodel: add exportOnRing method Change-Id: I849003605c7242c241e258bcd5e11ee9bac3a685 Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> --- src/api/account.h | 25 ++++++++++++++++++++++ src/api/newaccountmodel.h | 45 ++++++++++++++++++++++++++++++++++----- src/callbackshandler.cpp | 11 ++++++++++ src/callbackshandler.h | 16 ++++++++++++++ src/newaccountmodel.cpp | 35 +++++++++++++++++++++++++++++- 5 files changed, 126 insertions(+), 6 deletions(-) diff --git a/src/api/account.h b/src/api/account.h index d45b2684..a3229702 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 ad3437f6..0e8f6f96 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 1814fca4..817cc15f 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 06cf3b67..534468e1 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 7465890b..cccc852b 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) { -- GitLab