diff --git a/src/api/newaccountmodel.h b/src/api/newaccountmodel.h index 3184e7acb4578d43619077c2020becec1b0c602b..6e1975239bc0411bb789d72111b63c74476dccef 100644 --- a/src/api/newaccountmodel.h +++ b/src/api/newaccountmodel.h @@ -163,6 +163,11 @@ public: const std::string& password = "", const std::string& pin = ""); + /** + * Set an account to the first position + */ + void setTopAccount(const std::string& accountId); + Q_SIGNALS: /** * Connect this signal to know when an invalid account is here diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index 7c6d70774763fd0fee3b87fed39ed346bfe834ce..4eabda7be762c260e7e58de6d0f89378d14e9b65 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -140,11 +140,13 @@ std::vector<std::string> NewAccountModel::getAccountList() const { std::vector<std::string> accountsId; + const QStringList accountIds = ConfigurationManager::instance().getAccountList(); - for(auto const& accountInfo: pimpl_->accounts) { + for (auto const& id : accountIds) { + auto accountInfo = pimpl_->accounts.find(id.toStdString()); // Do not include accounts flagged for removal - if (accountInfo.second.valid) - accountsId.emplace_back(accountInfo.first); + if (accountInfo != pimpl_->accounts.end() && accountInfo->second.valid) + accountsId.emplace_back(id.toStdString()); } return accountsId; @@ -712,6 +714,27 @@ NewAccountModel::createNewAccount(profile::Type type, return accountId.toStdString(); } +void +NewAccountModel::setTopAccount(const std::string& accountId) +{ + bool found = false; + std::string order = {}; + + const QStringList accountIds = ConfigurationManager::instance().getAccountList(); + for (auto& id : accountIds) + { + if (id.toStdString() == accountId) { + found = true; + } else { + order += id.toStdString() + "/"; + } + } + if (found) { + order = accountId + "/" + order; + } + ConfigurationManager::instance().setAccountsOrder(order.c_str()); +} + } // namespace lrc #include "api/moc_newaccountmodel.cpp"