Skip to content
Snippets Groups Projects
Commit 1539584d authored by Sébastien Blin's avatar Sébastien Blin
Browse files

newaccountmodel: add exportOnRing method


Change-Id: I849003605c7242c241e258bcd5e11ee9bac3a685
Reviewed-by: default avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 5f946595
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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_;
};
......
......@@ -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
......@@ -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;
};
......
......@@ -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)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment