Skip to content

Commit

Permalink
libdenaro - complete accountsettingsdialogcontroller
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseBritto committed May 21, 2024
1 parent 750bd80 commit 7aea329
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
36 changes: 36 additions & 0 deletions libdenaro/include/controllers/accountsettingsdialogcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@ namespace Nickvision::Money::Shared::Controllers
{
public:
AccountSettingsDialogController(const std::shared_ptr<Models::Account>& account);
/**
* @brief Sets the name of the account.
* @param name The new name of the account
* @return True if the name was set, else false (example, the name was empty)
*/
bool setName(const std::string& name);
/**
* @brief Sets a password for the account.
* @param password The new password
*/
bool setPassword(const std::string& password);
/**
* @brief Sets the account type of the account.
* @param accountType The new account type of the account
*/
void setAccountType(Models::AccountType accountType);
/**
* @brief Sets the default transaction type of the account.
* @param defaultTransactionType The new default transaction type of the account
*/
void setDefaultTransactionType(Models::TransactionType defaultTransactionType);
/**
* @brief Turns off the custom currency for the account
*/
void setCustomCurrencyOff();
/**
* @brief Sets the custom currency of the account.
* @param symbol The symbol of the new custom currency
* @param code The code of the new custom currency
* @param decimalSeparator The decimal separator of the new custom currency
* @param groupSeparator The group separator of the new custom currency
* @param decimalDigits The decimal digits of the new custom currency
* @param amountStyle The amount style of the new custom currency
* @return CurrencyCheckStatus
*/
Models::CurrencyCheckStatus setCustomCurrency(const std::string& symbol, const std::string& code, char decimalSeparator, char groupSeparator, int decimalDigits, Models::AmountStyle amountStyle);

private:
std::shared_ptr<Models::Account> m_account;
Expand Down
57 changes: 57 additions & 0 deletions libdenaro/src/controllers/accountsettingsdialogcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,61 @@ namespace Nickvision::Money::Shared::Controllers
{

}

bool AccountSettingsDialogController::setName(const std::string& name)
{
if(name.empty())
{
return false;
}
AccountMetadata metadata{ m_account->getMetadata() };
metadata.setName(name);
m_account->setMetadata(metadata);
return true;
}

bool AccountSettingsDialogController::setPassword(const std::string& password)
{
return m_account->changePassword(password);
}

void AccountSettingsDialogController::setAccountType(Models::AccountType accountType)
{
AccountMetadata metadata{ m_account->getMetadata() };
metadata.setType(accountType);
m_account->setMetadata(metadata);
}

void AccountSettingsDialogController::setDefaultTransactionType(Models::TransactionType defaultTransactionType)
{
AccountMetadata metadata{ m_account->getMetadata() };
metadata.setDefaultTransactionType(defaultTransactionType);
m_account->setMetadata(metadata);
}

void AccountSettingsDialogController::setCustomCurrencyOff()
{
AccountMetadata metadata{ m_account->getMetadata() };
metadata.setUseCustomCurrency(false);
metadata.setCustomCurrency({});
m_account->setMetadata(metadata);
}

Models::CurrencyCheckStatus AccountSettingsDialogController::setCustomCurrency(const std::string& symbol, const std::string& code, char decimalSeparator, char groupSeparator, int decimalDigits, Models::AmountStyle amountStyle)
{
Currency currency{ symbol, code };
currency.setDecimalSeparator(decimalSeparator);
currency.setGroupSeparator(groupSeparator);
currency.setDecimalDigits(decimalDigits);
currency.setAmountStyle(amountStyle);
CurrencyCheckStatus status{ currency.validate() };
if(status == CurrencyCheckStatus::Valid)
{
AccountMetadata metadata{ m_account->getMetadata() };
metadata.setUseCustomCurrency(true);
metadata.setCustomCurrency(currency);
m_account->setMetadata(metadata);
}
return status;
}
}

0 comments on commit 7aea329

Please sign in to comment.