Skip to content
Snippets Groups Projects
Commit 6765592b authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

accountmodel: avoid invalid pointer, just update current structure

Change-Id: I237dfce4089ec97f91b8fa4b7b188a6f1f339883
parent 1a48e70a
Branches
No related tags found
No related merge requests found
...@@ -103,6 +103,12 @@ public: ...@@ -103,6 +103,12 @@ public:
*/ */
void updateAccounts(); void updateAccounts();
/**
* Update accountInfo with details from daemon
* @param account account to update
*/
void updateAccountDetails(account::Info& account);
public Q_SLOTS: public Q_SLOTS:
/** /**
...@@ -438,6 +444,32 @@ NewAccountModelPimpl::updateAccounts() ...@@ -438,6 +444,32 @@ NewAccountModelPimpl::updateAccounts()
} }
} }
void
NewAccountModelPimpl::updateAccountDetails(account::Info& accountInfo)
{
// Fill account::Info struct with details from daemon
MapStringString details = ConfigurationManager::instance().getAccountDetails(accountInfo.id);
accountInfo.fromDetails(details);
// Fill account::Info::confProperties credentials
VectorMapStringString credGet = ConfigurationManager::instance().getCredentials(accountInfo.id);
VectorMapStringString credToStore;
for (auto const &i : credGet.toStdVector()) {
MapStringString credMap;
for (auto const &j : i.toStdMap()) {
credMap[j.first] = j.second;
}
credToStore.push_back(credMap);
}
accountInfo.confProperties.credentials.swap(credToStore);
MapStringString volatileDetails = ConfigurationManager::instance().getVolatileAccountDetails(accountInfo.id);
QString daemonStatus = volatileDetails[DRing::Account::ConfProperties::Registration::STATUS];
accountInfo.status = lrc::api::account::to_status(daemonStatus);
}
void void
NewAccountModelPimpl::slotAccountStatusChanged(const QString& accountID, const api::account::Status status) NewAccountModelPimpl::slotAccountStatusChanged(const QString& accountID, const api::account::Status status)
{ {
...@@ -460,8 +492,8 @@ NewAccountModelPimpl::slotAccountStatusChanged(const QString& accountID, const a ...@@ -460,8 +492,8 @@ NewAccountModelPimpl::slotAccountStatusChanged(const QString& accountID, const a
// Detect when a new account is generated (keys are ready). During // Detect when a new account is generated (keys are ready). During
// the generation, a Ring account got the "INITIALIZING" status. // the generation, a Ring account got the "INITIALIZING" status.
// When keys are generated, the status will change. // When keys are generated, the status will change.
accounts.erase(accountID); // The account is already added and initialized. Just update details from daemon
addToAccounts(accountID); updateAccountDetails(accountInfo);
emit linked.accountAdded(accountID); emit linked.accountAdded(accountID);
} else if (!accountInfo.profileInfo.uri.isEmpty()) { } else if (!accountInfo.profileInfo.uri.isEmpty()) {
accountInfo.status = status; accountInfo.status = status;
...@@ -642,23 +674,7 @@ NewAccountModelPimpl::addToAccounts(const QString& accountId, ...@@ -642,23 +674,7 @@ NewAccountModelPimpl::addToAccounts(const QString& accountId,
account::Info& newAccInfo = (it.first)->second.first; account::Info& newAccInfo = (it.first)->second.first;
newAccInfo.id = accountId; newAccInfo.id = accountId;
newAccInfo.profileInfo.avatar = authority::storage::getAccountAvatar(accountId); newAccInfo.profileInfo.avatar = authority::storage::getAccountAvatar(accountId);
updateAccountDetails(newAccInfo);
// Fill account::Info struct with details from daemon
MapStringString details = ConfigurationManager::instance().getAccountDetails(accountId);
newAccInfo.fromDetails(details);
// Fill account::Info::confProperties credentials
VectorMapStringString credGet = ConfigurationManager::instance().getCredentials(accountId);
VectorMapStringString credToStore;
for (auto const &i : credGet.toStdVector()) {
MapStringString credMap;
for (auto const &j : i.toStdMap()) {
credMap[j.first] = j.second;
}
credToStore.push_back(credMap);
}
newAccInfo.confProperties.credentials.swap(credToStore);
// Init models for this account // Init models for this account
newAccInfo.accountModel = &linked; newAccInfo.accountModel = &linked;
...@@ -669,9 +685,6 @@ NewAccountModelPimpl::addToAccounts(const QString& accountId, ...@@ -669,9 +685,6 @@ NewAccountModelPimpl::addToAccounts(const QString& accountId,
newAccInfo.deviceModel = std::make_unique<NewDeviceModel>(newAccInfo, callbacksHandler); newAccInfo.deviceModel = std::make_unique<NewDeviceModel>(newAccInfo, callbacksHandler);
newAccInfo.codecModel = std::make_unique<NewCodecModel>(newAccInfo, callbacksHandler); newAccInfo.codecModel = std::make_unique<NewCodecModel>(newAccInfo, callbacksHandler);
MapStringString volatileDetails = ConfigurationManager::instance().getVolatileAccountDetails(accountId);
auto daemonStatus = volatileDetails[DRing::Account::ConfProperties::Registration::STATUS];
newAccInfo.status = lrc::api::account::to_status(daemonStatus);
} }
void void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment