Skip to content

Commit

Permalink
Shared - CurrencyCheckStatus API
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Mar 11, 2024
1 parent 703288a commit 1c2e6a4
Show file tree
Hide file tree
Showing 36 changed files with 252 additions and 143 deletions.
1 change: 1 addition & 0 deletions libdenaro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include(CTest)
add_library(libdenaro
"src/controllers/accountviewcontroller.cpp"
"src/controllers/mainwindowcontroller.cpp"
"src/controllers/newaccountdialogcontroller.cpp"
"src/controllers/preferencesviewcontroller.cpp"
"src/helpers/currencyhelpers.cpp"
"src/helpers/datehelpers.cpp"
Expand Down
6 changes: 6 additions & 0 deletions libdenaro/include/controllers/mainwindowcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <libnick/taskbar/taskbaritem.h>
#include <libnick/update/updater.h>
#include "controllers/accountviewcontroller.h"
#include "controllers/newaccountdialogcontroller.h"
#include "controllers/preferencesviewcontroller.h"
#include "models/accounttype.h"
#include "models/color.h"
Expand Down Expand Up @@ -98,6 +99,11 @@ namespace Nickvision::Money::Shared::Controllers
* @return The PreferencesViewController
*/
std::shared_ptr<PreferencesViewController> createPreferencesViewController() const;
/**
* @brief Gets a NewAccountDialogController.
* @return The NewAccountDialogController
*/
std::shared_ptr<NewAccountDialogController> createNewAccountDialogController() const;
/**
* @brief Gets a AccountViewController.
* @param path The path of the account
Expand Down
26 changes: 26 additions & 0 deletions libdenaro/include/controllers/newaccountdialogcontroller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef NEWACCOUNTDIALOGCONTROLLER_H
#define NEWACCOUNTDIALOGCONTROLLER_H

#include <filesystem>
#include <string>
#include <vector>

namespace Nickvision::Money::Shared::Controllers
{
/**
* @brief A controller for a NewAccountDialog.
*/
class NewAccountDialogController
{
public:
/**
* @brief Constructs a NewAccountDialogController.
*/
NewAccountDialogController(const std::vector<std::filesystem::path>& openAccounts);

private:
std::vector<std::filesystem::path> m_openAccounts;
};
}

#endif //NEWACCOUNTDIALOGCONTROLLER_H
9 changes: 5 additions & 4 deletions libdenaro/include/models/currency.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <string>
#include "amountstyle.h"
#include "currencycheckstatus.h"

namespace Nickvision::Money::Shared::Models
{
Expand All @@ -23,10 +24,10 @@ namespace Nickvision::Money::Shared::Models
*/
Currency(const std::string& symbol, const std::string& code);
/**
* @brief Gets whether or not the Currency object represents an empty value.
* @return True if empty, else false
* @brief Checks the validity of the Currency object.
* @return CurrencyCheckStatus
*/
bool empty() const;
CurrencyCheckStatus validate() const;
/**
* @brief Gets the symbol of the currency.
* @return The symbol of the currency
Expand Down Expand Up @@ -91,7 +92,7 @@ namespace Nickvision::Money::Shared::Models
void setAmountStyle(AmountStyle style);
/**
* @brief Gets whether or not the object is valid or not.
* @return True if valid (!empty), else false
* @return True if valid (check() == CurrencyCheckStatus::Valid), else false
*/
operator bool() const;

Expand Down
21 changes: 21 additions & 0 deletions libdenaro/include/models/currencycheckstatus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef CURRENCYCHECKSTATUS_H
#define CURRENCYCHECKSTATUS_H

namespace Nickvision::Money::Shared::Models
{
/**
* @brief Statuses for when a currency is validated.
*/
enum class CurrencyCheckStatus
{
Valid = 1,
EmptySymbol = 2,
EmptyCode = 4,
EmptyDecimalSeparator = 8,
SameSeparators = 16,
SameSymbolAndDecimalSeparator = 32,
SameSymbolAndGroupSeparator = 64
};
}

#endif //CURRENCYCHECKSTATUS_H
12 changes: 11 additions & 1 deletion libdenaro/src/controllers/mainwindowcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ namespace Nickvision::Money::Shared::Controllers
return std::make_shared<PreferencesViewController>();
}

std::shared_ptr<NewAccountDialogController> MainWindowController::createNewAccountDialogController() const
{
std::vector<std::filesystem::path> openAccounts;
for(const std::pair<const std::filesystem::path, std::shared_ptr<AccountViewController>>& pair : m_accountViewControllers)
{
openAccounts.push_back(pair.first);
}
return std::make_shared<NewAccountDialogController>(openAccounts);
}

const std::shared_ptr<AccountViewController>& MainWindowController::getAccountViewController(const std::filesystem::path& path) const
{
return m_accountViewControllers.at(path);
Expand Down Expand Up @@ -282,7 +292,7 @@ namespace Nickvision::Money::Shared::Controllers
}
if(controller)
{
m_accountViewControllers[path] = controller;
m_accountViewControllers.emplace(std::make_pair(path, controller));
Configuration& config{ Aura::getActive().getConfig<Configuration>("config") };
config.addRecentAccount(controller->toRecentAccount());
config.save();
Expand Down
10 changes: 10 additions & 0 deletions libdenaro/src/controllers/newaccountdialogcontroller.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "controllers/newaccountdialogcontroller.h"

namespace Nickvision::Money::Shared::Controllers
{
NewAccountDialogController::NewAccountDialogController(const std::vector<std::filesystem::path>& openAccounts)
: m_openAccounts(openAccounts)
{

}
}
30 changes: 27 additions & 3 deletions libdenaro/src/models/currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,33 @@ namespace Nickvision::Money::Shared::Models

}

bool Currency::empty() const
CurrencyCheckStatus Currency::validate() const
{
return m_symbol.empty() && m_code.empty();
if(m_symbol.empty())
{
return CurrencyCheckStatus::EmptySymbol;
}
else if(m_code.empty())
{
return CurrencyCheckStatus::EmptyCode;
}
else if(m_decimalSeparator == '\0')
{
return CurrencyCheckStatus::EmptyDecimalSeparator;
}
else if(m_decimalSeparator == m_groupSeparator)
{
return CurrencyCheckStatus::SameSeparators;
}
else if(m_symbol.find(m_decimalSeparator) != std::string::npos)
{
return CurrencyCheckStatus::SameSymbolAndDecimalSeparator;
}
else if(m_symbol.find(m_groupSeparator) != std::string::npos)
{
return CurrencyCheckStatus::SameSymbolAndGroupSeparator;
}
return CurrencyCheckStatus::Valid;
}

const std::string& Currency::getSymbol() const
Expand Down Expand Up @@ -100,6 +124,6 @@ namespace Nickvision::Money::Shared::Models

Currency::operator bool() const
{
return !empty();
return validate() == CurrencyCheckStatus::Valid;
}
}
10 changes: 10 additions & 0 deletions libdenaro/tests/currencytests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TEST(CurrencyHelpers, CustomCurrency1)
currency.setDecimalSeparator(',');
currency.setGroupSeparator('.');
currency.setAmountStyle(Models::AmountStyle::NumberSpaceSymbol);
ASSERT_TRUE(currency.validate() == CurrencyCheckStatus::Valid);
ASSERT_EQ(CurrencyHelpers::toAmountString(12347.89, currency), "12.347,89 #");
ASSERT_EQ(CurrencyHelpers::toAmountString(12347.89, currency, false), "12.347,89");
}
Expand All @@ -45,5 +46,14 @@ TEST(CurrencyHelpers, CustomCurrency2)
currency.setDecimalSeparator('-');
currency.setGroupSeparator('*');
currency.setAmountStyle(Models::AmountStyle::SymbolSpaceNumber);
ASSERT_TRUE(currency.validate() == CurrencyCheckStatus::Valid);
ASSERT_EQ(CurrencyHelpers::toAmountString(2765.9, currency), "@ 2*765-90");
}

TEST(CurrencyHelpers, CustomCurrency3)
{
Currency currency{ "@", "HAS" };
currency.setDecimalSeparator('-');
currency.setGroupSeparator('-');
ASSERT_TRUE(currency.validate() == CurrencyCheckStatus::SameSeparators);
}
10 changes: 5 additions & 5 deletions resources/po/ar.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-07 11:06-0500\n"
"POT-Creation-Date: 2024-03-07 22:59-0500\n"
"PO-Revision-Date: 2023-12-06 07:04+0000\n"
"Last-Translator: ButterflyOfFire <[email protected]>\n"
"Language-Team: Arabic <https://hosted.weblate.org/projects/nickvision-money/"
Expand Down Expand Up @@ -113,20 +113,20 @@ msgstr "مساء الخير!"
msgid "Good Day!"
msgstr "طاب يومك!"

#: libdenaro/src/controllers/mainwindowcontroller.cpp:213
#: libdenaro/src/controllers/mainwindowcontroller.cpp:223
msgid "New update available"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:231
#: libdenaro/src/controllers/mainwindowcontroller.cpp:241
msgid "Unable to download and install update"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:264
#: libdenaro/src/controllers/mainwindowcontroller.cpp:274
#, fuzzy
msgid "The file is not a Denaro account file."
msgstr "تعذَّر تصدير الحساب للملفِّ."

#: libdenaro/src/controllers/mainwindowcontroller.cpp:269
#: libdenaro/src/controllers/mainwindowcontroller.cpp:279
#, fuzzy
msgid "The account is already open."
msgstr "هذا الحساب مفتوح بالفعل."
Expand Down
10 changes: 5 additions & 5 deletions resources/po/cs.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-07 11:06-0500\n"
"POT-Creation-Date: 2024-03-07 22:59-0500\n"
"PO-Revision-Date: 2023-11-17 11:26+0000\n"
"Last-Translator: Fjuro <[email protected]>\n"
"Language-Team: Czech <https://hosted.weblate.org/projects/nickvision-money/"
Expand Down Expand Up @@ -112,20 +112,20 @@ msgstr "Dobrý večer!"
msgid "Good Day!"
msgstr "Dobrý den!"

#: libdenaro/src/controllers/mainwindowcontroller.cpp:213
#: libdenaro/src/controllers/mainwindowcontroller.cpp:223
msgid "New update available"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:231
#: libdenaro/src/controllers/mainwindowcontroller.cpp:241
msgid "Unable to download and install update"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:264
#: libdenaro/src/controllers/mainwindowcontroller.cpp:274
#, fuzzy
msgid "The file is not a Denaro account file."
msgstr "Nepodařilo se exportovat účet do souboru."

#: libdenaro/src/controllers/mainwindowcontroller.cpp:269
#: libdenaro/src/controllers/mainwindowcontroller.cpp:279
#, fuzzy
msgid "The account is already open."
msgstr "Tento účet je již otevřen."
Expand Down
10 changes: 5 additions & 5 deletions resources/po/da.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-07 11:06-0500\n"
"POT-Creation-Date: 2024-03-07 22:59-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -108,20 +108,20 @@ msgstr "Godaften!"
msgid "Good Day!"
msgstr "God dag!"

#: libdenaro/src/controllers/mainwindowcontroller.cpp:213
#: libdenaro/src/controllers/mainwindowcontroller.cpp:223
msgid "New update available"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:231
#: libdenaro/src/controllers/mainwindowcontroller.cpp:241
msgid "Unable to download and install update"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:264
#: libdenaro/src/controllers/mainwindowcontroller.cpp:274
#, fuzzy
msgid "The file is not a Denaro account file."
msgstr "Ude af stand til at eksportere konto til fil."

#: libdenaro/src/controllers/mainwindowcontroller.cpp:269
#: libdenaro/src/controllers/mainwindowcontroller.cpp:279
#, fuzzy
msgid "The account is already open."
msgstr "Denne konto er allerede åben."
Expand Down
10 changes: 5 additions & 5 deletions resources/po/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-07 11:06-0500\n"
"POT-Creation-Date: 2024-03-07 22:59-0500\n"
"PO-Revision-Date: 2023-08-29 18:53+0000\n"
"Last-Translator: Ettore Atalan <[email protected]>\n"
"Language-Team: German <https://hosted.weblate.org/projects/nickvision-money/"
Expand Down Expand Up @@ -112,20 +112,20 @@ msgstr "Guten Abend!"
msgid "Good Day!"
msgstr "Schönen Tag!"

#: libdenaro/src/controllers/mainwindowcontroller.cpp:213
#: libdenaro/src/controllers/mainwindowcontroller.cpp:223
msgid "New update available"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:231
#: libdenaro/src/controllers/mainwindowcontroller.cpp:241
msgid "Unable to download and install update"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:264
#: libdenaro/src/controllers/mainwindowcontroller.cpp:274
#, fuzzy
msgid "The file is not a Denaro account file."
msgstr "Konto konnte nicht zu Datei exportiert werden."

#: libdenaro/src/controllers/mainwindowcontroller.cpp:269
#: libdenaro/src/controllers/mainwindowcontroller.cpp:279
#, fuzzy
msgid "The account is already open."
msgstr "Dieses Konto ist schon geöffnet."
Expand Down
10 changes: 5 additions & 5 deletions resources/po/denaro.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-07 13:57-0500\n"
"POT-Creation-Date: 2024-03-08 14:03-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -107,19 +107,19 @@ msgstr ""
msgid "Good Day!"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:213
#: libdenaro/src/controllers/mainwindowcontroller.cpp:223
msgid "New update available"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:231
#: libdenaro/src/controllers/mainwindowcontroller.cpp:241
msgid "Unable to download and install update"
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:264
#: libdenaro/src/controllers/mainwindowcontroller.cpp:274
msgid "The file is not a Denaro account file."
msgstr ""

#: libdenaro/src/controllers/mainwindowcontroller.cpp:269
#: libdenaro/src/controllers/mainwindowcontroller.cpp:279
msgid "The account is already open."
msgstr ""

Expand Down
Loading

0 comments on commit 1c2e6a4

Please sign in to comment.