Skip to content

Commit

Permalink
Use locale kit for number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dospuntos authored and humdingerb committed Jun 9, 2024
1 parent a955411 commit 061b45a
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 364 deletions.
10 changes: 4 additions & 6 deletions locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
1 English application/x-vnd.wgp-CapitalBe 3882412825
1 English application/x-vnd.wgp-CapitalBe 1546978192
Year ReportWindow Year
None ReportWindow None
Export to QIF file… MainWindow Export to QIF file…
Expand All @@ -25,7 +25,6 @@ Import from QIF file… MainWindow Import from QIF file…
Preview: PrefWindow Preview:
Ending date: ReportWindow Ending date:
Scheduled transactions MainWindow Scheduled transactions
Separator: PrefWindow Separator:
Closed account: PrefWindow Closed account:
Help: Report ReportWindow Help: Report
Bank charges ReconcileWindow Bank charges
Expand All @@ -50,6 +49,7 @@ Highest BudgetWindow Highest
You need to have at least 2 accounts to perform a transfer. MainWindow You need to have at least 2 accounts to perform a transfer.
Monthly ScheduleListWindow Monthly
Frequency BudgetWindow Frequency
Decimals: PrefWindow Decimals:
CapitalBe didn't understand the amount for 'Bank charges' ReconcileWindow CapitalBe didn't understand the amount for 'Bank charges'
You need to enter a check number or transaction type, such as ATM (for debit card transactions and the like), DEP (for deposits), or your own code for some other kind of expense. CheckView You need to enter a check number or transaction type, such as ATM (for debit card transactions and the like), DEP (for deposits), or your own code for some other kind of expense.
Uncategorized SplitView Uncategorized
Expand All @@ -70,8 +70,8 @@ Interest earned ReconcileWindow Interest earned
Quit Locale Quit
Once deleted, you will not be able to get back any data on this account. MainWindow Once deleted, you will not be able to get back any data on this account.
Add category CategoryWindow Add category
Use system currency format Account Use system currency format
Could not export your financial data to the file '%%FILENAME%%' MainWindow Could not export your financial data to the file '%%FILENAME%%'
Currency format: PrefWindow Currency format:
Name: Account Name:
Total deposits: %s ReconcileWindow Total deposits: %s
Memo CommonTerms Memo
Expand Down Expand Up @@ -160,7 +160,6 @@ Total checks: ReconcileWindow Total checks:
Remove item SplitView Remove item
Transaction MainWindow Transaction
Edit transfer TransferWindow Edit transfer
Default account settings PrefWindow Default account settings
Reports MainWindow Reports
Categories CategoryWindow Categories
Account MainWindow Account
Expand All @@ -169,6 +168,7 @@ Unselected: PrefWindow Unselected:
Total deposits: ReconcileWindow Total deposits:
Categories… MainWindow Categories…
Help: Budget BudgetWindow Help: Budget
Currency format PrefWindow Currency format
Payee CommonTerms Payee
If you intend to transfer money, it will need to be an amount that is not zero. TransferWindow If you intend to transfer money, it will need to be an amount that is not zero.
You can schedule transfers, deposits, or ATM transactions. MainWindow You can schedule transfers, deposits, or ATM transactions.
Expand Down Expand Up @@ -208,7 +208,6 @@ Starting date: ReportWindow Starting date:
Starting balance ReconcileWindow Starting balance
Quarterly ScheduleAddWindow Quarterly
Reconcile: ReconcileWindow Reconcile:
Use default currency settings Account Use default currency settings
Total charges: ReconcileWindow Total charges:
Total worth ReportWindow Total worth
Expense CashFlowReport Expense
Expand All @@ -228,7 +227,6 @@ Total checks: %s ReconcileWindow Total checks: %s
Quarterly BudgetWindow Quarterly
Remove category CategoryWindow Remove category
You cannot schedule transactions on a closed account. MainWindow You cannot schedule transactions on a closed account.
Decimal: PrefWindow Decimal:
CapitalBe didn't understand the amount for 'Interest earned' ReconcileWindow CapitalBe didn't understand the amount for 'Interest earned'
Date is missing ReconcileWindow Date is missing
Unknown ScheduleListWindow Unknown
Expand Down
6 changes: 2 additions & 4 deletions src/Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,12 @@ Account::UseDefaultLocale(const bool& usedefault)

BString command;
if (fUseDefaultLocale) {
command = "delete from accountlocale where accountid = ";
command << fID << ";";
command << "DELETE FROM accountlocale WHERE accountid = " << fID << ";";
gDatabase.DBCommand(command.String(), "Account::UseDefaultLocale");
gCurrentLocale = gDefaultLocale;
} else {
// update the local copy in case it changed since the program was opened
fLocale = gDefaultLocale;

fLocale = gCurrentLocale;
gDatabase.SetAccountLocale(fID, fLocale);
}

Expand Down
7 changes: 0 additions & 7 deletions src/Account.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,19 @@ class Account : public Notifier {
~Account(void);

void SetName(const char* name);

const char* Name(void) const { return fName.String(); }

void SetID(const time_t& id) { fID = id; }

uint32 GetID(void) const { return fID; }

void SetClosed(const bool& value) { fClosed = value; }

bool IsClosed(void) const { return fClosed; }

uint32 CurrentTransaction(void) const { return fCurrentTransaction; }

bool SetCurrentTransaction(const uint32& id);

uint16 LastCheckNumber(void) const { return fLastCheckNumber; }

uint16 LookupLastCheckNumber(void);

void SetLastCheckNumber(const uint16& value) { fLastCheckNumber = value; }

BString AutocompleteCategory(const char* input);
Expand All @@ -58,7 +52,6 @@ class Account : public Notifier {
void (*TransactionIteratorFunc)(const TransactionData&, void*), void* ptr);

void UseDefaultLocale(const bool& usedefault);

bool IsUsingDefaultLocale(void) const { return fUseDefaultLocale; }

private:
Expand Down
13 changes: 5 additions & 8 deletions src/AccountSettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Database.h"
#include "PrefWindow.h"


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Account"

Expand All @@ -35,7 +34,7 @@ AccountSettingsWindow::AccountSettingsWindow(Account* account)
(fAccount ? fAccount->Name() : NULL), new BMessage(M_NAME_CHANGED));
fAccountName->SetCharacterLimit(32);

fUseDefault = new BCheckBox("usedefault", B_TRANSLATE("Use default currency settings"),
fUseDefault = new BCheckBox("usedefault", B_TRANSLATE("Use system currency format"),
new BMessage(M_TOGGLE_USE_DEFAULT));
if (!fAccount || fAccount->IsUsingDefaultLocale())
fUseDefault->SetValue(B_CONTROL_ON);
Expand All @@ -55,9 +54,9 @@ AccountSettingsWindow::AccountSettingsWindow(Account* account)

SetDefaultButton(fOK);

if (!fAccount || fAccount->IsUsingDefaultLocale()) {
if (!fAccount || fAccount->IsUsingDefaultLocale())
fPrefView->Hide();
}

// clang-format off
BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_DEFAULT_SPACING)
Expand Down Expand Up @@ -86,17 +85,15 @@ AccountSettingsWindow::MessageReceived(BMessage* msg)
case M_EDIT_ACCOUNT_SETTINGS:
{
Locale customLocale;
Locale defaultLocale;
fPrefView->GetSettings(customLocale);

if (!fAccount) {
fPrefView->GetSettings(customLocale);
gDatabase.AddAccount(fAccountName->Text(), ACCOUNT_BANK, "Open",
defaultLocale == customLocale ? NULL : &customLocale);
fUseDefault->Value() == B_CONTROL_ON ? NULL : &customLocale);
} else {
if (strcmp(fAccountName->Text(), fAccount->Name()) != 0)
gDatabase.RenameAccount(fAccount, fAccountName->Text());

fPrefView->GetSettings(customLocale);
if (fUseDefault->Value() != B_CONTROL_ON) {
fAccount->UseDefaultLocale(false);
fAccount->SetLocale(customLocale);
Expand Down
23 changes: 13 additions & 10 deletions src/BudgetWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <LayoutBuilder.h>
#include <MenuBar.h>
#include <Message.h>
#include <NumberFormat.h>
#include <StringView.h>

#include "Account.h"
Expand Down Expand Up @@ -44,6 +45,8 @@ BudgetWindow::BudgetWindow(const BRect& frame)
fIncomeGrid(13, 0),
fSpendingGrid(13, 0)
{
BNumberFormat numberFormatter;
fDecimalSymbol = numberFormatter.GetSeparator(B_DECIMAL_SEPARATOR);
fBar = new BMenuBar("menubar");
fBar->AddItem(
new BMenuItem(B_TRANSLATE("Recalculate all"), new BMessage(M_BUDGET_RECALCULATE)));
Expand Down Expand Up @@ -128,7 +131,7 @@ BudgetWindow::MessageReceived(BMessage* msg)
break;
f.Round();
gDefaultLocale.CurrencyToString(f, str);
str.Truncate(str.FindFirst(gDefaultLocale.CurrencyDecimal()));
str.Truncate(str.FindFirst(fDecimalSymbol));
str.RemoveFirst(gDefaultLocale.CurrencySymbol());

BRow* row = fCategoryList->CurrentSelection();
Expand Down Expand Up @@ -251,7 +254,7 @@ BudgetWindow::HandleCategorySelection(void)

BString str;
gDefaultLocale.CurrencyToString(entry.amount.AbsoluteValue(), str);
str.Truncate(str.FindFirst(gDefaultLocale.CurrencyDecimal()));
str.Truncate(str.FindFirst(fDecimalSymbol));
str.RemoveFirst(gDefaultLocale.CurrencySymbol());
fAmountBox->SetText(str.String());

Expand Down Expand Up @@ -306,7 +309,7 @@ BudgetWindow::RefreshCategories(void)

BString amountstr;
gDefaultLocale.CurrencyToString(amount.AbsoluteValue(), amountstr);
amountstr.Truncate(amountstr.FindFirst(gDefaultLocale.CurrencyDecimal()));
amountstr.Truncate(amountstr.FindFirst(fDecimalSymbol));
amountstr.RemoveFirst(gDefaultLocale.CurrencySymbol());

row->SetField(new BStringField(amountstr.String()), 1);
Expand Down Expand Up @@ -355,9 +358,9 @@ BudgetWindow::RefreshBudgetSummary(void)
gDefaultLocale.CurrencyToString(stotal, stemp);
gDefaultLocale.CurrencyToString(mtotal, mtemp);

itemp.Truncate(itemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
stemp.Truncate(stemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
mtemp.Truncate(mtemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
itemp.Truncate(itemp.FindFirst(fDecimalSymbol));
stemp.Truncate(stemp.FindFirst(fDecimalSymbol));
mtemp.Truncate(mtemp.FindFirst(fDecimalSymbol));

itemp.RemoveFirst(gDefaultLocale.CurrencySymbol());
stemp.RemoveFirst(gDefaultLocale.CurrencySymbol());
Expand Down Expand Up @@ -387,17 +390,17 @@ BudgetWindow::RefreshBudgetSummary(void)
BString ttemp;

gDefaultLocale.CurrencyToString(irowtotal, ttemp);
ttemp.Truncate(ttemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
ttemp.Truncate(ttemp.FindFirst(fDecimalSymbol));
ttemp.RemoveFirst(gDefaultLocale.CurrencySymbol());
fBudgetSummary->RowAt(0)->SetField(new BStringField(ttemp.String()), 13);

gDefaultLocale.CurrencyToString(srowtotal, ttemp);
ttemp.Truncate(ttemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
ttemp.Truncate(ttemp.FindFirst(fDecimalSymbol));
ttemp.RemoveFirst(gDefaultLocale.CurrencySymbol());
fBudgetSummary->RowAt(1)->SetField(new BStringField(ttemp.String()), 13);

gDefaultLocale.CurrencyToString(ttotal, ttemp);
ttemp.Truncate(ttemp.FindFirst(gDefaultLocale.CurrencyDecimal()));
ttemp.Truncate(ttemp.FindFirst(fDecimalSymbol));
ttemp.RemoveFirst(gDefaultLocale.CurrencySymbol());
fBudgetSummary->RowAt(2)->SetField(new BStringField(ttemp.String()), 13);

Expand Down Expand Up @@ -670,7 +673,7 @@ BudgetWindow::SetPeriod(const BudgetPeriod& period)

BString str;
gDefaultLocale.CurrencyToString(entry.amount, str);
str.Truncate(str.FindFirst(gDefaultLocale.CurrencyDecimal()));
str.Truncate(str.FindFirst(fDecimalSymbol));
str.RemoveFirst(gDefaultLocale.CurrencySymbol());

row->SetField(new BStringField(str.String()), 1);
Expand Down
1 change: 1 addition & 0 deletions src/BudgetWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class BudgetWindow : public BWindow {
BRow *fStatAverageRow, *fStatHighestRow, *fStatLowestRow;

ReportGrid fIncomeGrid, fSpendingGrid;
BString fDecimalSymbol;
};

#endif
27 changes: 1 addition & 26 deletions src/CBLocale.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#include "DAlert.h"
#include "Fixed.h"

typedef enum {
DATE_MDY = 1,
DATE_DMY = 2
} date_format;

class Locale {
public:
Locale(void);
Expand All @@ -31,42 +26,22 @@ class Locale {
void NumberToCurrency(const Fixed& number, BString& string);

void SetCurrencySymbol(const char* symbol);

const char* CurrencySymbol(void) const { return fCurrencySymbol.String(); }

void SetCurrencySeparator(const char* symbol);

const char* CurrencySeparator(void) const { return fCurrencySeparator.String(); }

void SetCurrencyDecimal(const char* symbol);

const char* CurrencyDecimal(void) const { return fCurrencyDecimal.String(); }

void SetCurrencySymbolPrefix(const bool& value);

bool IsCurrencySymbolPrefix(void) const { return fPrefixSymbol; }

void SetCurrencyDecimalPlace(const uint8& place);

void SetCurrencyDecimalPlace(const uint8 place);
uint8 CurrencyDecimalPlace(void) const { return fCurrencyDecimalPlace; }

void SetDST(const bool& value);

bool UseDST(void) const { return fUseDST; }

private:
friend class CapitalBeParser;

void SetDefaults(void);
status_t ConstructDateStringMDY(const char* in, BString& out);
status_t ConstructDateStringDMY(const char* in, BString& out);

BString fCurrencySymbol;
bool fPrefixSymbol;
BString fCurrencySeparator;
BString fCurrencyDecimal;
uint8 fCurrencyDecimalPlace;
bool fUseDST;
};

void ShowAlert(const char* header, const char* message, alert_type type = B_INFO_ALERT);
Expand Down
Loading

0 comments on commit 061b45a

Please sign in to comment.