From 5999035959338080a4250a59b297248dd9b12982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 4 Jul 2010 16:33:25 +0200 Subject: [PATCH] First code review --- controller/KissCount.cpp | 6 +- init.sql | 4 +- main.cpp | 4 +- model/Database.cpp | 442 ++++++++++++------------- model/Database.h | 6 +- model/User.cpp | 23 +- model/User.h | 2 +- view/AccountPanel.cpp | 530 +++++++++++++++--------------- view/AccountPanel.h | 4 +- view/ButtonPanel.cpp | 28 +- view/ButtonPanel.h | 4 +- view/CalendarEditor.cpp | 8 +- view/CalendarEditor.h | 4 +- view/GenerateDialog.cpp | 2 +- view/GenerateDialog.h | 6 +- view/GridAccount.h | 19 +- view/PasswordDialog.h | 6 +- view/PreferencesPanel.cpp | 200 +++++------ view/PreferencesPanel.h | 4 +- view/UsersDialog.cpp | 18 +- view/UsersDialog.h | 6 +- view/wxGridCellBitmapRenderer.cpp | 12 +- view/wxGridCellBitmapRenderer.h | 14 +- view/wxUI.cpp | 90 ++--- view/wxUI.h | 17 +- 25 files changed, 718 insertions(+), 741 deletions(-) diff --git a/controller/KissCount.cpp b/controller/KissCount.cpp index 2d5ca32..5c66906 100644 --- a/controller/KissCount.cpp +++ b/controller/KissCount.cpp @@ -71,17 +71,17 @@ double KissCount::GetAccountAmount(wxString id, int month, int year) void KissCount::UpdateOperation(Operation op) { - _db->UpdateOperation(op); + _db->UpdateOperation(op); } wxString KissCount::AddOperation(Operation op) { - return _db->AddOperation(_user, op); + return _db->AddOperation(_user, op); } void KissCount::DeleteOperation(Operation op) { - _db->DeleteOperation(op); + _db->DeleteOperation(op); } void KissCount::DeleteOperations(int month, int year) diff --git a/init.sql b/init.sql index e76b6b5..f6496f5 100644 --- a/init.sql +++ b/init.sql @@ -1,4 +1,4 @@ -CREATE TABLE kisscount(version VARCHAR(20), db_version VARCHAR(20)); +CREATE TABLE kisscount(db_version VARCHAR(20)); CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR(255), password VARCHAR(255)); CREATE TABLE account(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), number VARCHAR(255), shared CHAR(1), default_account CHAR(1)); CREATE TABLE account_amount(id INTEGER PRIMARY KEY, account REFERENCES account(id), year INTEGER, month INTEGER, amount FLOAT); @@ -7,7 +7,7 @@ CREATE TABLE category(id INTEGER PRIMARY KEY, user REFERENCES user(id), parent R CREATE TABLE preference(id INTEGER PRIMARY KEY, user REFERENCES user(id), name VARCHAR(255), value VARCHAR(255)); CREATE TABLE default_preference(id INTEGER PRIMARY KEY, type VARCHAR(255), name VARCHAR(255), value VARCHAR(255)); CREATE TABLE default_category(id INTEGER PRIMARY KEY, parent REFERENCES category(id), name VARCHAR(255), color VARCHAR(255), font VARCHAR(255)); -INSERT INTO kisscount ("version", "db_version") VALUES ("0.1", "1"); +INSERT INTO kisscount ("db_version") VALUES ("1"); -- INSERT INTO default_preference ("name", "value") VALUES ("category", "name", "Fixe"); -- INSERT INTO default_preference ("name", "value") VALUES ("category", "name", "Courses"); INSERT INTO default_category ("parent", "name", "color", "font") VALUES ("0", "Fixe", "#FFFF99", ""); diff --git a/main.cpp b/main.cpp index 11d22b1..7109460 100644 --- a/main.cpp +++ b/main.cpp @@ -9,10 +9,10 @@ class MyApp: public wxApp new KissCount(); } catch (std::string s) - { + { std::cerr << "Error " << s << "\n"; return false; - } + } return true; } diff --git a/model/Database.cpp b/model/Database.cpp index 7017268..b17c6b7 100644 --- a/model/Database.cpp +++ b/model/Database.cpp @@ -1,42 +1,42 @@ #include "Database.h" - // if (!_db.CheckSyntax(req)) - // { - // wxString s = req; - // std::cout << s.mb_str() << " is invalid !\n" ; - // code_if_syntax_fail; - // return return_value; - // } +// if (!_db.CheckSyntax(req)) +// { +// wxString s = req; +// std::cout << s.mb_str() << " is invalid !\n" ; +// code_if_syntax_fail; +// return return_value; +// } #define EXECUTE_SQL_UPDATE_WITH_CODE(req, return_value, code_if_fail, code_if_syntax_fail) \ - do{\ - try\ - {\ - _db.ExecuteUpdate(req);\ - }\ - catch (wxSQLite3Exception e)\ - {\ - std::cerr << req.mb_str() << "\n" ;\ - std::cerr << e.GetMessage().mb_str() << "\n" ;\ - code_if_fail; \ - return return_value;\ - }\ -} while(0); + do{ \ + try \ + { \ + _db.ExecuteUpdate(req); \ + } \ + catch (wxSQLite3Exception e) \ + { \ + std::cerr << req.mb_str() << "\n" ; \ + std::cerr << e.GetMessage().mb_str() << "\n" ; \ + code_if_fail; \ + return return_value; \ + } \ + } while(0); #define EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, code_if_fail, code_if_syntax_fail) \ - do{\ - try\ - {\ - res = _db.ExecuteQuery(req);\ - }\ - catch (wxSQLite3Exception e)\ - {\ - std::cerr << req.mb_str() << "\n" ;\ - std::cerr << e.GetMessage().mb_str() << "\n" ;\ - code_if_fail; \ - return return_value;\ - }\ -} while(0); + do{ \ + try \ + { \ + res = _db.ExecuteQuery(req); \ + } \ + catch (wxSQLite3Exception e) \ + { \ + std::cerr << req.mb_str() << "\n" ; \ + std::cerr << e.GetMessage().mb_str() << "\n" ; \ + code_if_fail; \ + return return_value; \ + } \ + } while(0); #define EXECUTE_SQL_QUERY(req, res, return_value) EXECUTE_SQL_QUERY_WITH_CODE(req, res, return_value, {}, {}) @@ -54,62 +54,62 @@ static inline wxString DoubleToString(double d) Database::Database() { - std::ifstream bdd_file; + std::ifstream bdd_file; - bdd_file.open(BDD_FILE); + bdd_file.open(BDD_FILE); - if (!bdd_file) + if (!bdd_file) { - CreateDatabase(); + CreateDatabase(); } - else - _db.Open(wxT(BDD_FILE)); + else + _db.Open(wxT(BDD_FILE)); - bdd_file.close(); + bdd_file.close(); } void Database::CreateDatabase() { - std::ifstream init_script; - std::string line; - wxString wxline; + std::ifstream init_script; + std::string line; + wxString wxline; - wxMessageBox(_("No database found, creating a new one"), wxT("KissCount"), wxICON_EXCLAMATION | wxOK ); + wxMessageBox(_("No database found, creating a new one"), wxT("KissCount"), wxICON_EXCLAMATION | wxOK ); - init_script.open(INIT_SCRIPT); + init_script.open(INIT_SCRIPT); - if (!init_script) + if (!init_script) { - wxMessageBox(_(INIT_SCRIPT " not found, aborting"), _("Error"), wxICON_ERROR | wxOK ); - throw "init.sql not found, aborting"; + wxMessageBox(_(INIT_SCRIPT " not found, aborting"), _("Error"), wxICON_ERROR | wxOK ); + throw "init.sql not found, aborting"; } - _db.Open(wxT(BDD_FILE)); + _db.Open(wxT(BDD_FILE)); - do + do { - getline(init_script, line); - wxline = wxString(line.c_str(), wxConvUTF8); - wxline.Trim(false); - if (!wxline.Length() || wxline.StartsWith(wxT("--"))) continue; - if (!_db.CheckSyntax(wxline)) + getline(init_script, line); + wxline = wxString(line.c_str(), wxConvUTF8); + wxline.Trim(false); + if (!wxline.Length() || wxline.StartsWith(wxT("--"))) continue; + if (!_db.CheckSyntax(wxline)) { - std::cout << line << " is invalid !\n" ; - continue; + std::cout << line << " is invalid !\n" ; + continue; } - try + try { - _db.ExecuteUpdate(wxline); + _db.ExecuteUpdate(wxline); } - catch (...) + catch (...) { - wxMessageBox(_("Error creating original database"), _("Error"), wxICON_ERROR | wxOK ); - remove(BDD_FILE); - throw line; + wxMessageBox(_("Error creating original database"), _("Error"), wxICON_ERROR | wxOK ); + remove(BDD_FILE); + throw line; } } while (init_script); - init_script.close(); + init_script.close(); } @@ -149,7 +149,7 @@ std::list Database::GetUsers() } bool Database::IsValidUser(wxString user, wxString password) - { +{ bool res; wxString req; wxSQLite3ResultSet set; @@ -237,7 +237,7 @@ User* Database::LoadUser(wxString name) category.color = wxColour(set.GetAsString(wxT("color"))); category.font = set.GetAsString(wxT("font")); if (category.name != wxT("Fixe")) - user->_categories.push_back(category); + user->_categories.push_back(category); else user->_categories.insert(user->_categories.begin(), category); } @@ -327,145 +327,145 @@ double Database::GetAccountAmount(wxString id, int month, int year) void Database::UpdateOperation(Operation op) { - wxString req; - req = wxT("UPDATE operation SET ") ; - req += wxT("account='") + op.account + wxT("'"); - req += wxT(", year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); - req += wxT(", month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); - req += wxT(", day='") + wxString::Format(wxT("%d"), op.day) + wxT("'"); - req += wxT(", amount='") + DoubleToString(op.amount) + wxT("'"); - req += wxT(", description=\"") + op.description + wxT("\""); - req += wxT(", category='") + op.category + wxT("'"); - if (op.checked) - req += wxT(", checked='1'"); - else - req += wxT(", checked='0'"); - req += wxT(" WHERE id='") + op.id + wxT("'"); + wxString req; + req = wxT("UPDATE operation SET ") ; + req += wxT("account='") + op.account + wxT("'"); + req += wxT(", year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); + req += wxT(", month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); + req += wxT(", day='") + wxString::Format(wxT("%d"), op.day) + wxT("'"); + req += wxT(", amount='") + DoubleToString(op.amount) + wxT("'"); + req += wxT(", description=\"") + op.description + wxT("\""); + req += wxT(", category='") + op.category + wxT("'"); + if (op.checked) + req += wxT(", checked='1'"); + else + req += wxT(", checked='0'"); + req += wxT(" WHERE id='") + op.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } wxString Database::AddOperation(User* user, Operation op) { wxString req, res; - wxSQLite3ResultSet set; + wxSQLite3ResultSet set; - req = wxT("INSERT INTO operation ('user', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost') VALUES ('") ; - req += user->_id + wxT("'"); - req += wxT(", '") + op.account + wxT("'"); - req += wxT(", '") + wxString::Format(wxT("%d"), op.year) + wxT("'"); - req += wxT(", '") + wxString::Format(wxT("%d"), op.month) + wxT("'"); - req += wxT(", '") + wxString::Format(wxT("%d"), op.day) + wxT("'"); - req += wxT(", '") + DoubleToString(op.amount) + wxT("'"); - req += wxT(", \"") + op.description + wxT("\""); - req += wxT(", '") + op.category + wxT("'"); - if (op.fix_cost) - req += wxT(", '1'") ; - else - req += wxT(", '0'") ; - req += wxT(")"); + req = wxT("INSERT INTO operation ('user', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost') VALUES ('") ; + req += user->_id + wxT("'"); + req += wxT(", '") + op.account + wxT("'"); + req += wxT(", '") + wxString::Format(wxT("%d"), op.year) + wxT("'"); + req += wxT(", '") + wxString::Format(wxT("%d"), op.month) + wxT("'"); + req += wxT(", '") + wxString::Format(wxT("%d"), op.day) + wxT("'"); + req += wxT(", '") + DoubleToString(op.amount) + wxT("'"); + req += wxT(", \"") + op.description + wxT("\""); + req += wxT(", '") + op.category + wxT("'"); + if (op.fix_cost) + req += wxT(", '1'") ; + else + req += wxT(", '0'") ; + req += wxT(")"); - EXECUTE_SQL_UPDATE(req, wxT("0")); + EXECUTE_SQL_UPDATE(req, wxT("0")); - req = wxT("SELECT id FROM operation WHERE "); - req += wxT("user='") + user->_id + wxT("'"); - req += wxT(" AND account='") + op.account + wxT("'"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); - req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); - req += wxT(" AND day='") + wxString::Format(wxT("%d"), op.day) + wxT("'"); - req += wxT(" AND amount='") + DoubleToString(op.amount) + wxT("'"); - req += wxT(" AND description=\"") + op.description + wxT("\""); - req += wxT(" AND category='") + op.category + wxT("'"); - if (op.fix_cost) - req += wxT(" AND fix_cost='1'") ; - else - req += wxT(" AND fix_cost='0'") ; - req += wxT("ORDER BY ID DESC") ; + req = wxT("SELECT id FROM operation WHERE "); + req += wxT("user='") + user->_id + wxT("'"); + req += wxT(" AND account='") + op.account + wxT("'"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); + req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); + req += wxT(" AND day='") + wxString::Format(wxT("%d"), op.day) + wxT("'"); + req += wxT(" AND amount='") + DoubleToString(op.amount) + wxT("'"); + req += wxT(" AND description=\"") + op.description + wxT("\""); + req += wxT(" AND category='") + op.category + wxT("'"); + if (op.fix_cost) + req += wxT(" AND fix_cost='1'") ; + else + req += wxT(" AND fix_cost='0'") ; + req += wxT("ORDER BY ID DESC") ; - EXECUTE_SQL_QUERY(req , set, wxT("0")); + EXECUTE_SQL_QUERY(req , set, wxT("0")); - if (set.NextRow()) - res = set.GetAsString(wxT("id")); - else - res = wxT("0"); + if (set.NextRow()) + res = set.GetAsString(wxT("id")); + else + res = wxT("0"); - set.Finalize(); + set.Finalize(); - return res; + return res; } void Database::DeleteOperation(Operation op) { - wxString req; - req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'"); + wxString req; + req = wxT("DELETE FROM operation WHERE id='") + op.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } void Database::DeleteOperations(User* user, int month, int year) { - wxString req; - std::vector::iterator it; + wxString req; + std::vector::iterator it; - it = user->_accounts.begin(); - req = wxT("DELETE FROM account_amount WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) - { - req += wxT("', '") + it->id ; - } - req += wxT("')"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); - if (month != -1) - req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); + it = user->_accounts.begin(); + req = wxT("DELETE FROM account_amount WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) + { + req += wxT("', '") + it->id ; + } + req += wxT("')"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); + if (month != -1) + req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); - it = user->_accounts.begin(); - req = wxT("DELETE FROM operation WHERE (account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) - { - req += wxT("', '") + it->id ; - } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("')"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); - if (month != -1) - req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); + it = user->_accounts.begin(); + req = wxT("DELETE FROM operation WHERE (account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) + { + req += wxT("', '") + it->id ; + } + req += wxT("')"); + req += wxT(" OR user='") + user->_id + wxT("')"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); + if (month != -1) + req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } void Database::SetAccountAmount(int month, int year, wxString accountId, double amount) { - wxString req; - req = wxT("UPDATE account_amount SET ") ; - req += wxT("amount='") + DoubleToString(amount) + wxT("'"); - req += wxT(" WHERE account='") + accountId + wxT("'"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); - req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); + wxString req; + req = wxT("UPDATE account_amount SET ") ; + req += wxT("amount='") + DoubleToString(amount) + wxT("'"); + req += wxT(" WHERE account='") + accountId + wxT("'"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); + req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); - try - { - if (!_db.ExecuteUpdate(req)) - { - req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; - req += accountId + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), year) + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), month) + wxT("'"); - req += wxT(" ,'") + DoubleToString(amount) + wxT("'"); - req += wxT(")"); - EXECUTE_SQL_UPDATE(req, ); - } - } - catch (wxSQLite3Exception e) - { - std::cerr << req.mb_str() << "\n" ; - std::cerr << e.GetMessage().mb_str() << "\n" ; - return ; - } + try + { + if (!_db.ExecuteUpdate(req)) + { + req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; + req += accountId + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), year) + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), month) + wxT("'"); + req += wxT(" ,'") + DoubleToString(amount) + wxT("'"); + req += wxT(")"); + EXECUTE_SQL_UPDATE(req, ); + } + } + catch (wxSQLite3Exception e) + { + std::cerr << req.mb_str() << "\n" ; + std::cerr << e.GetMessage().mb_str() << "\n" ; + return ; + } } wxString Database::AddAccount(User* user, Account ac) @@ -473,62 +473,62 @@ wxString Database::AddAccount(User* user, Account ac) wxString req, res; wxSQLite3ResultSet set; - req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'default_account') VALUES ('") ; - req += user->_id + wxT("'"); - req += wxT(", '") + ac.name + wxT("'"); - req += wxT(", '") + ac.number + wxT("'"); - if (ac.shared) - req += wxT(", '1'") ; - else - req += wxT(", '0'") ; - if (ac._default) - req += wxT(", '1'") ; - else - req += wxT(", '0'") ; - req += wxT(")"); + req = wxT("INSERT INTO account ('user', 'name', 'number', 'shared', 'default_account') VALUES ('") ; + req += user->_id + wxT("'"); + req += wxT(", '") + ac.name + wxT("'"); + req += wxT(", '") + ac.number + wxT("'"); + if (ac.shared) + req += wxT(", '1'") ; + else + req += wxT(", '0'") ; + if (ac._default) + req += wxT(", '1'") ; + else + req += wxT(", '0'") ; + req += wxT(")"); - EXECUTE_SQL_UPDATE(req, wxT("0")); + EXECUTE_SQL_UPDATE(req, wxT("0")); - req = wxT("SELECT id FROM account WHERE name='") + ac.name + wxT("'") ; - req += wxT("AND user='") + user->_id + wxT("'"); + req = wxT("SELECT id FROM account WHERE name='") + ac.name + wxT("'") ; + req += wxT("AND user='") + user->_id + wxT("'"); - EXECUTE_SQL_QUERY(req , set, wxT("0")); + EXECUTE_SQL_QUERY(req , set, wxT("0")); - if (set.NextRow()) - res = set.GetAsString(wxT("id")); - else - res = wxT("0"); + if (set.NextRow()) + res = set.GetAsString(wxT("id")); + else + res = wxT("0"); - set.Finalize(); + set.Finalize(); - return res; + return res; } void Database::UpdateAccount(Account ac) { - wxString req; - req = wxT("UPDATE account SET ") ; - req += wxT("name='") + ac.name + wxT("'"); - req += wxT(", number='") + ac.number + wxT("'"); - if (ac.shared) - req += wxT(", shared='1'"); - else - req += wxT(", shared='0'"); - if (ac._default) - req += wxT(", default_account='1'"); - else - req += wxT(", default_account='0'"); - req += wxT(" WHERE id='") + ac.id + wxT("'"); + wxString req; + req = wxT("UPDATE account SET ") ; + req += wxT("name='") + ac.name + wxT("'"); + req += wxT(", number='") + ac.number + wxT("'"); + if (ac.shared) + req += wxT(", shared='1'"); + else + req += wxT(", shared='0'"); + if (ac._default) + req += wxT(", default_account='1'"); + else + req += wxT(", default_account='0'"); + req += wxT(" WHERE id='") + ac.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } void Database::DeleteAccount(Account ac) { - wxString req; - req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'"); + wxString req; + req = wxT("DELETE FROM account WHERE id='") + ac.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } wxString Database::AddCategory(User* user, Category category) @@ -589,17 +589,17 @@ void Database::UpdateCategory(Category category) void Database::DeleteCategory(User* user, Category category) { - wxString req; + wxString req; - req = wxT("DELETE FROM category WHERE id='") + category.id + wxT("'"); + req = wxT("DELETE FROM category WHERE id='") + category.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); - req = wxT("UPDATE category SET") ; - req += wxT(" parent='0'"); - req += wxT(" WHERE parent='") + category.id + wxT("'"); + req = wxT("UPDATE category SET") ; + req += wxT(" parent='0'"); + req += wxT(" WHERE parent='") + category.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } std::map > Database::GetAllOperations(User* user) @@ -838,7 +838,7 @@ void Database::NewUser(wxString name) /* Shared accounts not currently supported - */ +*/ void Database::KillMe(User* user) { wxString req; diff --git a/model/Database.h b/model/Database.h index 8024513..5ca3ebc 100644 --- a/model/Database.h +++ b/model/Database.h @@ -49,10 +49,10 @@ class Database void KillMe(User* user); private: - wxSQLite3Database _db; + wxSQLite3Database _db; - void CreateDatabase(); - wxString HashPassword(wxString password); + void CreateDatabase(); + wxString HashPassword(wxString password); }; #endif diff --git a/model/User.cpp b/model/User.cpp index 359b5fc..1937981 100644 --- a/model/User.cpp +++ b/model/User.cpp @@ -1,6 +1,5 @@ #include "User.h" - User::~User() { std::map >* >::iterator it; @@ -49,27 +48,27 @@ wxString User::GetCategoryId(wxString catName) if (it->name == catName) return it->id; - return wxT("0") ; + return wxT("0") ; } wxString User::GetAccountName(wxString accountId) { - std::vector::iterator it; - for (it=_accounts.begin(); it !=_accounts.end(); it++) - if (it->id == accountId) - return it->name; + std::vector::iterator it; + for (it=_accounts.begin(); it !=_accounts.end(); it++) + if (it->id == accountId) + return it->name; - return _("Unknown") ; + return _("Unknown") ; } wxString User::GetAccountId(wxString accountName) { - std::vector::iterator it; - for (it=_accounts.begin(); it !=_accounts.end(); it++) - if (it->name == accountName) - return it->id; + std::vector::iterator it; + for (it=_accounts.begin(); it !=_accounts.end(); it++) + if (it->name == accountName) + return it->id; - return wxT("0") ; + return wxT("0") ; } int User::GetCategoriesNumber() diff --git a/model/User.h b/model/User.h index 8a34576..26207e4 100644 --- a/model/User.h +++ b/model/User.h @@ -12,7 +12,7 @@ class User { -public: + public: ~User(); wxString _id; diff --git a/view/AccountPanel.cpp b/view/AccountPanel.cpp index 9365522..b7db1c1 100644 --- a/view/AccountPanel.cpp +++ b/view/AccountPanel.cpp @@ -3,154 +3,154 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS}; enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS}; enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS}; -enum {CALENDAR_TREE_ID, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID}; +enum {CALENDAR_TREE_ID=1, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID}; static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _(""), _("")}; BEGIN_EVENT_TABLE(AccountPanel, wxPanel) - EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified) - EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, AccountPanel::OnAccountModified) +EVT_GRID_CMD_CELL_CHANGE(OPS_GRID_ID, AccountPanel::OnOperationModified) +EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, AccountPanel::OnAccountModified) EVT_TREE_ITEM_RIGHT_CLICK(CALENDAR_TREE_ID, AccountPanel::OnTreeRightClick) EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange) EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange) - EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate) - EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete) - EVT_SHOW(AccountPanel::OnShow) +EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate) +EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete) +EVT_SHOW(AccountPanel::OnShow) EVT_CALENDAR_SEL_CHANGED(CALENDAR_ID, AccountPanel::OnCalendarChange) END_EVENT_TABLE() AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _curMonth(-1), _curYear(-1), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT) { - wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL); - wxChartPanel* chart ; - int i ; - DEFAULT_FONT(font); - User* user = _kiss->GetUser(); - std::vector::iterator accountIt; - std::vector::iterator categoryIt; - wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86), - wxColour(0xFF, 0x3E, 0x0E), - wxColour(0xFF, 0xD3, 0x20), - wxColour(0x58, 0x9D, 0x1B), - wxColour(0x7E, 0x00, 0x21), - wxColour(0x83, 0xCC, 0xFF), - wxColour(0x31, 0x40, 0x04), - wxColour(0xB0, 0xCF, 0x00), - wxColour(0x4B, 0x1F, 0x6F), - wxColour(0xFF, 0x93, 0x0E), - wxColour(0xC5, 0x00, 0x0D), - wxColour(0x00, 0x84, 0xD1)}; - wxBitmap deleteBitmap(wxT(DELETE_ICON)); - wxBitmap checkedBitmap(wxT(CHECKED_ICON)); + wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL); + wxChartPanel* chart ; + int i ; + DEFAULT_FONT(font); + User* user = _kiss->GetUser(); + std::vector::iterator accountIt; + std::vector::iterator categoryIt; + wxColour categoryColors[] = {wxColour(0x00, 0x45, 0x86), + wxColour(0xFF, 0x3E, 0x0E), + wxColour(0xFF, 0xD3, 0x20), + wxColour(0x58, 0x9D, 0x1B), + wxColour(0x7E, 0x00, 0x21), + wxColour(0x83, 0xCC, 0xFF), + wxColour(0x31, 0x40, 0x04), + wxColour(0xB0, 0xCF, 0x00), + wxColour(0x4B, 0x1F, 0x6F), + wxColour(0xFF, 0x93, 0x0E), + wxColour(0xC5, 0x00, 0x0D), + wxColour(0x00, 0x84, 0xD1)}; + wxBitmap deleteBitmap(wxT(DELETE_ICON)); + wxBitmap checkedBitmap(wxT(CHECKED_ICON)); - SetSizer(hbox); + SetSizer(hbox); - ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors)); + ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors)); - _pie = new PiePlot(); - _calendar = new wxCalendarCtrl(this, CALENDAR_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, - wxCAL_MONDAY_FIRST | wxCAL_NO_MONTH_CHANGE | wxCAL_SEQUENTIAL_MONTH_SELECTION); - _calendar->EnableMonthChange(false); - _calendar->EnableYearChange(false); - _calendar->EnableHolidayDisplay(false); - _calendar->Enable(false); + _pie = new PiePlot(); + _calendar = new wxCalendarCtrl(this, CALENDAR_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, + wxCAL_MONDAY_FIRST | wxCAL_NO_MONTH_CHANGE | wxCAL_SEQUENTIAL_MONTH_SELECTION); + _calendar->EnableMonthChange(false); + _calendar->EnableYearChange(false); + _calendar->EnableHolidayDisplay(false); + _calendar->Enable(false); - _accounts = new wxString[user->GetAccountsNumber()]; - for (i=0, - accountIt = user->_accounts.begin(); - accountIt != user->_accounts.end(); - accountIt++, i++) - _accounts[i] = accountIt->name; + _accounts = new wxString[user->GetAccountsNumber()]; + for (i=0, + accountIt = user->_accounts.begin(); + accountIt != user->_accounts.end(); + accountIt++, i++) + _accounts[i] = accountIt->name; - _categories = new wxString[user->GetCategoriesNumber()] ; - for(i=0, categoryIt = user->_categories.begin(); - categoryIt != user->_categories.end(); - categoryIt++, i++) - { - _categories[i] = categoryIt->name ; - _categoriesIndexes[categoryIt->name] = i; - } + _categories = new wxString[user->GetCategoriesNumber()] ; + for(i=0, categoryIt = user->_categories.begin(); + categoryIt != user->_categories.end(); + categoryIt++, i++) + { + _categories[i] = categoryIt->name ; + _categoriesIndexes[categoryIt->name] = i; + } - _dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber()); + _dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber()); - _categoriesValues = new double[user->GetCategoriesNumber()]; - for(i=0; iGetCategoriesNumber(); i++) - _categoriesValues[i] = 0.0; + _categoriesValues = new double[user->GetCategoriesNumber()]; + for(i=0; iGetCategoriesNumber(); i++) + _categoriesValues[i] = 0.0; - _dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber()); - _dataset->SetRenderer(new CategoryRenderer(*colorScheme)); - _pie->SetDataset(_dataset); - _pie->SetColorScheme(colorScheme); + _dataset->AddSerie(_("Serie 1"), _categoriesValues, user->GetCategoriesNumber()); + _dataset->SetRenderer(new CategoryRenderer(*colorScheme)); + _pie->SetDataset(_dataset); + _pie->SetColorScheme(colorScheme); - _pie->SetLegend(new Legend(wxBOTTOM, wxCENTER)); + _pie->SetLegend(new Legend(wxBOTTOM, wxCENTER)); - _grid = new GridAccount(this, OPS_GRID_ID); - _grid->CreateGrid(1, NUMBER_COLS_OPS); - _grid->SetColLabelSize(0); - _grid->SetRowLabelSize(0); + _grid = new GridAccount(this, OPS_GRID_ID); + _grid->CreateGrid(1, NUMBER_COLS_OPS); + _grid->SetColLabelSize(0); + _grid->SetRowLabelSize(0); - _grid->CreateGrid(1, NUMBER_COLS_OPS); - _grid->SetColSize (0, _grid->GetColSize(0)*3); - _grid->SetDefaultCellFont(font); + _grid->CreateGrid(1, NUMBER_COLS_OPS); + _grid->SetColSize (0, _grid->GetColSize(0)*3); + _grid->SetDefaultCellFont(font); - font.SetWeight(wxFONTWEIGHT_BOLD); - for(i=0; iSetCellValue(0, i, colsName[i]); - _grid->SetCellBackgroundColour(0, i, OWN_CYAN); - _grid->SetCellFont(0, i, font); - _grid->SetReadOnly(0, i, true); - _grid->SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE); - } - _grid->SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(deleteBitmap)); - _grid->SetCellRenderer(0, CHECKED, new wxGridCellBitmapRenderer(checkedBitmap)); + font.SetWeight(wxFONTWEIGHT_BOLD); + for(i=0; iSetCellValue(0, i, colsName[i]); + _grid->SetCellBackgroundColour(0, i, OWN_CYAN); + _grid->SetCellFont(0, i, font); + _grid->SetReadOnly(0, i, true); + _grid->SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE); + } + _grid->SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(deleteBitmap)); + _grid->SetCellRenderer(0, CHECKED, new wxGridCellBitmapRenderer(checkedBitmap)); - font.SetWeight(wxFONTWEIGHT_NORMAL); + font.SetWeight(wxFONTWEIGHT_NORMAL); - _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID); - _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNTS); - _accountsGrid->SetRowLabelSize(0); + _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID); + _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNTS); + _accountsGrid->SetRowLabelSize(0); - _accountsGrid->SetDefaultCellFont(font); + _accountsGrid->SetDefaultCellFont(font); - _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Account number")); - _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Account name")); - _accountsGrid->SetColLabelValue(ACCOUNT_INIT, _("Initial value")); - _accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value")); - _accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value")); + _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Account number")); + _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Account name")); + _accountsGrid->SetColLabelValue(ACCOUNT_INIT, _("Initial value")); + _accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value")); + _accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value")); - _accountsGrid->AutoSizeColumns(true); + _accountsGrid->AutoSizeColumns(true); - _statsGrid = new wxGrid(this, -1); + _statsGrid = new wxGrid(this, -1); - chart = new wxChartPanel(this); - chart->SetChart(new Chart(_pie, _("Cost repartition"))); - chart->Fit(); - chart->Layout(); - chart->SetMinSize(// chart->GetSize() - wxSize(200,250)); - hbox->Add(&_tree, 0); - hbox2->Add(_accountsGrid, 0); - hbox2->Add(_calendar, 0); - vbox2->Add(hbox2, 0); - vbox2->Add(-1, 10); - vbox2->Add(_grid, 0); - hbox->Add(vbox2, 0); - vbox->Add(_statsGrid, 0); - vbox->Add(-1, 10); - vbox->Add(chart, 0); - hbox->Add(-1, 10); - hbox->Add(vbox, 0); + chart = new wxChartPanel(this); + chart->SetChart(new Chart(_pie, _("Cost repartition"))); + chart->Fit(); + chart->Layout(); + chart->SetMinSize(// chart->GetSize() + wxSize(200,250)); + hbox->Add(&_tree, 0); + hbox2->Add(_accountsGrid, 0); + hbox2->Add(_calendar, 0); + vbox2->Add(hbox2, 0); + vbox2->Add(-1, 10); + vbox2->Add(_grid, 0); + hbox->Add(vbox2, 0); + vbox->Add(_statsGrid, 0); + vbox->Add(-1, 10); + vbox->Add(chart, 0); + hbox->Add(-1, 10); + hbox->Add(vbox, 0); - ChangeUser(); + ChangeUser(); - Fit(); + Fit(); - SetMinSize(wxSize(1024, 640)); - SetScrollbars(10, 10, 100/10, 100/10); + SetMinSize(wxSize(1024, 640)); + SetScrollbars(10, 10, 100/10, 100/10); } AccountPanel::~AccountPanel() @@ -164,48 +164,48 @@ void AccountPanel::InitStatsGrid(User* user) { int i; - DEFAULT_FONT(font); + DEFAULT_FONT(font); - if (!_statsGrid->GetNumberRows()) - { - _statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2); - _statsGrid->SetColLabelSize(0); - _statsGrid->SetRowLabelSize(0); - _statsGrid->EnableEditing(false); - } - else - { - _statsGrid->DeleteRows(0, _statsGrid->GetNumberRows()); - _statsGrid->InsertRows(0, user->GetCategoriesNumber()+6); - } + if (!_statsGrid->GetNumberRows()) + { + _statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2); + _statsGrid->SetColLabelSize(0); + _statsGrid->SetRowLabelSize(0); + _statsGrid->EnableEditing(false); + } + else + { + _statsGrid->DeleteRows(0, _statsGrid->GetNumberRows()); + _statsGrid->InsertRows(0, user->GetCategoriesNumber()+6); + } - _statsGrid->SetDefaultCellFont(font); + _statsGrid->SetDefaultCellFont(font); - _statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit")); - _statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit")); + _statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit")); + _statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit")); - _statsGrid->AutoSizeColumn(0, false); + _statsGrid->AutoSizeColumn(0, false); - for(i=0; iGetCategoriesNumber(); i++) - { - _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]); - _statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); - } - font.SetWeight(wxFONTWEIGHT_BOLD); - _statsGrid->SetCellFont(CUR_CREDIT, 0, font); - _statsGrid->SetCellFont(CUR_DEBIT, 0, font); - _statsGrid->SetCellFont(REMAINS, 0, font); - _statsGrid->SetCellFont(REMAINS, 1, font); + for(i=0; iGetCategoriesNumber(); i++) + { + _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]); + _statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + } + font.SetWeight(wxFONTWEIGHT_BOLD); + _statsGrid->SetCellFont(CUR_CREDIT, 0, font); + _statsGrid->SetCellFont(CUR_DEBIT, 0, font); + _statsGrid->SetCellFont(REMAINS, 0, font); + _statsGrid->SetCellFont(REMAINS, 1, font); - _statsGrid->SetCellValue(CUR_CREDIT, 0, _("Cur Credit")); - _statsGrid->SetCellValue(CUR_DEBIT, 0, _("Cur Debit")); - _statsGrid->SetCellValue(REMAINS, 0, _("Remains")); + _statsGrid->SetCellValue(CUR_CREDIT, 0, _("Cur Credit")); + _statsGrid->SetCellValue(CUR_DEBIT, 0, _("Cur Debit")); + _statsGrid->SetCellValue(REMAINS, 0, _("Remains")); - _statsGrid->SetCellAlignment(CUR_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); - _statsGrid->SetCellAlignment(CUR_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); - _statsGrid->SetCellAlignment(TOTAL_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); - _statsGrid->SetCellAlignment(TOTAL_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); - _statsGrid->SetCellAlignment(REMAINS, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellAlignment(CUR_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellAlignment(CUR_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellAlignment(TOTAL_DEBIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellAlignment(TOTAL_CREDIT, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellAlignment(REMAINS, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); } void AccountPanel::ChangeUser() @@ -289,8 +289,8 @@ void AccountPanel::LoadYear(int year, bool showMonth) } #define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color);\ + { \ + _grid->SetCellBackgroundColour(row, i, color); \ } void AccountPanel::ShowMonth(int month, int year) @@ -384,32 +384,32 @@ void AccountPanel::ShowMonth(int month, int year) void AccountPanel::InsertOperation(User* user, Operation* op, int line, bool fix) { - std::vector::iterator it; - int curLine, curWeek, week, i; - int r, g, b; - wxColour color; + std::vector::iterator it; + int curLine, curWeek, week, i; + int r, g, b; + wxColour color; - if (!op && !user->_accounts.size()) return; + if (!op && !user->_accounts.size()) return; - _grid->InsertRows(line, 1); + _grid->InsertRows(line, 1); - _grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2)); - _grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2)); - wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false); - _grid->SetCellEditor(line, ACCOUNT, accountEditor); - wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false); - _grid->SetCellEditor(line, CATEGORY, categoryEditor); + _grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2)); + _grid->SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(-1, 2)); + wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false); + _grid->SetCellEditor(line, ACCOUNT, accountEditor); + wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false); + _grid->SetCellEditor(line, CATEGORY, categoryEditor); - if (fix) + if (fix) { - _fixCosts++; - _grid->SetCellValue(line, CATEGORY, _("Fixe")); - _grid->SetReadOnly(line, CATEGORY); + _fixCosts++; + _grid->SetCellValue(line, CATEGORY, _("Fixe")); + _grid->SetReadOnly(line, CATEGORY); } - if (op) + if (op) { - _grid->SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year)); + _grid->SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year)); _grid->SetCellValue(line, DESCRIPTION, op->description); _grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year)); if (op->amount < 0) @@ -427,56 +427,56 @@ void AccountPanel::InsertOperation(User* user, Operation* op, int line, bool fix color = user->GetCategory(op->category).color; if (op->checked) - { + { r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; color.Set(r, g, b, color.Alpha()); _grid->SetCellValue(line, CHECKED, wxT("1")); - } + } SET_ROW_COLOR(line, color); } - else - { - _grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear)); - if (fix) - SET_ROW_COLOR(line, OWN_YELLOW) - else - SET_ROW_COLOR(line, OWN_GREEN); - _grid->SetReadOnly(line, CHECKED, true); - _grid->SetReadOnly(line, DELETE, true); - } - - _grid->SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE); - _grid->SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE); - _grid->SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - _grid->SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE); - - if (op) + else { - for (it = _curOperations->begin(), curLine=1; - it->fix_cost && it != _curOperations->end(); - it++, curLine++) ; + _grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear)); + if (fix) + SET_ROW_COLOR(line, OWN_YELLOW) + else + SET_ROW_COLOR(line, OWN_GREEN); + _grid->SetReadOnly(line, CHECKED, true); + _grid->SetReadOnly(line, DELETE, true); + } + + _grid->SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE); + _grid->SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE); + _grid->SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + _grid->SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE); - if (it == _curOperations->end()) return; + if (op) + { + for (it = _curOperations->begin(), curLine=1; + it->fix_cost && it != _curOperations->end(); + it++, curLine++) ; - curLine++; - curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth(); - for (i=1, it++; it != _curOperations->end(); it++, curLine++) + if (it == _curOperations->end()) return; + + curLine++; + curWeek = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth(); + for (i=1, it++; it != _curOperations->end(); it++, curLine++) { - week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth(); - if (week != curWeek) + week = wxDateTime(it->day+1, (wxDateTime::Month)it->month, it->year).GetWeekOfMonth(); + if (week != curWeek) { - _grid->SetWeek(i++, curLine); - curWeek = week; + _grid->SetWeek(i++, curLine); + curWeek = week; } } } - _grid->Layout(); - _grid->SetMinSize(_grid->GetMinSize()); - _wxUI->Layout(); + _grid->Layout(); + _grid->SetMinSize(_grid->GetMinSize()); + _wxUI->Layout(); } void AccountPanel::InitAccountsGrid(User* user, int month, int year) @@ -607,119 +607,119 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) inModification = true ; if (event.GetCol() == DEBIT) - _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); + _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); else if (event.GetCol() == CREDIT) - _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); + _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); value = _grid->GetCellValue(event.GetRow(), DESCRIPTION); if (value != wxT("")) - { + { new_op.description = value; op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), DATE); if (value != wxT("")) - { + { date.ParseFormat(value, wxT("%d/%m/%Y")); new_op.day = date.GetDay()-1; new_op.month = date.GetMonth(); new_op.year = date.GetYear(); op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), DEBIT); if (value != wxT("")) - { + { value.ToDouble(&new_op.amount); new_op.amount *= -1.0; op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), CREDIT); if (value != wxT("")) - { + { value.ToDouble(&new_op.amount); op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), CATEGORY); if (value != wxT("")) - { + { new_op.category = user->GetCategoryId(value); op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), ACCOUNT); if (value != wxT("")) - { + { new_op.account = user->GetAccountId(value); op_complete--; - } + } value = _grid->GetCellValue(event.GetRow(), CHECKED); if (value != wxT("") && value != wxT("0")) - new_op.checked = true; + new_op.checked = true; else - new_op.checked = false; + new_op.checked = false; op_complete--; if (col == CHECKED || col == CATEGORY) - { + { color = user->GetCategory(new_op.category).color; if (new_op.checked) - { + { r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ; g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ; b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ; color.Set(r, g, b, color.Alpha()); - } + } SET_ROW_COLOR(event.GetRow(), color); - } + } if (col == DELETE) - { + { wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_op.description, wxT("KissCount"), wxYES_NO); if (dialog.ShowModal() == wxID_NO) - { + { _grid->SetCellValue(event.GetRow(), event.GetCol(), wxT("0")); inModification = false; return; - } - } + } + } // Penser au fix implosif // Modify a fix operation if (row < _fixCosts) { - cur_op = (*_curOperations)[row] ; + cur_op = (*_curOperations)[row] ; - if (col == DELETE) + if (col == DELETE) { - _grid->DeleteRows(event.GetRow(), 1); - _curOperations->erase(_curOperations->begin()+row); - _kiss->DeleteOperation(cur_op); - _grid->_fixCosts = _fixCosts--; - UpdateStats(); - inModification = false ; - return ; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); + _kiss->DeleteOperation(cur_op); + _grid->_fixCosts = _fixCosts--; + UpdateStats(); + inModification = false ; + return ; } - new_op.id = cur_op.id; - new_op.fix_cost = true; - if (cur_op.day != new_op.day) + new_op.id = cur_op.id; + new_op.fix_cost = true; + if (cur_op.day != new_op.day) { - need_insertion = true; - _grid->DeleteRows(event.GetRow(), 1); - _curOperations->erase(_curOperations->begin()+row); - _fixCosts--; + need_insertion = true; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); + _fixCosts--; } - else - (*_curOperations)[row] = new_op; - _kiss->UpdateOperation(new_op); - fix_op = true; + else + (*_curOperations)[row] = new_op; + _kiss->UpdateOperation(new_op); + fix_op = true; } // Add a fixCost else if (row == _fixCosts) @@ -742,30 +742,30 @@ void AccountPanel::OnOperationModified(wxGridEvent& event) // Modify an operation else if (row <= user->GetOperationsNumber(_curMonth, _curYear)) { - row--; - cur_op = (*_curOperations)[row] ; - new_op.id = cur_op.id; - new_op.fix_cost = false; + row--; + cur_op = (*_curOperations)[row] ; + new_op.id = cur_op.id; + new_op.fix_cost = false; - if (col == DELETE) + if (col == DELETE) { - _grid->DeleteRows(event.GetRow(), 1); - _curOperations->erase(_curOperations->begin()+row); - _kiss->DeleteOperation(cur_op); - UpdateStats(); - inModification = false ; - return ; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); + _kiss->DeleteOperation(cur_op); + UpdateStats(); + inModification = false ; + return ; } - if (cur_op.day != new_op.day) + if (cur_op.day != new_op.day) { - need_insertion = true; - _grid->DeleteRows(event.GetRow(), 1); - _curOperations->erase(_curOperations->begin()+row); + need_insertion = true; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); } - else - (*_curOperations)[row] = new_op; - _kiss->UpdateOperation(new_op); + else + (*_curOperations)[row] = new_op; + _kiss->UpdateOperation(new_op); } // Add an operation else @@ -972,7 +972,7 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event) wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO); if (dialog.ShowModal() == wxID_NO) - return; + return; curNode = _tree.GetSelection(); diff --git a/view/AccountPanel.h b/view/AccountPanel.h index 4c8db52..abfe0f8 100644 --- a/view/AccountPanel.h +++ b/view/AccountPanel.h @@ -32,7 +32,7 @@ class KissCount; class AccountPanel: public wxScrolledWindow { -public: + public: AccountPanel(KissCount* kiss, wxUI *parent); ~AccountPanel(); void ChangeUser(); @@ -51,7 +51,7 @@ public: int _curMonth, _curYear; -private: + private: KissCount* _kiss; wxUI* _wxUI; wxTreeCtrl _tree; diff --git a/view/ButtonPanel.cpp b/view/ButtonPanel.cpp index f05234a..a156470 100644 --- a/view/ButtonPanel.cpp +++ b/view/ButtonPanel.cpp @@ -1,25 +1,25 @@ #include "ButtonPanel.h" -enum {ID_BUTTON_ACCOUNT=1, ID_BUTTON_STATS, ID_BUTTON_SEARCH, ID_BUTTON_PREFS, ID_BUTTON_CHANGE_USER, ID_BUTTON_ABOUT, ID_BUTTON_QUIT}; +enum {BUTTON_ACCOUNT_ID=1, BUTTON_STATS_ID, BUTTON_SEARCH_ID, BUTTON_PREFS_ID, BUTTON_CHANGE_USER_ID, BUTTON_ABOUT_ID, BUTTON_QUIT_ID}; BEGIN_EVENT_TABLE(ButtonPanel, wxPanel) -EVT_BUTTON(ID_BUTTON_ACCOUNT, ButtonPanel::OnButtonAccount) -EVT_BUTTON(ID_BUTTON_PREFS, ButtonPanel::OnButtonPreferences) -EVT_BUTTON(ID_BUTTON_CHANGE_USER, ButtonPanel::OnButtonChangeUser) -EVT_BUTTON(ID_BUTTON_ABOUT, ButtonPanel::OnButtonAbout) -EVT_BUTTON(ID_BUTTON_QUIT, ButtonPanel::OnButtonQuit) +EVT_BUTTON(BUTTON_ACCOUNT_ID, ButtonPanel::OnButtonAccount) +EVT_BUTTON(BUTTON_PREFS_ID, ButtonPanel::OnButtonPreferences) +EVT_BUTTON(BUTTON_CHANGE_USER_ID, ButtonPanel::OnButtonChangeUser) +EVT_BUTTON(BUTTON_ABOUT_ID, ButtonPanel::OnButtonAbout) +EVT_BUTTON(BUTTON_QUIT_ID, ButtonPanel::OnButtonQuit) END_EVENT_TABLE() ButtonPanel::ButtonPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent) { wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - _account = new wxBitmapButton(this, ID_BUTTON_ACCOUNT, wxBitmap(wxT(ACCOUNT_ICON)), wxDefaultPosition, wxSize(128, 128)); - _stats = new wxBitmapButton(this, ID_BUTTON_STATS, wxBitmap(wxT(STATS_ICON)), wxDefaultPosition, wxSize(128, 128)); - _search = new wxBitmapButton(this, ID_BUTTON_SEARCH, wxBitmap(wxT(SEARCH_ICON)), wxDefaultPosition, wxSize(128, 128)); - _prefs = new wxBitmapButton(this, ID_BUTTON_PREFS, wxBitmap(wxT(PREFS_ICON)), wxDefaultPosition, wxSize(128, 128)); - _changeUser = new wxBitmapButton(this, ID_BUTTON_CHANGE_USER, wxBitmap(wxT(CHANGE_USER_ICON)), wxDefaultPosition, wxSize(128, 128)); - _about = new wxBitmapButton(this, ID_BUTTON_ABOUT, wxBitmap(wxT(ABOUT_ICON)), wxDefaultPosition, wxSize(128, 128)); - _quit = new wxBitmapButton(this, ID_BUTTON_QUIT, wxBitmap(wxT(QUIT_ICON)), wxDefaultPosition, wxSize(128, 128)); + _account = new wxBitmapButton(this, BUTTON_ACCOUNT_ID, wxBitmap(wxT(ACCOUNT_ICON)), wxDefaultPosition, wxSize(128, 128)); + _stats = new wxBitmapButton(this, BUTTON_STATS_ID, wxBitmap(wxT(STATS_ICON)), wxDefaultPosition, wxSize(128, 128)); + _search = new wxBitmapButton(this, BUTTON_SEARCH_ID, wxBitmap(wxT(SEARCH_ICON)), wxDefaultPosition, wxSize(128, 128)); + _prefs = new wxBitmapButton(this, BUTTON_PREFS_ID, wxBitmap(wxT(PREFS_ICON)), wxDefaultPosition, wxSize(128, 128)); + _changeUser = new wxBitmapButton(this, BUTTON_CHANGE_USER_ID, wxBitmap(wxT(CHANGE_USER_ICON)), wxDefaultPosition, wxSize(128, 128)); + _about = new wxBitmapButton(this, BUTTON_ABOUT_ID, wxBitmap(wxT(ABOUT_ICON)), wxDefaultPosition, wxSize(128, 128)); + _quit = new wxBitmapButton(this, BUTTON_QUIT_ID, wxBitmap(wxT(QUIT_ICON)), wxDefaultPosition, wxSize(128, 128)); SetSizer(hbox); @@ -60,7 +60,7 @@ void ButtonPanel::OnButtonChangeUser(wxCommandEvent& event) void ButtonPanel::OnButtonAbout(wxCommandEvent& event) { - wxMessageBox( _("KissCount v0.1\n\nLogiciel de comptabilité\n\nCopyright (C) 2010 Grégory Soutadé"), + wxMessageBox( _("KissCount v0.1\n\nPersonal accounting software\n\nCopyright (C) 2010 Grégory Soutadé"), wxT("KissCount"), wxOK | wxICON_INFORMATION, _wxUI ); } diff --git a/view/ButtonPanel.h b/view/ButtonPanel.h index 3418efc..9217f2a 100644 --- a/view/ButtonPanel.h +++ b/view/ButtonPanel.h @@ -20,7 +20,7 @@ class wxUI; class ButtonPanel: public wxPanel { -public: + public: ButtonPanel(KissCount* kiss, wxUI *parent); ~ButtonPanel(); @@ -31,7 +31,7 @@ public: void OnButtonAbout(wxCommandEvent& event); void OnButtonQuit(wxCommandEvent& event); -private: + private: KissCount* _kiss; wxUI* _wxUI; wxBitmapButton* _account; diff --git a/view/CalendarEditor.cpp b/view/CalendarEditor.cpp index 164c99a..2e00123 100644 --- a/view/CalendarEditor.cpp +++ b/view/CalendarEditor.cpp @@ -46,19 +46,19 @@ void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHa bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid) { - grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ; + grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ; return true; } void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid) { - grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year)) ; + grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ; } wxString CalendarEditor::GetValue() const { - return wxString::Format(wxT("%02d/%02d/%d"), _day, _month+1, _year); + return wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year); } void CalendarEditor::Reset() @@ -88,5 +88,5 @@ bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event) void CalendarEditor::OnDateChanged(wxCommandEvent& event) { - _day = _editor->GetSelection()+1; + _day = _editor->GetSelection(); } diff --git a/view/CalendarEditor.h b/view/CalendarEditor.h index 3c8b704..c27f766 100644 --- a/view/CalendarEditor.h +++ b/view/CalendarEditor.h @@ -10,7 +10,7 @@ class CalendarEditor : public wxGridCellChoiceEditor, public wxEvtHandler { -public: + public: CalendarEditor(int day, int month, int year); ~CalendarEditor(); @@ -29,7 +29,7 @@ public: void StartingClick(); bool IsAcceptedKey(wxKeyEvent &event); -private: + private: int _day; int _month; int _year; diff --git a/view/GenerateDialog.cpp b/view/GenerateDialog.cpp index b96285d..0a82784 100644 --- a/view/GenerateDialog.cpp +++ b/view/GenerateDialog.cpp @@ -136,7 +136,7 @@ void GenerateDialog::OnYearFromChange(wxCommandEvent& event) year = wxAtoi(years); for(it=_ops[year].begin(); it!=_ops[year].end(); it++) - _monthFrom->Append(months[*it]); + _monthFrom->Append(months[*it]); _monthFrom->Select(0); Layout(); diff --git a/view/GenerateDialog.h b/view/GenerateDialog.h index 615ab7a..a84168f 100644 --- a/view/GenerateDialog.h +++ b/view/GenerateDialog.h @@ -15,7 +15,7 @@ class KissCount; class GenerateDialog : public wxDialog { -public: + public: GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year); void OnYearFromChange(wxCommandEvent& event); @@ -23,13 +23,13 @@ public: void OnOK(wxCommandEvent& event); void OnCancel(wxCommandEvent& event); -private: + private: KissCount* _kiss; wxUI* _wxUI; wxChoice* _yearFrom, *_monthFrom, *_yearTo, *_monthTo; std::map > _ops; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE(); }; #endif diff --git a/view/GridAccount.h b/view/GridAccount.h index 5c50c1c..71cc6b7 100644 --- a/view/GridAccount.h +++ b/view/GridAccount.h @@ -8,8 +8,8 @@ class GridAccount : public wxGrid { -public: - GridAccount(wxWindow *parent, wxWindowID id) : wxGrid(parent, id) {} + public: + GridAccount(wxWindow *parent, wxWindowID id) : wxGrid(parent, id) {} wxPen GetColGridLinePen (int col) {return wxPen(*wxBLACK, 1, wxSOLID);} wxPen GetRowGridLinePen (int row) { if (row == 0 || row == _fixCosts || @@ -23,16 +23,17 @@ public: } void SetWeek(int week, int line) { - switch (week) { - case 1: _week1 = line; break; - case 2: _week2 = line; break; - case 3: _week3 = line; break; - case 4: _week4 = line; break; - } + switch (week) { + case 1: _week1 = line; break; + case 2: _week2 = line; break; + case 3: _week3 = line; break; + case 4: _week4 = line; break; + } } int _fixCosts; int _week1, _week2, _week3, _week4; -private: + + private: std::list _col; }; #endif diff --git a/view/PasswordDialog.h b/view/PasswordDialog.h index 0f68244..b5d333e 100644 --- a/view/PasswordDialog.h +++ b/view/PasswordDialog.h @@ -15,17 +15,17 @@ class KissCount; class PasswordDialog : public wxDialog { -public: + public: PasswordDialog(KissCount* kiss, wxUI *parent); void OnOK(wxCommandEvent& event); void OnCancel(wxCommandEvent& event); -private: + private: KissCount* _kiss; wxUI* _wxUI; wxTextCtrl* _oldPassword, *_newPassword, *_confirmPassword; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE(); }; #endif diff --git a/view/PreferencesPanel.cpp b/view/PreferencesPanel.cpp index 8f12d8f..6017580 100644 --- a/view/PreferencesPanel.cpp +++ b/view/PreferencesPanel.cpp @@ -3,101 +3,101 @@ enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT}; enum {CATEGORY_NAME, CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY}; -enum {CATEGORIES_GRID_ID=20, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID}; +enum {CATEGORIES_GRID_ID=1, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID}; BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel) EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName) EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword) EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe) - EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified) - EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified) +EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified) +EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified) EVT_SHOW(PreferencesPanel::OnShow) END_EVENT_TABLE() PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent) { - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - wxStaticBox* staticUser, *staticAccount, *staticCategories; - User* user = _kiss->GetUser(); - wxGridBagSizer *gridBagSizer; - wxStaticText* label; - wxButton* buttonChangeName, *buttonChangePassword, *killMe; - wxStaticBoxSizer * staticBoxSizer; + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + wxStaticBox* staticUser, *staticAccount, *staticCategories; + User* user = _kiss->GetUser(); + wxGridBagSizer *gridBagSizer; + wxStaticText* label; + wxButton* buttonChangeName, *buttonChangePassword, *killMe; + wxStaticBoxSizer * staticBoxSizer; - SetSizer(vbox); + SetSizer(vbox); - staticUser = new wxStaticBox(this, -1, _("User")); - staticAccount = new wxStaticBox(this, -1, _("Accounts")); - staticCategories = new wxStaticBox(this, -1, _("Categories")); + staticUser = new wxStaticBox(this, -1, _("User")); + staticAccount = new wxStaticBox(this, -1, _("Accounts")); + staticCategories = new wxStaticBox(this, -1, _("Categories")); - // User - staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL); + // User + staticBoxSizer = new wxStaticBoxSizer (staticUser, wxVERTICAL); - gridBagSizer = new wxGridBagSizer(10, 10); - staticBoxSizer->Add(gridBagSizer); + gridBagSizer = new wxGridBagSizer(10, 10); + staticBoxSizer->Add(gridBagSizer); - label = new wxStaticText(this, -1, _("Name")); - gridBagSizer->Add(label, wxGBPosition(0, 0)); + label = new wxStaticText(this, -1, _("Name")); + gridBagSizer->Add(label, wxGBPosition(0, 0)); - _name = new wxTextCtrl(this, NAME_ID, user->_name); - gridBagSizer->Add(_name, wxGBPosition(0, 1)); + _name = new wxTextCtrl(this, NAME_ID, user->_name); + gridBagSizer->Add(_name, wxGBPosition(0, 1)); - buttonChangeName = new wxButton(this, CHANGE_NAME_ID, _("Change Name")); - buttonChangePassword = new wxButton(this, CHANGE_PASSWORD_ID, _("Change Password")); - killMe = new wxButton(this, KILL_ME_ID, _("Kill me")); + buttonChangeName = new wxButton(this, CHANGE_NAME_ID, _("Change Name")); + buttonChangePassword = new wxButton(this, CHANGE_PASSWORD_ID, _("Change Password")); + killMe = new wxButton(this, KILL_ME_ID, _("Kill me")); - gridBagSizer->Add(buttonChangeName, wxGBPosition(1, 0)); - gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1)); - gridBagSizer->Add(killMe, wxGBPosition(1, 2)); + gridBagSizer->Add(buttonChangeName, wxGBPosition(1, 0)); + gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1)); + gridBagSizer->Add(killMe, wxGBPosition(1, 2)); - vbox->Add(staticBoxSizer); - vbox->Add(-1, 20); + vbox->Add(staticBoxSizer); + vbox->Add(-1, 20); - // Account - staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL); + // Account + staticBoxSizer = new wxStaticBoxSizer (staticAccount, wxVERTICAL); - _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID); + _accountsGrid = new wxGrid(this, ACCOUNTS_GRID_ID); - InitAccounts(user); + InitAccounts(user); - staticBoxSizer->Add(_accountsGrid); + staticBoxSizer->Add(_accountsGrid); - vbox->Add(staticBoxSizer); - vbox->Add(-1, 20); + vbox->Add(staticBoxSizer); + vbox->Add(-1, 20); - // Categories - staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL); + // Categories + staticBoxSizer = new wxStaticBoxSizer (staticCategories, wxVERTICAL); - _categoriesGrid = new wxGrid(this, CATEGORIES_GRID_ID); + _categoriesGrid = new wxGrid(this, CATEGORIES_GRID_ID); - staticBoxSizer->Add(_categoriesGrid); + staticBoxSizer->Add(_categoriesGrid); - InitCategories(user); + InitCategories(user); - vbox->Add(staticBoxSizer); + vbox->Add(staticBoxSizer); - Fit(); - SetMinSize(GetSize()); + Fit(); + SetMinSize(GetSize()); - Hide(); + Hide(); } void PreferencesPanel::InitAccounts(User* user) { - std::vector::iterator it; - int curLine = 0; - Account account ; - DEFAULT_FONT(font); + std::vector::iterator it; + int curLine = 0; + Account account ; + DEFAULT_FONT(font); - _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNT); - _accountsGrid->SetRowLabelSize(0); - _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name")); - _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number")); - _accountsGrid->SetColLabelValue(ACCOUNT_SHARED, _("Shared")); - _accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default")); - _accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete")); - _accountsGrid->SetDefaultCellFont(font); + _accountsGrid->CreateGrid(0, NUMBER_COLS_ACCOUNT); + _accountsGrid->SetRowLabelSize(0); + _accountsGrid->SetColLabelValue(ACCOUNT_NAME, _("Name")); + _accountsGrid->SetColLabelValue(ACCOUNT_NUMBER, _("Number")); + _accountsGrid->SetColLabelValue(ACCOUNT_SHARED, _("Shared")); + _accountsGrid->SetColLabelValue(ACCOUNT_DEFAULT, _("Default")); + _accountsGrid->SetColLabelValue(ACCOUNT_DELETE, _("Delete")); + _accountsGrid->SetDefaultCellFont(font); for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++) { @@ -128,52 +128,52 @@ void PreferencesPanel::InitAccounts(User* user) _accountsGrid->SetReadOnly(curLine, ACCOUNT_DELETE, true); } -#define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color);\ +#define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color); \ } void PreferencesPanel::InitCategories(User* user) { - std::vector::iterator it; - int curLine = 0; - DEFAULT_FONT(font); + std::vector::iterator it; + int curLine = 0; + DEFAULT_FONT(font); - _categoriesGrid->CreateGrid(0, NUMBER_COLS_CATEGORY); - _categoriesGrid->SetRowLabelSize(0); - _categoriesGrid->SetDefaultCellFont(font); + _categoriesGrid->CreateGrid(0, NUMBER_COLS_CATEGORY); + _categoriesGrid->SetRowLabelSize(0); + _categoriesGrid->SetDefaultCellFont(font); - _categoriesGrid->SetColLabelValue(CATEGORY_NAME, _("Name")); - _categoriesGrid->SetColLabelValue(CATEGORY_COLOR, _("Color")); - _categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font")); - _categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete")); + _categoriesGrid->SetColLabelValue(CATEGORY_NAME, _("Name")); + _categoriesGrid->SetColLabelValue(CATEGORY_COLOR, _("Color")); + _categoriesGrid->SetColLabelValue(CATEGORY_FONT, _("Font")); + _categoriesGrid->SetColLabelValue(CATEGORY_DELETE, _("Delete")); - for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++) + for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++) { - _categoriesGrid->AppendRows(); + _categoriesGrid->AppendRows(); - _categoriesGrid->SetCellValue(curLine, CATEGORY_NAME, it->name); - SET_ROW_COLOR(curLine, it->color); - if (curLine) + _categoriesGrid->SetCellValue(curLine, CATEGORY_NAME, it->name); + SET_ROW_COLOR(curLine, it->color); + if (curLine) { - _categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + _categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); + _categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellBoolEditor ()); } - _categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); - _categoriesGrid->SetCellAlignment(curLine, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(curLine, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); } - _categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true); - _categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true); - _categoriesGrid->AutoSizeColumns(true); + _categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true); + _categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true); + _categoriesGrid->AutoSizeColumns(true); - _categoriesGrid->AppendRows(); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_COLOR, true); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_FONT, true); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_DELETE, true); - SET_ROW_COLOR(curLine, OWN_GREEN); + _categoriesGrid->AppendRows(); + _categoriesGrid->SetReadOnly(curLine, CATEGORY_COLOR, true); + _categoriesGrid->SetReadOnly(curLine, CATEGORY_FONT, true); + _categoriesGrid->SetReadOnly(curLine, CATEGORY_DELETE, true); + SET_ROW_COLOR(curLine, OWN_GREEN); } void PreferencesPanel::OnAccountModified(wxGridEvent& event) @@ -193,29 +193,29 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME); if (value != wxT("")) - { + { new_account.name = value; op_complete--; - } + } value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER); if (value != wxT("")) - { + { new_account.number = value; op_complete--; - } + } value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED); if (value != wxT("") && value != wxT("0")) - new_account.shared = true; + new_account.shared = true; else - new_account.shared = false; + new_account.shared = false; value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT); if (value != wxT("") && value != wxT("0")) - new_account._default = true; + new_account._default = true; else - new_account._default = false; + new_account._default = false; if (col == ACCOUNT_DEFAULT) { @@ -337,10 +337,10 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME); if (value != wxT("")) - { + { new_cat.name = value; op_complete--; - } + } new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col); new_cat.font = wxT(""); diff --git a/view/PreferencesPanel.h b/view/PreferencesPanel.h index 230053a..567450e 100644 --- a/view/PreferencesPanel.h +++ b/view/PreferencesPanel.h @@ -19,7 +19,7 @@ class KissCount; class PreferencesPanel: public wxPanel { -public: + public: PreferencesPanel(KissCount* kiss, wxUI *parent); void ChangeUser(); @@ -30,7 +30,7 @@ public: void OnShow(wxShowEvent& event); void OnKillMe(wxCommandEvent& event); -private: + private: KissCount* _kiss; wxUI* _wxUI; wxGrid* _accountsGrid; diff --git a/view/UsersDialog.cpp b/view/UsersDialog.cpp index 8098eba..f002a39 100644 --- a/view/UsersDialog.cpp +++ b/view/UsersDialog.cpp @@ -1,17 +1,18 @@ #include "UsersDialog.h" -enum {ID_BUTTON_OK=1, ID_BUTTON_CANCEL, ID_BUTTON_NEW_USER}; +enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, BUTTON_NEW_USER_ID}; BEGIN_EVENT_TABLE(UsersDialog, wxDialog) -EVT_BUTTON(ID_BUTTON_OK, UsersDialog::OnOK) -EVT_BUTTON(ID_BUTTON_CANCEL, UsersDialog::OnCancel) -EVT_BUTTON(ID_BUTTON_NEW_USER, UsersDialog::OnNewUser) +EVT_BUTTON(BUTTON_OK_ID, UsersDialog::OnOK) +EVT_BUTTON(BUTTON_CANCEL_ID, UsersDialog::OnCancel) +EVT_BUTTON(BUTTON_NEW_USER_ID, UsersDialog::OnNewUser) END_EVENT_TABLE() UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent) { wxGridBagSizer *gridBagSizer; wxStaticText* label; + wxCommandEvent event; gridBagSizer = new wxGridBagSizer(4, 4); @@ -27,9 +28,9 @@ UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), - _password->SetWindowStyle(wxTE_PASSWORD); - wxButton* ok = new wxButton(this, ID_BUTTON_OK, _("OK")); - wxButton* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel")); - wxButton* newUser = new wxButton(this, ID_BUTTON_NEW_USER, _("New User")); + wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); + wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); + wxButton* newUser = new wxButton(this, BUTTON_NEW_USER_ID, _("New User")); gridBagSizer->Add(ok, wxGBPosition(3, 1)); gridBagSizer->Add(cancel, wxGBPosition(3, 2)); gridBagSizer->Add(newUser, wxGBPosition(3, 3)); @@ -48,6 +49,9 @@ UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), - _users->SetFocus(); Layout(); Center(); + + if (users_list.size() == 0) + OnNewUser(event); } void UsersDialog::OnOK(wxCommandEvent& event) diff --git a/view/UsersDialog.h b/view/UsersDialog.h index 45a9109..cb92aa4 100644 --- a/view/UsersDialog.h +++ b/view/UsersDialog.h @@ -15,20 +15,20 @@ class KissCount; class UsersDialog : public wxDialog { -public: + public: UsersDialog(KissCount* kiss, wxUI *parent); void OnOK(wxCommandEvent& event); void OnCancel(wxCommandEvent& event); void OnNewUser(wxCommandEvent& event); -private: + private: KissCount* _kiss; wxUI* _wxUI; wxChoice* _users; wxTextCtrl* _password; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE(); }; #endif diff --git a/view/wxGridCellBitmapRenderer.cpp b/view/wxGridCellBitmapRenderer.cpp index 8c5c622..51e4087 100644 --- a/view/wxGridCellBitmapRenderer.cpp +++ b/view/wxGridCellBitmapRenderer.cpp @@ -7,18 +7,18 @@ wxGridCellBitmapRenderer::wxGridCellBitmapRenderer(wxBitmap& bitmap) : _bitmap(b wxGridCellRenderer* wxGridCellBitmapRenderer::Clone () const { - wxBitmap bitmap(_bitmap); - return new wxGridCellBitmapRenderer(bitmap); + wxBitmap bitmap(_bitmap); + return new wxGridCellBitmapRenderer(bitmap); } void wxGridCellBitmapRenderer::Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected) { - dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col))); - dc.DrawRectangle(rect); - dc.DrawBitmap (_bitmap, rect.x + (rect.width-_bitmap.GetWidth())/2, rect.y + (rect.height-_bitmap.GetHeight())/2, true); + dc.SetBrush(wxBrush(grid.GetCellBackgroundColour(row, col))); + dc.DrawRectangle(rect); + dc.DrawBitmap (_bitmap, rect.x + (rect.width-_bitmap.GetWidth())/2, rect.y + (rect.height-_bitmap.GetHeight())/2, true); } wxSize wxGridCellBitmapRenderer::GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col) { - return wxSize(_bitmap.GetWidth(), _bitmap.GetHeight()); + return wxSize(_bitmap.GetWidth(), _bitmap.GetHeight()); } diff --git a/view/wxGridCellBitmapRenderer.h b/view/wxGridCellBitmapRenderer.h index 7937934..dafbef5 100644 --- a/view/wxGridCellBitmapRenderer.h +++ b/view/wxGridCellBitmapRenderer.h @@ -7,15 +7,15 @@ class wxGridCellBitmapRenderer : public wxGridCellRenderer { -public: - wxGridCellBitmapRenderer(wxBitmap& bitmap); + public: + wxGridCellBitmapRenderer(wxBitmap& bitmap); - virtual wxGridCellRenderer* Clone () const; - virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected); - virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col); + virtual wxGridCellRenderer* Clone () const; + virtual void Draw (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected); + virtual wxSize GetBestSize (wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col); -private: - wxBitmap _bitmap; + private: + wxBitmap _bitmap; }; #endif diff --git a/view/wxUI.cpp b/view/wxUI.cpp index 7f98aa5..0bc9564 100644 --- a/view/wxUI.cpp +++ b/view/wxUI.cpp @@ -1,35 +1,30 @@ #include "wxUI.h" -BEGIN_EVENT_TABLE(wxUI, wxFrame) - EVT_MENU(ID_Quit, wxUI::OnQuit) - EVT_MENU(ID_About, wxUI::OnAbout) -END_EVENT_TABLE() - wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ; wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL), _needReload(false) { - _hbox = new wxBoxSizer(wxVERTICAL); - ButtonPanel* buttons = new ButtonPanel(_kiss, this); - // wxMenu *menuFile = new wxMenu; + _hbox = new wxBoxSizer(wxVERTICAL); + ButtonPanel* buttons = new ButtonPanel(_kiss, this); + // wxMenu *menuFile = new wxMenu; - // menuFile->Append( ID_About, wxT("&About...") ); - // menuFile->AppendSeparator(); - // menuFile->Append( ID_Quit, wxT("E&xit") ); + // menuFile->Append( ID_About, wxT("&About...") ); + // menuFile->AppendSeparator(); + // menuFile->Append( ID_Quit, wxT("E&xit") ); - // wxMenuBar *menuBar = new wxMenuBar; - // menuBar->Append( menuFile, wxT("&File") ); + // wxMenuBar *menuBar = new wxMenuBar; + // menuBar->Append( menuFile, wxT("&File") ); - // SetMenuBar( menuBar ); + // SetMenuBar( menuBar ); - // CreateStatusBar(); - // SetStatusText( wxT("Welcome to wxWidgets!") ); + // CreateStatusBar(); + // SetStatusText( wxT("Welcome to wxWidgets!") ); - SetSizer(_hbox); + SetSizer(_hbox); - _hbox->Add(buttons); + _hbox->Add(buttons); } wxUI::~wxUI() @@ -38,19 +33,6 @@ wxUI::~wxUI() if (_preferencesPanel) delete _preferencesPanel; } -void wxUI::OnQuit(wxCommandEvent& WXUNUSED(event)) -{ - Close(true); -} - -void wxUI::OnAbout(wxCommandEvent& WXUNUSED(event)) -{ - wxMessageBox( _("This is a wxWidgets Hello world sample"), - _("About Hello World"), - wxOK | wxICON_INFORMATION, this ); -} - - void wxUI::ShowAccount() { ShowPanel(_accountPanel); @@ -69,17 +51,17 @@ void wxUI::ChangeUser() void wxUI::LoadUser() { - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel = NULL; + _hbox->Detach(_curPanel); + _curPanel = NULL; } if (_accountPanel) - delete _accountPanel; + delete _accountPanel; if (_preferencesPanel) - delete _preferencesPanel; + delete _preferencesPanel; _preferencesPanel = new PreferencesPanel(_kiss, this); _accountPanel = new AccountPanel(_kiss, this); @@ -91,23 +73,23 @@ void wxUI::ShowPanel(wxPanel* panel) { int month, year; - if (!panel) return; + if (!panel) return; - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel->Hide(); + _hbox->Detach(_curPanel); + _curPanel->Hide(); } - if (panel == _accountPanel && _needReload) - { - month = _accountPanel->_curMonth; - year = _accountPanel->_curYear; - delete _accountPanel; - panel = _accountPanel = new AccountPanel(_kiss, this); - _accountPanel->ShowMonth(month, year); - _needReload = false; - } + if (panel == _accountPanel && _needReload) + { + month = _accountPanel->_curMonth; + year = _accountPanel->_curYear; + delete _accountPanel; + panel = _accountPanel = new AccountPanel(_kiss, this); + _accountPanel->ShowMonth(month, year); + _needReload = false; + } _curPanel = panel; _hbox->Add(panel); @@ -122,17 +104,17 @@ void wxUI::GenerateMonth(int month, int year) void wxUI::KillMe() { - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel = NULL; + _hbox->Detach(_curPanel); + _curPanel = NULL; } if (_accountPanel) - delete _accountPanel; + delete _accountPanel; if (_preferencesPanel) - delete _preferencesPanel; + delete _preferencesPanel; _accountPanel = NULL; _preferencesPanel = NULL; diff --git a/view/wxUI.h b/view/wxUI.h index ecdbe6d..77c9163 100644 --- a/view/wxUI.h +++ b/view/wxUI.h @@ -17,13 +17,13 @@ extern wxString months[12]; class wxUI: public wxFrame { -public: + public: wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size); ~wxUI(); - void OnQuit(wxCommandEvent& event); - void OnAbout(wxCommandEvent& event); + void OnQuit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); void ChangeUser(); void LoadUser(); @@ -36,7 +36,7 @@ public: void NeedReload(); -private: + private: KissCount *_kiss; wxBoxSizer *_hbox; AccountPanel *_accountPanel; @@ -44,15 +44,6 @@ private: wxPanel *_curPanel; bool _needReload; void ShowPanel(wxPanel* panel); - - DECLARE_EVENT_TABLE(); - -}; - -enum -{ - ID_Quit = 1, - ID_About, }; #endif