Skip to content

Commit

Permalink
V2022.11.0-beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Nov 12, 2022
1 parent 0bca051 commit ea82c2d
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 131 deletions.
2 changes: 1 addition & 1 deletion org.nickvision.money.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{
"type": "git",
"url": "https://github.com/nlogozzo/NickvisionMoney.git",
"tag": "2022.11.0-beta3"
"tag": "2022.11.0-beta4"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion org.nickvision.money.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<binary>org.nickvision.money</binary>
</provides>
<releases>
<release version="2022.11.0-beta3" date="2022-11-06">
<release version="2022.11.0-beta4" date="2022-11-12">
<description>
<p>- Introducing Groups: Add groups to an account and associate transactions with groups for a more precise finance management system</p>
<p>- Money will automatically obtain the user's currency symbol and format from their locale</p>
Expand Down
4 changes: 2 additions & 2 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ msgstr "Répéter à intervalle"

#: src/ui/views/transactiondialog.cpp:73 src/ui/views/transactiondialog.cpp:112
#, c-format
msgid "Amount (%s)"
msgstr "Montant (%s)"
msgid "Amount"
msgstr "Montant"

#: src/ui/views/transactiondialog.cpp:122
msgid "Amount (Empty)"
Expand Down
4 changes: 2 additions & 2 deletions po/hi.po
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ msgstr "दोहराई का समय अंतराल"

#: src/ui/views/transactiondialog.cpp:72 src/ui/views/transactiondialog.cpp:111
#, c-format
msgid "Amount (%s)"
msgstr "धनराशि (%s)"
msgid "Amount"
msgstr "धनराशि"

#: src/ui/views/transactiondialog.cpp:121
msgid "Amount (Empty)"
Expand Down
4 changes: 2 additions & 2 deletions po/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ msgstr "Frequenza"

#: src/ui/views/transactiondialog.cpp:72 src/ui/views/transactiondialog.cpp:111
#, c-format
msgid "Amount (%s)"
msgstr "Ammontare (%s)"
msgid "Amount"
msgstr "Ammontare"

#: src/ui/views/transactiondialog.cpp:121
msgid "Amount (Empty)"
Expand Down
4 changes: 2 additions & 2 deletions po/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ msgstr "Herhalen"

#: src/ui/views/transactiondialog.cpp:72 src/ui/views/transactiondialog.cpp:111
#, c-format
msgid "Amount (%s)"
msgstr "Bedrag (%s)"
msgid "Amount"
msgstr "Bedrag"

#: src/ui/views/transactiondialog.cpp:121
msgid "Amount (Empty)"
Expand Down
4 changes: 2 additions & 2 deletions po/pl.po
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ msgstr "Interwał powtórzeń"

#: src/ui/views/transactiondialog.cpp:73 src/ui/views/transactiondialog.cpp:112
#, c-format
msgid "Amount (%s)"
msgstr "Kwota (%s)"
msgid "Amount"
msgstr "Kwota"

#: src/ui/views/transactiondialog.cpp:122
msgid "Amount (Empty)"
Expand Down
4 changes: 2 additions & 2 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ msgstr "Повторять с интервалом"

#: src/ui/views/transactiondialog.cpp:73 src/ui/views/transactiondialog.cpp:112
#, c-format
msgid "Amount (%s)"
msgstr "Сумма (%s)"
msgid "Amount"
msgstr "Сумма"

#: src/ui/views/transactiondialog.cpp:122
msgid "Amount (Empty)"
Expand Down
51 changes: 10 additions & 41 deletions src/controllers/accountviewcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "accountviewcontroller.hpp"
#include <sstream>
#include "../helpers/moneyhelpers.hpp"
#include "../helpers/stringhelpers.hpp"
#include "../helpers/translation.hpp"

using namespace NickvisionMoney::Controllers;
using namespace NickvisionMoney::Helpers;
using namespace NickvisionMoney::Models;

AccountViewController::AccountViewController(const std::string& path, const std::string& currencySymbol, bool displayCurrencySymbolOnRight, const std::function<void(const std::string& message)>& sendToastCallback) : m_currencySymbol{ currencySymbol }, m_displayCurrencySymbolOnRight{ displayCurrencySymbolOnRight }, m_account{ path }, m_sendToastCallback{ sendToastCallback }
AccountViewController::AccountViewController(const std::string& path, const std::locale& locale, const std::function<void(const std::string& message)>& sendToastCallback) : m_locale{ locale }, m_account{ path }, m_sendToastCallback{ sendToastCallback }
{

}
Expand All @@ -17,56 +17,24 @@ const std::string& AccountViewController::getAccountPath() const
return m_account.getPath();
}

const std::string& AccountViewController::getCurrencySymbol() const
const std::locale& AccountViewController::getLocale() const
{
return m_currencySymbol;
}

bool AccountViewController::getDisplayCurrencySymbolOnRight() const
{
return m_displayCurrencySymbolOnRight;
return m_locale;
}

std::string AccountViewController::getAccountTotalString() const
{
std::stringstream builder;
if(m_displayCurrencySymbolOnRight)
{
builder << m_account.getTotal() << m_currencySymbol;
}
else
{
builder << m_currencySymbol << m_account.getTotal();
}
return builder.str();
return MoneyHelpers::boostMoneyToLocaleString(m_account.getTotal(), m_locale);
}

std::string AccountViewController::getAccountIncomeString() const
{
std::stringstream builder;
if(m_displayCurrencySymbolOnRight)
{
builder << m_account.getIncome() << m_currencySymbol;
}
else
{
builder << m_currencySymbol << m_account.getIncome();
}
return builder.str();
return MoneyHelpers::boostMoneyToLocaleString(m_account.getIncome(), m_locale);
}

std::string AccountViewController::getAccountExpenseString() const
{
std::stringstream builder;
if(m_displayCurrencySymbolOnRight)
{
builder << m_account.getExpense() << m_currencySymbol;
}
else
{
builder << m_currencySymbol << m_account.getExpense();
}
return builder.str();
return MoneyHelpers::boostMoneyToLocaleString(m_account.getExpense(), m_locale);
}

const std::map<unsigned int, Group>& AccountViewController::getGroups() const
Expand Down Expand Up @@ -158,10 +126,11 @@ void AccountViewController::deleteTransaction(unsigned int id)

TransactionDialogController AccountViewController::createTransactionDialogController() const
{
return { m_account.getNextAvailableTransactionId(), m_currencySymbol, m_account.getGroups() };
return { m_account.getNextAvailableTransactionId(), m_account.getGroups(), m_locale };
}

TransactionDialogController AccountViewController::createTransactionDialogController(unsigned int id) const
{
return { m_account.getTransactionById(id).value(), m_currencySymbol, m_account.getGroups() };
return { m_account.getTransactionById(id).value(), m_account.getGroups(), m_locale };
}

21 changes: 7 additions & 14 deletions src/controllers/accountviewcontroller.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <functional>
#include <locale>
#include <map>
#include <string>
#include "groupdialogcontroller.hpp"
Expand All @@ -21,29 +22,22 @@ namespace NickvisionMoney::Controllers
* Constructs an AccountViewController
*
* @param path The path of the account to open
* @param currencySymbol The symbol to use when displaying monetary values
* @param displayCurrencySymbolOnRight True to display the currency symbol on the right of monetary values, else false
* @param locale The user's locale
* @param sendToastCallback A callback function for sending a toast notification to the UI
*/
AccountViewController(const std::string& path, const std::string& currencySymbol, bool displayCurrencySymbolOnRight, const std::function<void(const std::string& message)>& sendToastCallback);
AccountViewController(const std::string& path, const std::locale& locale, const std::function<void(const std::string& message)>& sendToastCallback);
/**
* Gets the path of the account
*
* @returns The path of the account
*/
const std::string& getAccountPath() const;
/**
* Gets the symbol to use when displaying monetary values
* Gets the user's locale
*
* @returns The symbol to use when displaying monetary values
* @returns The user's locale
*/
const std::string& getCurrencySymbol() const;
/**
* Gets whether or not to display the currency symbol on the right of a monetary value
*
* @returns True to display currency symbol on the right, else false
*/
bool getDisplayCurrencySymbolOnRight() const;
const std::locale& getLocale() const;
/**
* Gets the total of the account as a string
*
Expand Down Expand Up @@ -156,8 +150,7 @@ namespace NickvisionMoney::Controllers
TransactionDialogController createTransactionDialogController(unsigned int id) const;

private:
std::string m_currencySymbol;
bool m_displayCurrencySymbolOnRight;
const std::locale& m_locale;
NickvisionMoney::Models::Account m_account;
std::function<void(const std::string& message)> m_sendToastCallback;
std::function<void()> m_accountInfoChangedCallback;
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::string MainWindowController::getFirstOpenAccountPath() const

AccountViewController MainWindowController::createAccountViewControllerForLatestAccount() const
{
return { m_openAccounts[m_openAccounts.size() - 1], m_configuration.getCurrencySymbol(), m_configuration.getDisplayCurrencySymbolOnRight(), m_sendToastCallback };
return { m_openAccounts[m_openAccounts.size() - 1], m_configuration.getLocale(), m_sendToastCallback };
}

void MainWindowController::addAccount(std::string& path)
Expand Down
28 changes: 11 additions & 17 deletions src/controllers/transactiondialogcontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "transactiondialogcontroller.hpp"
#include <sstream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include "../helpers/moneyhelpers.hpp"
#include "../helpers/translation.hpp"

using namespace NickvisionMoney::Controllers;
using namespace NickvisionMoney::Helpers;
using namespace NickvisionMoney::Models;

TransactionDialogController::TransactionDialogController(unsigned int newId, const std::string& currencySymbol, const std::map<unsigned int, Group>& groups) : m_response{ "cancel" }, m_currencySymbol{ currencySymbol }, m_transaction{ newId }, m_groups{ groups }
TransactionDialogController::TransactionDialogController(unsigned int newId, const std::map<unsigned int, Group>& groups, const std::locale& locale) : m_response{ "cancel" }, m_locale{ locale }, m_transaction{ newId }, m_groups{ groups }
{
for(const std::pair<const unsigned int, Group>& pair : m_groups)
{
Expand All @@ -16,7 +17,7 @@ TransactionDialogController::TransactionDialogController(unsigned int newId, con
m_groupNames.insert(m_groupNames.begin(), _("None"));
}

TransactionDialogController::TransactionDialogController(const Transaction& transaction, const std::string& currencySymbol, const std::map<unsigned int, Group>& groups) : m_response{ "cancel" }, m_currencySymbol{ currencySymbol }, m_transaction{ transaction }, m_groups{ groups }
TransactionDialogController::TransactionDialogController(const Transaction& transaction, const std::map<unsigned int, Group>& groups, const std::locale& locale) : m_response{ "cancel" }, m_locale{ locale }, m_transaction{ transaction }, m_groups{ groups }
{
for(const std::pair<const unsigned int, Group>& pair : m_groups)
{
Expand All @@ -36,11 +37,6 @@ void TransactionDialogController::setResponse(const std::string& response)
m_response = response;
}

const std::string& TransactionDialogController::getCurrencySymbol() const
{
return m_currencySymbol;
}

const Transaction& TransactionDialogController::getTransaction() const
{
return m_transaction;
Expand Down Expand Up @@ -98,12 +94,10 @@ int TransactionDialogController::getGroupAsIndex() const

std::string TransactionDialogController::getAmountAsString() const
{
std::stringstream builder;
builder << m_transaction.getAmount();
return builder.str();
return MoneyHelpers::boostMoneyToLocaleString(m_transaction.getAmount(), m_locale);
}

TransactionCheckStatus TransactionDialogController::updateTransaction(const std::string& dateString, const std::string& description, int type, int repeatInterval, int groupIndex, const std::string& amountString)
TransactionCheckStatus TransactionDialogController::updateTransaction(const std::string& dateString, const std::string& description, int type, int repeatInterval, int groupIndex, std::string amountString)
{
if(description.empty())
{
Expand All @@ -113,15 +107,15 @@ TransactionCheckStatus TransactionDialogController::updateTransaction(const std:
{
return TransactionCheckStatus::EmptyAmount;
}
boost::multiprecision::cpp_dec_float_50 amount{ 0.0 };
try
if(MoneyHelpers::isLocaleDotDecimalSeperated(m_locale) && amountString.find(".") == std::string::npos)
{
amount = static_cast<boost::multiprecision::cpp_dec_float_50>(amountString);
amountString += ".00";
}
catch(...)
else if(!MoneyHelpers::isLocaleDotDecimalSeperated(m_locale) && amountString.find(",") == std::string::npos)
{
return TransactionCheckStatus::InvalidAmount;
amountString += ",00";
}
boost::multiprecision::cpp_dec_float_50 amount{ MoneyHelpers::localeStringToBoostMoney(amountString, m_locale) };
m_transaction.setDate(boost::gregorian::from_string(dateString));
m_transaction.setDescription(description);
m_transaction.setType(static_cast<TransactionType>(type));
Expand Down
21 changes: 9 additions & 12 deletions src/controllers/transactiondialogcontroller.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <locale>
#include <map>
#include <string>
#include <vector>
Expand Down Expand Up @@ -29,16 +30,18 @@ namespace NickvisionMoney::Controllers
* Constructs a TransactionDialogController
*
* @param newId The Id of the new transaction
* @param currencySymbol The currency symbol
* @param groups The groups of the account
* @param locale The user's locale
*/
TransactionDialogController(unsigned int newId, const std::string& currencySymbol, const std::map<unsigned int, NickvisionMoney::Models::Group>& groups);
TransactionDialogController(unsigned int newId, const std::map<unsigned int, NickvisionMoney::Models::Group>& groups, const std::locale& locale);
/**
* Constructs a TransactionDialogController
*
* @param transaction The transaction to update
* @param currencySymbol The currency symbol
* @param groups The groups of the account
* @param locale The user's locale
*/
TransactionDialogController(const NickvisionMoney::Models::Transaction& transaction, const std::string& currencySymbol, const std::map<unsigned int, NickvisionMoney::Models::Group>& groups);
TransactionDialogController(const NickvisionMoney::Models::Transaction& transaction, const std::map<unsigned int, NickvisionMoney::Models::Group>& groups, const std::locale& locale);
/**
* Gets the response of the dialog
*
Expand All @@ -51,12 +54,6 @@ namespace NickvisionMoney::Controllers
* @param response The new response of the dialog
*/
void setResponse(const std::string& response);
/**
* Gets the currency symbol
*
* @returns The currency symbol
*/
const std::string& getCurrencySymbol() const;
/**
* Gets the transaction managed by the dialog
*
Expand Down Expand Up @@ -134,11 +131,11 @@ namespace NickvisionMoney::Controllers
* @param amountString The amount string
* @returns The TransactionCheckStatus
*/
TransactionCheckStatus updateTransaction(const std::string& dateString, const std::string& description, int type, int repeatInterval, int groupIndex, const std::string& amountString);
TransactionCheckStatus updateTransaction(const std::string& dateString, const std::string& description, int type, int repeatInterval, int groupIndex, std::string amountString);

private:
std::string m_response;
std::string m_currencySymbol;
const std::locale& m_locale;
NickvisionMoney::Models::Transaction m_transaction;
std::map<unsigned int, NickvisionMoney::Models::Group> m_groups;
std::vector<std::string> m_groupNames;
Expand Down
Loading

0 comments on commit ea82c2d

Please sign in to comment.