From 28fd0dc30ef77193d2f89e600476c154b632fb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Sun, 23 Dec 2018 21:42:37 -0500 Subject: [PATCH] newaccountmodel: save registered name when necessary Change-Id: I9292f1a9b1325f9da73c7f40453f0d7c6b96c6bb Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com> --- src/newaccountmodel.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index cdf34bcc..360742b2 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -49,7 +49,7 @@ // Dbus #include "dbus/configurationmanager.h" -#include <iostream> +#include <atomic> namespace lrc { @@ -78,6 +78,8 @@ public: std::mutex m_mutex_account; std::mutex m_mutex_account_removal; std::condition_variable m_condVar_account_removal; + std::atomic_bool username_changed; + std::string new_username; /** * Add the profile information from an account to the db then add it to accounts. @@ -336,6 +338,7 @@ NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked, , behaviorController(behaviorController) , callbacksHandler(callbacksHandler) , database(database) +, username_changed(false) { const QStringList accountIds = ConfigurationManager::instance().getAccountList(); @@ -437,8 +440,12 @@ NewAccountModelPimpl::slotAccountDetailsChanged(const std::string& accountId, co if (accountInfo == accounts.end()) { throw std::out_of_range("NewAccountModelPimpl::slotAccountDetailsChanged, can't find " + accountId); } - accountInfo->second.fromDetails(convertMap(details)); + if (username_changed) { + username_changed = false; + accountInfo->second.registeredName = new_username; + emit linked.profileUpdated(accountId); + } emit linked.accountStatusChanged(accountId); } @@ -473,9 +480,11 @@ NewAccountModelPimpl::slotNameRegistrationEnded(const std::string& accountId, in auto accountInfo = accounts.find(accountId); if (accountInfo != accounts.end() && accountInfo->second.registeredName.empty()) { auto conf = linked.getAccountConfig(accountId); + username_changed = true; + new_username = name; linked.setAccountConfig(accountId, conf); - break; } + break; } case 1: convertedStatus = account::RegisterNameStatus::WRONG_PASSWORD; -- GitLab