diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 451a0f0..499be26 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -1,318 +1,318 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "KissCount.h" KissCount::KissCount(const char* bdd_filename) : _user(NULL) { - _wxUI = new wxUI(this, wxT("KissCount"), wxPoint(50, 50), wxSize(1024, 768)); + _wxUI = new wxUI(this, wxT("KissCount"), wxPoint(50, 50), wxSize(1024, 768)); - _wxUI->SetLanguage(wxLocale::GetSystemLanguage()); + _wxUI->SetLanguage(wxLocale::GetSystemLanguage()); - _wxUI->Show(true); - _wxUI->Centre(); - _wxUI->Disable(); + _wxUI->Show(true); + _wxUI->Centre(); + _wxUI->Disable(); - try + try { - _db = new Database(bdd_filename); + _db = new Database(bdd_filename); } - catch (std::string s) + catch (std::string s) { - _wxUI->Close(true); - throw s; + _wxUI->Close(true); + throw s; } - _wxUI->ChangeUser(); - _wxUI->Enable(); + _wxUI->ChangeUser(); + _wxUI->Enable(); } KissCount::~KissCount() { - delete _db; - delete _wxUI; - if (_user) delete _user; + delete _db; + delete _wxUI; + if (_user) delete _user; } std::list KissCount::GetUsers() { - return _db->GetUsers(); + return _db->GetUsers(); } bool KissCount::IsValidUser(const wxString& user, const wxString& password) { - return _db->IsValidUser(user, password) ; + return _db->IsValidUser(user, password) ; } void KissCount::LoadUser(const wxString& user) { - if (_user) delete _user; - _user = _db->LoadUser(user) ; - if (_user) - _wxUI->LoadUser(); + if (_user) delete _user; + _user = _db->LoadUser(user) ; + if (_user) + _wxUI->LoadUser(); } void KissCount::LoadYear(int year, bool force) { - if (!force && _user->_operations[year] != NULL) return; + if (!force && _user->_operations[year] != NULL) return; - if (_user->_operations[year] != NULL) + if (_user->_operations[year] != NULL) { - delete _user->_operations[year]; - _user->_operations[year] = NULL; + delete _user->_operations[year]; + _user->_operations[year] = NULL; } - _db->LoadYear(_user, year); + _db->LoadYear(_user, year); } User* KissCount::GetUser() { - return _user; + return _user; } double KissCount::GetAccountAmount(const wxString& id, int month, int year) { - return _db->GetAccountAmount(id, month, year); + return _db->GetAccountAmount(id, month, year); } void KissCount::UpdateOperation(Operation& op) { - // Unlink - op.transfert = wxT(""); - _user->LinkOrUnlinkOperation(op); + // Unlink + op.transfert = wxT(""); + _user->LinkOrUnlinkOperation(op); - _db->UpdateOperation(op); + _db->UpdateOperation(op); - // Link - _user->LinkOrUnlinkOperation(op); + // Link + _user->LinkOrUnlinkOperation(op); } wxString KissCount::AddOperation(Operation& op) { - wxString ret = _db->AddOperation(_user, op); + wxString ret = _db->AddOperation(_user, op); - if (op.transfert.Length()) - _user->LinkOrUnlinkOperation(op); + if (op.transfert.Length()) + _user->LinkOrUnlinkOperation(op); - return ret; + return ret; } void KissCount::DeleteOperation(Operation& op) { - if (op.transfert.Length()) + if (op.transfert.Length()) { - op.transfert = wxT(""); - _user->LinkOrUnlinkOperation(op); + op.transfert = wxT(""); + _user->LinkOrUnlinkOperation(op); } - _db->DeleteOperation(op); + _db->DeleteOperation(op); } void KissCount::DeleteOperations(int month, int year) { - _db->DeleteOperations(_user, month, year); - if (month != -1) - (*_user->_operations[year]).erase(month); + _db->DeleteOperations(_user, month, year); + if (month != -1) + (*_user->_operations[year]).erase(month); - if (month == -1 || !_user->_operations[year]->size()) + if (month == -1 || !_user->_operations[year]->size()) { - delete _user->_operations[year]; - _user->_operations.erase(year); + delete _user->_operations[year]; + _user->_operations.erase(year); } } void KissCount::SetAccountAmount(int month, int year, const wxString& accountId, double amount) { - _db->SetAccountAmount(month, year, accountId, amount); + _db->SetAccountAmount(month, year, accountId, amount); } wxString KissCount::AddAccount(Account& ac) { - ac.id = _db->AddAccount(_user, ac); - _user->_accounts.push_back(ac); + ac.id = _db->AddAccount(_user, ac); + _user->_accounts.push_back(ac); - return ac.id; + return ac.id; } void KissCount::UpdateAccount(Account& ac) { - std::vector::iterator it; - int i; + std::vector::iterator it; + int i; - _db->UpdateAccount(ac); - for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++) - if (it->id == ac.id) - _user->_accounts[i] = ac; + _db->UpdateAccount(ac); + for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++) + if (it->id == ac.id) + _user->_accounts[i] = ac; } void KissCount::DeleteAccount(Account& ac) { - std::vector::iterator it; - int i; + std::vector::iterator it; + int i; - _db->DeleteAccount(ac); - for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++) - if (it->id == ac.id) - { - _user->_accounts.erase(_user->_accounts.begin()+i); - break; - } + _db->DeleteAccount(ac); + for (i=0, it=_user->_accounts.begin(); it !=_user->_accounts.end(); it++, i++) + if (it->id == ac.id) + { + _user->_accounts.erase(_user->_accounts.begin()+i); + break; + } } wxString KissCount::AddCategory(Category& category) { - wxString id; - id = _db->AddCategory(_user, category); - category.id = id; + wxString id; + id = _db->AddCategory(_user, category); + category.id = id; - _user->_categories.push_back(category); + _user->_categories.push_back(category); - return id; + return id; } void KissCount::UpdateCategory(Category& category) { - _db->UpdateCategory(category); + _db->UpdateCategory(category); - for (int i=0; i<_user->GetCategoriesNumber();i++) - if (_user->_categories[i].id == category.id) - { - _user->_categories[i] = category; - break; - } + for (int i=0; i<_user->GetCategoriesNumber();i++) + if (_user->_categories[i].id == category.id) + { + _user->_categories[i] = category; + break; + } } void KissCount::DeleteCategory(Category& category) { - _db->DeleteCategory(_user, category); + _db->DeleteCategory(_user, category); - for (int i=0; i<_user->GetCategoriesNumber();i++) - if (_user->_categories[i].id == category.id) - { - _user->_categories.erase(_user->_categories.begin()+i); - break; - } + for (int i=0; i<_user->GetCategoriesNumber();i++) + if (_user->_categories[i].id == category.id) + { + _user->_categories.erase(_user->_categories.begin()+i); + break; + } } std::map > KissCount::GetAllOperations() { - return _db->GetAllOperations(_user); + return _db->GetAllOperations(_user); } void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo) { - std::vector::iterator it; - Operation op; + std::vector::iterator it; + Operation op; - _db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo); + _db->GenerateMonth(_user, monthFrom, yearFrom, monthTo, yearTo); - if (!_user->_operations[yearTo]) - _user->_operations[yearTo] = new std::map >(); + if (!_user->_operations[yearTo]) + _user->_operations[yearTo] = new std::map >(); - if (monthFrom != -1 && yearFrom != -1) + if (monthFrom != -1 && yearFrom != -1) { - LoadYear(yearFrom, false); + LoadYear(yearFrom, false); - for(it = (*_user->_operations[yearFrom])[monthFrom].begin(); - it != (*_user->_operations[yearFrom])[monthFrom].end() - && it->fix_cost; - it++) + for(it = (*_user->_operations[yearFrom])[monthFrom].begin(); + it != (*_user->_operations[yearFrom])[monthFrom].end() + && it->fix_cost; + it++) { - op = *it; - op.month = monthTo; - op.year = yearTo; - op.id = AddOperation(op); - (*_user->_operations[yearTo])[monthTo].push_back(op); + op = *it; + op.month = monthTo; + op.year = yearTo; + op.id = AddOperation(op); + (*_user->_operations[yearTo])[monthTo].push_back(op); } } - _wxUI->GenerateMonth(monthTo, yearTo); + _wxUI->GenerateMonth(monthTo, yearTo); } void KissCount::ChangePassword(const wxString& password) { - _db->ChangePassword(_user, password); + _db->ChangePassword(_user, password); } bool KissCount::UserExists(const wxString& name) { - return _db->UserExists(name); + return _db->UserExists(name); } void KissCount::ChangeName(const wxString& name) { - _db->ChangeName(_user, name); - _user->_name = name; + _db->ChangeName(_user, name); + _user->_name = name; } void KissCount::NewUser(const wxString& name) { - wxDateTime curDate; - Account ac = {wxT(""), wxT("Account 1"), wxT(""), false, true}; - Category cat ; + wxDateTime curDate; + Account ac = {wxT(""), wxT("Account 1"), wxT(""), false, true}; + Category cat ; - _db->NewUser(name); - if (_user) delete _user; - _user = _db->LoadUser(name) ; + _db->NewUser(name); + if (_user) delete _user; + _user = _db->LoadUser(name) ; - curDate.SetToCurrent(); + curDate.SetToCurrent(); - AddAccount(ac); + AddAccount(ac); - cat.parent = wxT("0") ; cat.name = _("Fix") ; cat.color = OWN_YELLOW ; - AddCategory(cat); - cat.parent = wxT("0") ; cat.name = _("Groceries") ; cat.color = OWN_GREEN; - AddCategory(cat); - cat.parent = wxT("0") ; cat.name = _("Hobbies") ; cat.color = OWN_GREEN; - AddCategory(cat); - cat.parent = wxT("0") ; cat.name = _("Operating exepense") ; cat.color = OWN_GREEN; - AddCategory(cat); - cat.parent = wxT("0") ; cat.name = _("Unexpected") ; cat.color = OWN_GREEN; - AddCategory(cat); - cat.parent = wxT("0") ; cat.name = _("Other") ; cat.color = OWN_GREEN; - AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Fix") ; cat.color = OWN_YELLOW ; + AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Groceries") ; cat.color = OWN_GREEN; + AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Hobbies") ; cat.color = OWN_GREEN; + AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Operating exepense") ; cat.color = OWN_GREEN; + AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Unexpected") ; cat.color = OWN_GREEN; + AddCategory(cat); + cat.parent = wxT("0") ; cat.name = _("Other") ; cat.color = OWN_GREEN; + AddCategory(cat); - SetOperationOrder(wxT("ASC")); + SetOperationOrder(wxT("ASC")); - _db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear()); + _db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear()); } void KissCount::KillMe() { - _wxUI->KillMe(); - _db->KillMe(_user); - delete _user; - _user = NULL; - _wxUI->ChangeUser(); + _wxUI->KillMe(); + _db->KillMe(_user); + delete _user; + _user = NULL; + _wxUI->ChangeUser(); } void KissCount::SetLanguage(wxLanguage language) { - _user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ; - _db->UpdatePreference(_user, wxT("language")); + _user->_preferences[wxT("language")] = wxString::Format(wxT("%d"), language) ; + _db->UpdatePreference(_user, wxT("language")); } /* ASC (default) or DESC - */ +*/ void KissCount::SetOperationOrder(const wxString& order) { - _user->_preferences[wxT("operation_order")] = order; - _db->UpdatePreference(_user, wxT("operation_order")); + _user->_preferences[wxT("operation_order")] = order; + _db->UpdatePreference(_user, wxT("operation_order")); } std::vector* KissCount::Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, @@ -320,55 +320,55 @@ std::vector* KissCount::Search(wxString* description, wxDateTime* dat std::vector categories, std::vector accounts) { - return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); + return _db->Search(_user, description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); } bool KissCount::SearchPreviousOperation(Operation* res, wxString& description, int month, int year) { - std::vector* operations; - wxDateTime* date ; - //wxDateSpan threeMonths(0, 3); Not working :( - std::vector v; + std::vector* operations; + wxDateTime* date ; + //wxDateSpan threeMonths(0, 3); Not working :( + std::vector v; - month -= 3; - if (month < 0) + month -= 3; + if (month < 0) { - year -= 1; - month += 12; + year -= 1; + month += 12; } - date = new wxDateTime(0, (wxDateTime::Month)month, year); + date = new wxDateTime(0, (wxDateTime::Month)month, year); - operations = Search(&description, date, NULL, NULL, NULL, v, v); + operations = Search(&description, date, NULL, NULL, NULL, v, v); - delete date; + delete date; - if (!operations->size()) + if (!operations->size()) { - delete operations; - return false; + delete operations; + return false; } - *res = (*operations)[operations->size()-1]; + *res = (*operations)[operations->size()-1]; - delete operations; + delete operations; - return true; + return true; } void KissCount::GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo, - std::map > >* accountAmounts, - std::map* categories) + std::map > >* accountAmounts, + std::map* categories) { - wxString monthF = wxString::Format(wxT("%d"), monthFrom); - wxString monthT = wxString::Format(wxT("%d"), monthTo); - wxString yearF = wxString::Format(wxT("%d"), yearFrom); - wxString yearT = wxString::Format(wxT("%d"), yearTo); + wxString monthF = wxString::Format(wxT("%d"), monthFrom); + wxString monthT = wxString::Format(wxT("%d"), monthTo); + wxString yearF = wxString::Format(wxT("%d"), yearFrom); + wxString yearT = wxString::Format(wxT("%d"), yearTo); - _db->GetStats(_user, monthF, yearF, monthT, yearT, accountAmounts, categories); + _db->GetStats(_user, monthF, yearF, monthT, yearT, accountAmounts, categories); } std::map* KissCount::GetNotChecked(int month, int year) { - return _db->GetNotChecked(_user, month, year); + return _db->GetNotChecked(_user, month, year); } diff --git a/src/controller/KissCount.h b/src/controller/KissCount.h index b8063cc..bdb88f1 100644 --- a/src/controller/KissCount.h +++ b/src/controller/KissCount.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef KISSCOUNT_H @@ -32,60 +32,60 @@ along with KissCount. If not, see . class wxUI; class KissCount { - public: - KissCount(const char* bdd_filename); - ~KissCount(); +public: + KissCount(const char* bdd_filename); + ~KissCount(); - std::list GetUsers(); - bool IsValidUser(const wxString& user, const wxString& password); - void LoadUser(const wxString& user); - User* GetUser(); - void ChangePassword(const wxString& password); - bool UserExists(const wxString& name); - void ChangeName(const wxString& name); - void NewUser(const wxString& name); + std::list GetUsers(); + bool IsValidUser(const wxString& user, const wxString& password); + void LoadUser(const wxString& user); + User* GetUser(); + void ChangePassword(const wxString& password); + bool UserExists(const wxString& name); + void ChangeName(const wxString& name); + void NewUser(const wxString& name); - void LoadYear(int year, bool force=false); + void LoadYear(int year, bool force=false); - wxString AddOperation(Operation& op); - void UpdateOperation(Operation& op); - void DeleteOperation(Operation& op); - void DeleteOperations(int month, int year); + wxString AddOperation(Operation& op); + void UpdateOperation(Operation& op); + void DeleteOperation(Operation& op); + void DeleteOperations(int month, int year); - double GetAccountAmount(const wxString& id, int month, int year); - void SetAccountAmount(int month, int year, const wxString& accountId, double value); - wxString AddAccount(Account& ac); - void UpdateAccount(Account& ac); - void DeleteAccount(Account& ac); + double GetAccountAmount(const wxString& id, int month, int year); + void SetAccountAmount(int month, int year, const wxString& accountId, double value); + wxString AddAccount(Account& ac); + void UpdateAccount(Account& ac); + void DeleteAccount(Account& ac); - wxString AddCategory(Category& category); - void UpdateCategory(Category& category); - void DeleteCategory(Category& category); + wxString AddCategory(Category& category); + void UpdateCategory(Category& category); + void DeleteCategory(Category& category); - std::map > GetAllOperations(); + std::map > GetAllOperations(); - void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo); - void KillMe(); + void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo); + void KillMe(); - void SetLanguage(wxLanguage language); - void SetOperationOrder(const wxString& order); + void SetLanguage(wxLanguage language); + void SetOperationOrder(const wxString& order); - std::vector* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, - wxString* amountFrom, wxString* amountTo, - std::vector categories, std::vector accounts); + std::vector* Search(wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, + wxString* amountFrom, wxString* amountTo, + std::vector categories, std::vector accounts); - bool SearchPreviousOperation(Operation* res, wxString& description, int month, int year); + bool SearchPreviousOperation(Operation* res, wxString& description, int month, int year); - void GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo, - std::map > >* accountAmounts, - std::map* categories); + void GetStats(int monthFrom, int yearFrom, int monthTo, int yearTo, + std::map > >* accountAmounts, + std::map* categories); - std::map* GetNotChecked(int month, int year); + std::map* GetNotChecked(int month, int year); - private: - wxUI* _wxUI; - Database* _db; - User* _user; +private: + wxUI* _wxUI; + Database* _db; + User* _user; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 70cb491..4061e71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,43 +1,43 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "main.h" class MyApp: public wxApp { - virtual bool OnInit() - { - try - { - if (argc == 2) - new KissCount(wxString(argv[1]).mb_str()); - else - new KissCount(NULL); - } - catch (std::string s) - { - std::cerr << "Error " << s << "\n"; - return false; - } + virtual bool OnInit() + { + try + { + if (argc == 2) + new KissCount(wxString(argv[1]).mb_str()); + else + new KissCount(NULL); + } + catch (std::string s) + { + std::cerr << "Error " << s << "\n"; + return false; + } - return true; - } + return true; + } }; IMPLEMENT_APP(MyApp); diff --git a/src/main.h b/src/main.h index 836d4f2..7563d00 100644 --- a/src/main.h +++ b/src/main.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef MAIN_H diff --git a/src/model/Account.h b/src/model/Account.h index 1f1bf19..c9d34b6 100644 --- a/src/model/Account.h +++ b/src/model/Account.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef ACCOUNT_H @@ -25,12 +25,12 @@ along with KissCount. If not, see . #include class Account { - public: - wxString id; - wxString name; - wxString number; - bool shared; - bool _default; +public: + wxString id; + wxString name; + wxString number; + bool shared; + bool _default; }; #endif diff --git a/src/model/Category.h b/src/model/Category.h index 6dc31c4..a06cd5d 100644 --- a/src/model/Category.h +++ b/src/model/Category.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef CATEGORY_H @@ -22,12 +22,12 @@ along with KissCount. If not, see . class Category { - public: - wxString id; - wxString parent; - wxString name; - wxColour color; - wxString font; +public: + wxString id; + wxString parent; + wxString name; + wxColour color; + wxString font; }; #endif diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 438fffe..35a258d 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "Database.h" @@ -28,34 +28,34 @@ along with KissCount. If not, see . // } #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, {}, {}) @@ -63,901 +63,901 @@ along with KissCount. If not, see . static inline wxString DoubleToString(double d) { - wxString res; + wxString res; - res = wxString::Format(wxT("%.2lf"), d); - res.Replace(wxT(","), wxT(".")); + res = wxString::Format(wxT("%.2lf"), d); + res.Replace(wxT(","), wxT(".")); - return res; + return res; } Database::Database(const char* filename) { - std::ifstream bdd_file; + std::ifstream bdd_file; - if (filename) + if (filename) { - bdd_file.open(filename, std::ifstream::in); + bdd_file.open(filename, std::ifstream::in); - if (!bdd_file.good()) + if (!bdd_file.good()) { - wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); - throw std::string("Unable to open ") + filename; + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + filename; } - _db.Open(wxString(filename, wxConvUTF8)); - if (!_db.IsOpen()) + _db.Open(wxString(filename, wxConvUTF8)); + if (!_db.IsOpen()) { - wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); - throw std::string("Unable to open ") + filename; + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + filename; } } - else + else { - // If default BDD file, assume this can be the first load - bdd_file.open(BDD_FILE, std::ifstream::in); + // If default BDD file, assume this can be the first load + bdd_file.open(BDD_FILE, std::ifstream::in); - if (!bdd_file.good()) + if (!bdd_file.good()) { - CreateDatabase(); + CreateDatabase(); } - else + else { - _db.Open(wxT(BDD_FILE)); - if (!_db.IsOpen()) + _db.Open(wxT(BDD_FILE)); + if (!_db.IsOpen()) { - wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); - throw std::string("Unable to open ") + BDD_FILE; + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + 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)); - if (!_db.IsOpen()) + if (!_db.IsOpen()) { - wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); - throw std::string("Unable to open ") + BDD_FILE; + wxMessageBox(_("Unable to open Database"), _("Error"), wxICON_ERROR | wxOK ); + throw std::string("Unable to open ") + 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(); } wxString Database::HashPassword(const wxString& password) { - blk_SHA_CTX sha_ctx; - unsigned char sha[20]; - wxString wxSHA; + blk_SHA_CTX sha_ctx; + unsigned char sha[20]; + wxString wxSHA; - blk_SHA1_Init(&sha_ctx); - blk_SHA1_Update(&sha_ctx, password.c_str(), password.Length()); - blk_SHA1_Final(sha, &sha_ctx); + blk_SHA1_Init(&sha_ctx); + blk_SHA1_Update(&sha_ctx, password.c_str(), password.Length()); + blk_SHA1_Final(sha, &sha_ctx); - for(int i=0; i<20; i++) - wxSHA += wxString::Format(wxT("%02x"), (int)sha[i]); + for(int i=0; i<20; i++) + wxSHA += wxString::Format(wxT("%02x"), (int)sha[i]); - return wxSHA; + return wxSHA; } std::list Database::GetUsers() { - std::list res; - wxString req; - // Check whether value exists in table - wxSQLite3ResultSet set ; + std::list res; + wxString req; + // Check whether value exists in table + wxSQLite3ResultSet set ; - req = wxT("SELECT name FROM user ORDER BY name"); - EXECUTE_SQL_QUERY(req, set, res); + req = wxT("SELECT name FROM user ORDER BY name"); + EXECUTE_SQL_QUERY(req, set, res); - while (set.NextRow()) + while (set.NextRow()) { - res.push_front(set.GetAsString(0)); + res.push_front(set.GetAsString(0)); } - set.Finalize(); + set.Finalize(); - return res; + return res; } bool Database::IsValidUser(const wxString& user, const wxString& password) { - bool res; - wxString req; - wxSQLite3ResultSet set; + bool res; + wxString req; + wxSQLite3ResultSet set; - req = wxT("SELECT name FROM user WHERE name='") + user + wxT("' AND password='") + HashPassword(password) + wxT("'"); + req = wxT("SELECT name FROM user WHERE name='") + user + wxT("' AND password='") + HashPassword(password) + wxT("'"); - EXECUTE_SQL_QUERY(req, set, false); + EXECUTE_SQL_QUERY(req, set, false); - res = set.NextRow() ; - set.Finalize(); + res = set.NextRow() ; + set.Finalize(); - return res; + return res; } User* Database::LoadUser(const wxString& name) { - wxSQLite3ResultSet set; - wxString req; - User* user; - Account account; - Category category; + wxSQLite3ResultSet set; + wxString req; + User* user; + Account account; + Category category; - std::vector::iterator it; + std::vector::iterator it; - req = wxT("SELECT * FROM user WHERE name='") + name + wxT("'"); + req = wxT("SELECT * FROM user WHERE name='") + name + wxT("'"); - EXECUTE_SQL_QUERY(req, set, NULL); + EXECUTE_SQL_QUERY(req, set, NULL); - if (!set.NextRow()) - return NULL; + if (!set.NextRow()) + return NULL; - user = new User(); + user = new User(); - user->_id = set.GetAsString(wxT("id")); - user->_name = set.GetAsString(wxT("name")); - user->_password = wxT("") ; // Security reasons set.GetAsString("password"); + user->_id = set.GetAsString(wxT("id")); + user->_name = set.GetAsString(wxT("name")); + user->_password = wxT("") ; // Security reasons set.GetAsString("password"); - user->_preferences[wxT("operation_order")] = wxT("ASC") ; + user->_preferences[wxT("operation_order")] = wxT("ASC") ; - set.Finalize(); + set.Finalize(); - req = wxT("SELECT * FROM account WHERE user='") + user->_id + wxT("' ORDER BY default_account DESC, name ASC"); + req = wxT("SELECT * FROM account WHERE user='") + user->_id + wxT("' ORDER BY default_account DESC, name ASC"); - EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); + EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); - while (set.NextRow()) + while (set.NextRow()) { - account.id = set.GetAsString(wxT("id")); - account.name = set.GetAsString(wxT("name")); - account.number = set.GetAsString(wxT("number")); - account.shared = set.GetBool(wxT("shared")); - account._default = set.GetBool(wxT("default_account")); - user->_accounts.push_back(account); + account.id = set.GetAsString(wxT("id")); + account.name = set.GetAsString(wxT("name")); + account.number = set.GetAsString(wxT("number")); + account.shared = set.GetBool(wxT("shared")); + account._default = set.GetBool(wxT("default_account")); + user->_accounts.push_back(account); } - set.Finalize(); + set.Finalize(); - if (!user->_accounts.empty()) + if (!user->_accounts.empty()) { - it = user->_accounts.begin(); - req = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req += wxT("', '") + it->id ; + req += wxT("', '") + it->id ; } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("'"); - req += wxT(" ORDER BY year ASC"); + req += wxT("')"); + req += wxT(" OR user='") + user->_id + wxT("'"); + req += wxT(" ORDER BY year ASC"); - EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); + EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); - while (set.NextRow()) + while (set.NextRow()) { - user->_operations[set.GetInt(wxT("year"))] = NULL; + user->_operations[set.GetInt(wxT("year"))] = NULL; } - set.Finalize(); + set.Finalize(); } - req = wxT("SELECT * FROM category WHERE user='") + user->_id + wxT("' ORDER BY name ASC"); - EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); + req = wxT("SELECT * FROM category WHERE user='") + user->_id + wxT("' ORDER BY name ASC"); + EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); - while (set.NextRow()) + while (set.NextRow()) { - category.id = set.GetAsString(wxT("id")); - category.parent = set.GetAsString(wxT("parent")); - category.name = set.GetAsString(wxT("name")); - category.color = wxColour(set.GetAsString(wxT("color"))); - category.font = set.GetAsString(wxT("font")); - if (category.name != _("Fix")) - user->_categories.push_back(category); - else - user->_categories.insert(user->_categories.begin(), category); + category.id = set.GetAsString(wxT("id")); + category.parent = set.GetAsString(wxT("parent")); + category.name = set.GetAsString(wxT("name")); + category.color = wxColour(set.GetAsString(wxT("color"))); + category.font = set.GetAsString(wxT("font")); + if (category.name != _("Fix")) + user->_categories.push_back(category); + else + user->_categories.insert(user->_categories.begin(), category); } - set.Finalize(); + set.Finalize(); - req = wxT("SELECT name, value FROM preference WHERE user='") + user->_id + wxT("' ORDER BY value ASC"); - EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); + req = wxT("SELECT name, value FROM preference WHERE user='") + user->_id + wxT("' ORDER BY value ASC"); + EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, {delete user;}, {delete user;}); - while (set.NextRow()) - user->_preferences[set.GetAsString(wxT("name"))] = set.GetAsString(wxT("value")); + while (set.NextRow()) + user->_preferences[set.GetAsString(wxT("name"))] = set.GetAsString(wxT("value")); - set.Finalize(); + set.Finalize(); - return user; + return user; } void Database::LoadYear(User* user, int year) { - wxSQLite3ResultSet set; - wxString req; - std::vector::iterator it; + wxSQLite3ResultSet set; + wxString req; + std::vector::iterator it; - if (user->_operations[year] == NULL) - user->_operations[year] = new std::map >(); + if (user->_operations[year] == NULL) + user->_operations[year] = new std::map >(); - if (!user->_accounts.size()) return; + if (!user->_accounts.size()) return; - it = user->_accounts.begin(); - req = wxT("SELECT * FROM operation WHERE (account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req = wxT("SELECT * FROM operation WHERE (account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req += wxT("', '") + it->id ; + req += wxT("', '") + it->id ; } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("')"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); - req += wxT(" ORDER BY fix_cost DESC, year, month ASC, day "); - req += user->_preferences[wxT("operation_order")]; + req += wxT("')"); + req += wxT(" OR user='") + user->_id + wxT("')"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); + req += wxT(" ORDER BY fix_cost DESC, year, month ASC, day "); + req += user->_preferences[wxT("operation_order")]; - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - while (set.NextRow()) + while (set.NextRow()) { - Operation op; - op.id = set.GetAsString(wxT("id")); - op.parent = set.GetAsString(wxT("parent")); - op.account = set.GetAsString(wxT("account")); - op.day = set.GetInt(wxT("day")); - op.month = set.GetInt(wxT("month")); - op.year = set.GetInt(wxT("year")); - op.amount = set.GetDouble(wxT("amount")); - op.description = set.GetAsString(wxT("description")); - op.category = set.GetAsString(wxT("category")); - op.fix_cost = set.GetBool(wxT("fix_cost")); - op.checked = set.GetBool(wxT("checked")); - op.transfert = set.GetAsString(wxT("transfert")); - op.formula = set.GetAsString(wxT("formula")); - (*user->_operations[op.year])[op.month].push_back(op); + Operation op; + op.id = set.GetAsString(wxT("id")); + op.parent = set.GetAsString(wxT("parent")); + op.account = set.GetAsString(wxT("account")); + op.day = set.GetInt(wxT("day")); + op.month = set.GetInt(wxT("month")); + op.year = set.GetInt(wxT("year")); + op.amount = set.GetDouble(wxT("amount")); + op.description = set.GetAsString(wxT("description")); + op.category = set.GetAsString(wxT("category")); + op.fix_cost = set.GetBool(wxT("fix_cost")); + op.checked = set.GetBool(wxT("checked")); + op.transfert = set.GetAsString(wxT("transfert")); + op.formula = set.GetAsString(wxT("formula")); + (*user->_operations[op.year])[op.month].push_back(op); } - set.Finalize(); + set.Finalize(); } double Database::GetAccountAmount(const wxString& id, int month, int year) { - wxSQLite3ResultSet set; - wxString req; - double res; + wxSQLite3ResultSet set; + wxString req; + double res; - req = wxT("SELECT amount FROM account_amount WHERE account='") + id ; - req += wxT("' AND month='") + wxString::Format(wxT("%d"), month); - req += wxT("' AND year='") + wxString::Format(wxT("%d"), year); - req += wxT("'"); + req = wxT("SELECT amount FROM account_amount WHERE account='") + id ; + req += wxT("' AND month='") + wxString::Format(wxT("%d"), month); + req += wxT("' AND year='") + wxString::Format(wxT("%d"), year); + req += wxT("'"); - EXECUTE_SQL_QUERY(req , set, 0.0); + EXECUTE_SQL_QUERY(req , set, 0.0); - if (set.NextRow()) - res = set.GetDouble(wxT("amount")); - else + if (set.NextRow()) + res = set.GetDouble(wxT("amount")); + else { - SetAccountAmount(month, year, id, 0.0); - res = 0.0; + SetAccountAmount(month, year, id, 0.0); + res = 0.0; } - set.Finalize(); + set.Finalize(); - return res; + return res; } bool Database::GetOperation(const wxString& id, Operation* op) { - wxSQLite3ResultSet set; - wxString req; + wxSQLite3ResultSet set; + wxString req; - req = wxT("SELECT * FROM operation WHERE id='") + id + wxT("'"); + req = wxT("SELECT * FROM operation WHERE id='") + id + wxT("'"); - EXECUTE_SQL_QUERY(req, set, false); + EXECUTE_SQL_QUERY(req, set, false); - if (!set.NextRow()) return false; + if (!set.NextRow()) return false; - op->id = set.GetAsString(wxT("id")); - op->parent = set.GetAsString(wxT("parent")); - op->account = set.GetAsString(wxT("account")); - op->day = set.GetInt(wxT("day")); - op->month = set.GetInt(wxT("month")); - op->year = set.GetInt(wxT("year")); - op->amount = set.GetDouble(wxT("amount")); - op->description = set.GetAsString(wxT("description")); - op->category = set.GetAsString(wxT("category")); - op->fix_cost = set.GetBool(wxT("fix_cost")); - op->checked = set.GetBool(wxT("checked")); - op->transfert = set.GetAsString(wxT("transfert")); - op->formula = set.GetAsString(wxT("formula")); + op->id = set.GetAsString(wxT("id")); + op->parent = set.GetAsString(wxT("parent")); + op->account = set.GetAsString(wxT("account")); + op->day = set.GetInt(wxT("day")); + op->month = set.GetInt(wxT("month")); + op->year = set.GetInt(wxT("year")); + op->amount = set.GetDouble(wxT("amount")); + op->description = set.GetAsString(wxT("description")); + op->category = set.GetAsString(wxT("category")); + op->fix_cost = set.GetBool(wxT("fix_cost")); + op->checked = set.GetBool(wxT("checked")); + op->transfert = set.GetAsString(wxT("transfert")); + op->formula = set.GetAsString(wxT("formula")); - return true; + return true; } void Database::LinkOrUnlinkOperation(Operation& op) { - Operation linked; - wxString req; - wxSQLite3ResultSet set; + Operation linked; + wxString req; + wxSQLite3ResultSet set; - if (op.transfert.Length()) + if (op.transfert.Length()) { - // No one or not linked - if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount) + // No one or not linked + if (!GetOperation(op.transfert, &linked) || op.description != linked.description || op.amount != -linked.amount) { - req = wxT("UPDATE operation SET transfert='' where id='") + op.id + wxT("'") ; - EXECUTE_SQL_UPDATE(req, ); - return; + req = wxT("UPDATE operation SET transfert='' where id='") + op.id + wxT("'") ; + EXECUTE_SQL_UPDATE(req, ); + return; } } - // Not Linked - else + // Not Linked + else { - req = wxT("SELECT id FROM operation WHERE transfert='") + op.id + wxT("'"); + req = wxT("SELECT id FROM operation WHERE transfert='") + op.id + wxT("'"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - if (set.NextRow()) + if (set.NextRow()) { - req = wxT("UPDATE operation SET transfert='' where id='") + set.GetAsString(wxT("id")) + wxT("'") ; - EXECUTE_SQL_UPDATE(req, ); + req = wxT("UPDATE operation SET transfert='' where id='") + set.GetAsString(wxT("id")) + wxT("'") ; + EXECUTE_SQL_UPDATE(req, ); } - req = wxT("SELECT id FROM operation WHERE description='") + op.description + wxT("'"); - req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); - req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'"); - req += wxT(" AND (transfert='' OR transfert IS NULL)"); + req = wxT("SELECT id FROM operation WHERE description='") + op.description + wxT("'"); + req += wxT(" AND month='") + wxString::Format(wxT("%d"), op.month) + wxT("'"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), op.year) + wxT("'"); + req += wxT(" AND amount='") + DoubleToString(-op.amount) + wxT("'"); + req += wxT(" AND (transfert='' OR transfert IS NULL)"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - // Don't need to link - if (!set.NextRow()) return ; + // Don't need to link + if (!set.NextRow()) return ; - // Link - linked.id = set.GetAsString(wxT("id")); + // Link + linked.id = set.GetAsString(wxT("id")); - op.transfert = linked.id; + op.transfert = linked.id; - req = wxT("UPDATE operation SET transfert='") + linked.id + wxT("' where id='") + op.id + wxT("'") ; - EXECUTE_SQL_UPDATE(req, ); + req = wxT("UPDATE operation SET transfert='") + linked.id + wxT("' where id='") + op.id + wxT("'") ; + EXECUTE_SQL_UPDATE(req, ); - req = wxT("UPDATE operation SET transfert='") + op.id + wxT("' where id='") + linked.id + wxT("'") ; - EXECUTE_SQL_UPDATE(req, ); + req = wxT("UPDATE operation SET transfert='") + op.id + wxT("' where id='") + linked.id + wxT("'") ; + EXECUTE_SQL_UPDATE(req, ); } } void Database::UpdateOperation(Operation& op) { - wxString req; + wxString req; - LinkOrUnlinkOperation(op); + LinkOrUnlinkOperation(op); - req = wxT("UPDATE operation SET ") ; - req += wxT("parent='") + op.parent + wxT("'"); - 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(", transfert='") + op.transfert + wxT("'"); - req += wxT(", formula='") + op.formula + wxT("'"); - req += wxT(" WHERE id='") + op.id + wxT("'"); + req = wxT("UPDATE operation SET ") ; + req += wxT("parent='") + op.parent + wxT("'"); + 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(", transfert='") + op.transfert + wxT("'"); + req += wxT(", formula='") + op.formula + wxT("'"); + req += wxT(" WHERE id='") + op.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); - LinkOrUnlinkOperation(op); + LinkOrUnlinkOperation(op); } wxString Database::AddOperation(User* user, Operation& op) { - wxString req, res; - wxSQLite3ResultSet set; + wxString req, res; + wxSQLite3ResultSet set; - req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert') VALUES ('") ; - req += user->_id + wxT("'"); - req += wxT(", '") + op.parent + 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(", '") + op.formula + wxT("'"); - req += wxT(", '") + op.transfert + wxT("'"); - req += wxT(")"); + req = wxT("INSERT INTO operation ('user', 'parent', 'account', 'year', 'month', 'day', 'amount', 'description', 'category', 'fix_cost', 'formula', 'transfert') VALUES ('") ; + req += user->_id + wxT("'"); + req += wxT(", '") + op.parent + 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(", '") + op.formula + wxT("'"); + req += wxT(", '") + op.transfert + wxT("'"); + 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 parent='") + op.parent + 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(" AND formula='") + op.formula + wxT("'"); - req += wxT(" AND transfert='") + op.transfert + wxT("'"); - req += wxT("ORDER BY id DESC") ; + req = wxT("SELECT id FROM operation WHERE "); + req += wxT("user='") + user->_id + wxT("'"); + req += wxT(" AND parent='") + op.parent + 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(" AND formula='") + op.formula + wxT("'"); + req += wxT(" AND transfert='") + op.transfert + wxT("'"); + 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(); - op.id = res; + op.id = res; - LinkOrUnlinkOperation(op); + LinkOrUnlinkOperation(op); - 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, ); - LinkOrUnlinkOperation(op); + LinkOrUnlinkOperation(op); } 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++) + 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("', '") + 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("'"); + 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++) + 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("', '") + 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("'"); + 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, const 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 + try { - if (!_db.ExecuteUpdate(req)) + 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, ); + 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) + catch (wxSQLite3Exception e) { - std::cerr << req.mb_str() << "\n" ; - std::cerr << e.GetMessage().mb_str() << "\n" ; - return ; + std::cerr << req.mb_str() << "\n" ; + std::cerr << e.GetMessage().mb_str() << "\n" ; + return ; } } wxString Database::AddAccount(User* user, Account& ac) { - wxString req, res; - wxSQLite3ResultSet set; + 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) { - wxString req, res; - wxSQLite3ResultSet set; - wxString color; + wxString req, res; + wxSQLite3ResultSet set; + wxString color; - color = wxT("#") ; - color += wxString::Format(wxT("%02X"), category.color.Red()); - color += wxString::Format(wxT("%02X"), category.color.Green()); - color += wxString::Format(wxT("%02X"), category.color.Blue()); + color = wxT("#") ; + color += wxString::Format(wxT("%02X"), category.color.Red()); + color += wxString::Format(wxT("%02X"), category.color.Green()); + color += wxString::Format(wxT("%02X"), category.color.Blue()); - req = wxT("INSERT INTO category ('user', 'parent', 'name', 'color', font) VALUES ('") ; - req += user->_id + wxT("'"); - req += wxT(", '") + category.parent + wxT("'"); - req += wxT(", '") + category.name + wxT("'"); - req += wxT(", '") + color + wxT("'"); - req += wxT(", '") + category.font + wxT("'"); - req += wxT(")"); + req = wxT("INSERT INTO category ('user', 'parent', 'name', 'color', font) VALUES ('") ; + req += user->_id + wxT("'"); + req += wxT(", '") + category.parent + wxT("'"); + req += wxT(", '") + category.name + wxT("'"); + req += wxT(", '") + color + wxT("'"); + req += wxT(", '") + category.font + wxT("'"); + req += wxT(")"); - EXECUTE_SQL_UPDATE(req, wxT("0")); + EXECUTE_SQL_UPDATE(req, wxT("0")); - req = wxT("SELECT id FROM preference WHERE user='") + user->_id + wxT("'") ; - req += wxT(" AND name='") + category.name + wxT("'"); + req = wxT("SELECT id FROM preference WHERE user='") + user->_id + wxT("'") ; + req += wxT(" AND name='") + category.name + 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::UpdateCategory(Category& category) { - wxString req; - wxString color; + wxString req; + wxString color; - color = wxT("#") ; - color += wxString::Format(wxT("%02X"), category.color.Red()); - color += wxString::Format(wxT("%02X"), category.color.Green()); - color += wxString::Format(wxT("%02X"), category.color.Blue()); + color = wxT("#") ; + color += wxString::Format(wxT("%02X"), category.color.Red()); + color += wxString::Format(wxT("%02X"), category.color.Green()); + color += wxString::Format(wxT("%02X"), category.color.Blue()); - req = wxT("UPDATE category SET") ; - req += wxT(" parent='") + category.parent + wxT("'"); - req += wxT(", name='") + category.name + wxT("'"); - req += wxT(", color='") + color + wxT("'"); - req += wxT(", font='") + category.font + wxT("'"); - req += wxT(" WHERE id='") + category.id + wxT("'"); + req = wxT("UPDATE category SET") ; + req += wxT(" parent='") + category.parent + wxT("'"); + req += wxT(", name='") + category.name + wxT("'"); + req += wxT(", color='") + color + wxT("'"); + req += wxT(", font='") + category.font + wxT("'"); + req += wxT(" WHERE id='") + category.id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } 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) { - wxString req, req2, reqUnion; - wxSQLite3ResultSet set, set2; - std::vector::iterator it; - std::map > res; - int year; + wxString req, req2, reqUnion; + wxSQLite3ResultSet set, set2; + std::vector::iterator it; + std::map > res; + int year; - if (!user->_accounts.empty()) + if (!user->_accounts.empty()) { - it = user->_accounts.begin(); - req = wxT("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req = wxT("SELECT DISTINCT year FROM account_amount WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req += wxT("', '") + it->id ; + req += wxT("', '") + it->id ; } - req += wxT("')"); + req += wxT("')"); - it = user->_accounts.begin(); - req2 = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req2 = wxT("SELECT DISTINCT year FROM operation WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req2 += wxT("', '") + it->id ; + req2 += wxT("', '") + it->id ; } - req2 += wxT("')"); - req2 += wxT(" OR user='") + user->_id + wxT("'"); - req2 += wxT(" ORDER BY year ASC"); + req2 += wxT("')"); + req2 += wxT(" OR user='") + user->_id + wxT("'"); + req2 += wxT(" ORDER BY year ASC"); - reqUnion = req + wxT(" UNION ") + req2; - EXECUTE_SQL_QUERY(reqUnion, set, res); + reqUnion = req + wxT(" UNION ") + req2; + EXECUTE_SQL_QUERY(reqUnion, set, res); - while (set.NextRow()) + while (set.NextRow()) { - year = set.GetInt(wxT("year")); + year = set.GetInt(wxT("year")); - it = user->_accounts.begin(); - req = wxT("SELECT DISTINCT month FROM account_amount WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req = wxT("SELECT DISTINCT month FROM account_amount WHERE account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req += wxT("', '") + it->id ; + req += wxT("', '") + it->id ; } - req += wxT("')"); - req += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'"); + req += wxT("')"); + req += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'"); - it = user->_accounts.begin(); - req2 = wxT("SELECT DISTINCT month FROM operation WHERE (account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); it++) + it = user->_accounts.begin(); + req2 = wxT("SELECT DISTINCT month FROM operation WHERE (account IN('") + it->id; + it++; + for (;it != user->_accounts.end(); it++) { - req2 += wxT("', '") + it->id ; + req2 += wxT("', '") + it->id ; } - req2 += wxT("')"); - req2 += wxT(" OR user='") + user->_id + wxT("')"); - req2 += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'"); - req2 += wxT(" ORDER BY month ASC"); + req2 += wxT("')"); + req2 += wxT(" OR user='") + user->_id + wxT("')"); + req2 += wxT(" AND year='") + set.GetAsString(wxT("year")) + wxT("'"); + req2 += wxT(" ORDER BY month ASC"); - reqUnion = req + wxT(" UNION ") + req2; - EXECUTE_SQL_QUERY(reqUnion, set2, res); + reqUnion = req + wxT(" UNION ") + req2; + EXECUTE_SQL_QUERY(reqUnion, set2, res); - while (set2.NextRow()) + while (set2.NextRow()) { - res[year].push_back(set2.GetInt(wxT("month"))); + res[year].push_back(set2.GetInt(wxT("month"))); } - set2.Finalize(); + set2.Finalize(); } - set.Finalize(); + set.Finalize(); } - return res; + return res; } void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo) { - std::vector::iterator it; - wxString req; - wxSQLite3ResultSet set; - double amount; + std::vector::iterator it; + wxString req; + wxSQLite3ResultSet set; + double amount; - if (monthFrom == -1 || yearFrom == -1) + if (monthFrom == -1 || yearFrom == -1) { - for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) { - req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; - req += it->id + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), yearTo) + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), monthTo) + wxT("'"); - req += wxT(" ,'0.0'"); - req += wxT(")"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; + req += it->id + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), yearTo) + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), monthTo) + wxT("'"); + req += wxT(" ,'0.0'"); + req += wxT(")"); + EXECUTE_SQL_UPDATE(req, ); } - return; + return; } - for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++) { - amount = 0.0; - req = wxT("SELECT SUM(amount) AS total FROM operation WHERE") ; - req += wxT(" account='") + it->id + wxT("'"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), yearFrom) + wxT("'"); - req += wxT(" AND month='") + wxString::Format(wxT("%d"), monthFrom) + wxT("'"); + amount = 0.0; + req = wxT("SELECT SUM(amount) AS total FROM operation WHERE") ; + req += wxT(" account='") + it->id + wxT("'"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), yearFrom) + wxT("'"); + req += wxT(" AND month='") + wxString::Format(wxT("%d"), monthFrom) + wxT("'"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - if (set.NextRow()) - amount += set.GetDouble(wxT("total")); + if (set.NextRow()) + amount += set.GetDouble(wxT("total")); - req = wxT("SELECT amount FROM account_amount WHERE") ; - req += wxT(" account='") + it->id + wxT("'"); - req += wxT(" AND year='") + wxString::Format(wxT("%d"), yearFrom) + wxT("'"); - req += wxT(" AND month='") + wxString::Format(wxT("%d"), monthFrom) + wxT("'"); + req = wxT("SELECT amount FROM account_amount WHERE") ; + req += wxT(" account='") + it->id + wxT("'"); + req += wxT(" AND year='") + wxString::Format(wxT("%d"), yearFrom) + wxT("'"); + req += wxT(" AND month='") + wxString::Format(wxT("%d"), monthFrom) + wxT("'"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - if (set.NextRow()) - amount += set.GetDouble(wxT("amount")); + if (set.NextRow()) + amount += set.GetDouble(wxT("amount")); - req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; - req += it->id + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), yearTo) + wxT("'"); - req += wxT(" ,'") + wxString::Format(wxT("%d"), monthTo) + wxT("'"); - req += wxT(" ,'") + DoubleToString(amount) + wxT("'"); - req += wxT(")"); + req = wxT("INSERT INTO account_amount ('account', 'year', 'month', 'amount') VALUES ('") ; + req += it->id + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), yearTo) + wxT("'"); + req += wxT(" ,'") + wxString::Format(wxT("%d"), monthTo) + wxT("'"); + req += wxT(" ,'") + DoubleToString(amount) + wxT("'"); + req += wxT(")"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } } void Database::ChangePassword(User* user, const wxString& password) { - wxString req; + wxString req; - req = wxT("UPDATE user SET ") ; - req += wxT("password='") + HashPassword(password) + wxT("'"); - req += wxT(" WHERE name='") + user->_name + wxT("'"); + req = wxT("UPDATE user SET ") ; + req += wxT("password='") + HashPassword(password) + wxT("'"); + req += wxT(" WHERE name='") + user->_name + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } bool Database::UserExists(const wxString& name) { - wxSQLite3ResultSet set; - wxString req; - bool res=false; + wxSQLite3ResultSet set; + wxString req; + bool res=false; - req = wxT("SELECT name FROM user WHERE name='") + name + wxT("'") ; + req = wxT("SELECT name FROM user WHERE name='") + name + wxT("'") ; - EXECUTE_SQL_QUERY(req , set, false); + EXECUTE_SQL_QUERY(req , set, false); - if (set.NextRow()) - res = true; - else - res = false; + if (set.NextRow()) + res = true; + else + res = false; - set.Finalize(); + set.Finalize(); - return res; + return res; } void Database::ChangeName(User* user, const wxString& name) { - wxString req; + wxString req; - req = wxT("UPDATE user SET ") ; - req += wxT("name='") + name + wxT("'"); - req += wxT(" WHERE name='") + user->_name + wxT("'"); + req = wxT("UPDATE user SET ") ; + req += wxT("name='") + name + wxT("'"); + req += wxT(" WHERE name='") + user->_name + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } void Database::NewUser(const wxString& name) { - wxString req, id; - wxSQLite3ResultSet set; + wxString req, id; + wxSQLite3ResultSet set; - req = wxT("INSERT INTO user ('name', 'password') VALUES ('") ; - req += name + wxT("'"); - req += wxT(", '") + HashPassword(wxT("")) + wxT("'"); - req += wxT(")"); + req = wxT("INSERT INTO user ('name', 'password') VALUES ('") ; + req += name + wxT("'"); + req += wxT(", '") + HashPassword(wxT("")) + wxT("'"); + req += wxT(")"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); - req = wxT("SELECT id FROM user WHERE "); - req += wxT("name='") + name + wxT("'"); + req = wxT("SELECT id FROM user WHERE "); + req += wxT("name='") + name + wxT("'"); - EXECUTE_SQL_QUERY(req , set, ); + EXECUTE_SQL_QUERY(req , set, ); - set.NextRow(); - id = set.GetAsString(wxT("id")); + set.NextRow(); + id = set.GetAsString(wxT("id")); - set.Finalize(); + set.Finalize(); - return ; + return ; } /* @@ -965,75 +965,75 @@ void Database::NewUser(const wxString& name) */ void Database::KillMe(User* user) { - wxString req; - std::vector::iterator it; + wxString req; + std::vector::iterator it; - req = wxT("DELETE FROM preference WHERE user='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("DELETE FROM preference WHERE user='") + user->_id + wxT("'"); + EXECUTE_SQL_UPDATE(req, ); - if (!user->_accounts.empty()) + if (!user->_accounts.empty()) { - it = user->_accounts.begin(); - req = wxT("DELETE FROM account_amount WHERE account IN('") + it->id; - it++; - for (;it != user->_accounts.end(); 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("', '") + it->id ; } - req += wxT("')"); + req += 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++) + 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("', '") + it->id ; } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("'"); + req += wxT("')"); + req += wxT(" OR user='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + EXECUTE_SQL_UPDATE(req, ); } - req = wxT("DELETE FROM account WHERE user='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("DELETE FROM account WHERE user='") + user->_id + wxT("'"); + EXECUTE_SQL_UPDATE(req, ); - req = wxT("DELETE FROM category WHERE user='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("DELETE FROM category WHERE user='") + user->_id + wxT("'"); + EXECUTE_SQL_UPDATE(req, ); - req = wxT("DELETE FROM user WHERE id='") + user->_id + wxT("'"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("DELETE FROM user WHERE id='") + user->_id + wxT("'"); + EXECUTE_SQL_UPDATE(req, ); } void Database::UpdatePreference(User* user, const wxString& preference) { - wxString req; - wxString value = user->_preferences[preference]; + wxString req; + wxString value = user->_preferences[preference]; - req = wxT("UPDATE preference SET ") ; - req += wxT("name='") + preference + wxT("'"); - req += wxT(", value='") + value + wxT("'"); - req += wxT(" WHERE user='") + user->_id + wxT("'"); + req = wxT("UPDATE preference SET ") ; + req += wxT("name='") + preference + wxT("'"); + req += wxT(", value='") + value + wxT("'"); + req += wxT(" WHERE user='") + user->_id + wxT("'"); - try + try { - if (!_db.ExecuteUpdate(req)) + if (!_db.ExecuteUpdate(req)) { - req = wxT("INSERT INTO preference ('user', 'name', 'value') VALUES ('") ; - req += user->_id + wxT("'"); - req += wxT(" ,'") + preference + wxT("'"); - req += wxT(" ,'") + value + wxT("'"); - req += wxT(")"); - EXECUTE_SQL_UPDATE(req, ); + req = wxT("INSERT INTO preference ('user', 'name', 'value') VALUES ('") ; + req += user->_id + wxT("'"); + req += wxT(" ,'") + preference + wxT("'"); + req += wxT(" ,'") + value + wxT("'"); + req += wxT(")"); + EXECUTE_SQL_UPDATE(req, ); } } - catch (wxSQLite3Exception e) + catch (wxSQLite3Exception e) { - std::cerr << req.mb_str() << "\n" ; - std::cerr << e.GetMessage().mb_str() << "\n" ; - return ; + std::cerr << req.mb_str() << "\n" ; + std::cerr << e.GetMessage().mb_str() << "\n" ; + return ; } } @@ -1041,213 +1041,213 @@ std::vector* Database::Search(User* user, wxString* description, wxDa wxString* amountFrom, wxString* amountTo, std::vector categories, std::vector accounts) { - wxSQLite3ResultSet set; - wxString req; - bool firstCond = false; - std::vector::iterator it; - std::vector::iterator accountIt; - std::vector* res = new std::vector; + wxSQLite3ResultSet set; + wxString req; + bool firstCond = false; + std::vector::iterator it; + std::vector::iterator accountIt; + std::vector* res = new std::vector; - wxString dayFrom, monthFrom, yearFrom; - wxString dayTo, monthTo, yearTo; + wxString dayFrom, monthFrom, yearFrom; + wxString dayTo, monthTo, yearTo; - if (dateFrom) + if (dateFrom) { - dayFrom = wxString::Format(wxT("%d"), dateFrom->GetDay()-1); - monthFrom = wxString::Format(wxT("%d"), dateFrom->GetMonth()); - yearFrom = wxString::Format(wxT("%d"), dateFrom->GetYear()); + dayFrom = wxString::Format(wxT("%d"), dateFrom->GetDay()-1); + monthFrom = wxString::Format(wxT("%d"), dateFrom->GetMonth()); + yearFrom = wxString::Format(wxT("%d"), dateFrom->GetYear()); } - if (dateTo) + if (dateTo) { - dayTo = wxString::Format(wxT("%d"), dateTo->GetDay()-1); - monthTo = wxString::Format(wxT("%d"), dateTo->GetMonth()); - yearTo = wxString::Format(wxT("%d"), dateTo->GetYear()); + dayTo = wxString::Format(wxT("%d"), dateTo->GetDay()-1); + monthTo = wxString::Format(wxT("%d"), dateTo->GetMonth()); + yearTo = wxString::Format(wxT("%d"), dateTo->GetYear()); } - req = wxT("SELECT * from operation WHERE "); + req = wxT("SELECT * from operation WHERE "); - if (description) + if (description) { - req += wxT("description='") + *description + wxT("'"); - firstCond = true; + req += wxT("description='") + *description + wxT("'"); + firstCond = true; } - if (dateFrom) + if (dateFrom) { - if (firstCond) req += wxT(" AND ") ; else firstCond = true; - req += wxT("("); - req += wxT("year >= ") + yearFrom ; - req += wxT(" AND (month > '") + monthFrom + wxT("' OR (month == '") + monthFrom + wxT("' AND day >= '") + dayFrom + wxT("'))"); - req += wxT(")"); + if (firstCond) req += wxT(" AND ") ; else firstCond = true; + req += wxT("("); + req += wxT("year >= ") + yearFrom ; + req += wxT(" AND (month > '") + monthFrom + wxT("' OR (month == '") + monthFrom + wxT("' AND day >= '") + dayFrom + wxT("'))"); + req += wxT(")"); } - if (dateTo) + if (dateTo) { - if (firstCond) req += wxT(" AND ") ; else firstCond = true; - req += wxT("("); - req += wxT("year <= ") + yearTo ; - req += wxT(" AND (month < '") + monthTo + wxT("' OR (month == '") + monthTo + wxT("' AND day <= '") + dayTo + wxT("'))"); - req += wxT(")"); + if (firstCond) req += wxT(" AND ") ; else firstCond = true; + req += wxT("("); + req += wxT("year <= ") + yearTo ; + req += wxT(" AND (month < '") + monthTo + wxT("' OR (month == '") + monthTo + wxT("' AND day <= '") + dayTo + wxT("'))"); + req += wxT(")"); } - if (amountFrom) + if (amountFrom) { - if (firstCond) req += wxT(" AND ") ; else firstCond = true; - req += wxT("ABS(amount) >= ") + *amountFrom; + if (firstCond) req += wxT(" AND ") ; else firstCond = true; + req += wxT("ABS(amount) >= ") + *amountFrom; } - if (amountTo) + if (amountTo) { - if (firstCond) req += wxT(" AND ") ; else firstCond = true; - req += wxT("ABS(amount) <= ") + *amountTo; + if (firstCond) req += wxT(" AND ") ; else firstCond = true; + req += wxT("ABS(amount) <= ") + *amountTo; } - if (categories.size()) + if (categories.size()) { - if (firstCond) req += wxT(" AND ") ; else firstCond = true; - req += wxT("category IN ('"); - it = categories.begin(); - req += *it; - it++; + if (firstCond) req += wxT(" AND ") ; else firstCond = true; + req += wxT("category IN ('"); + it = categories.begin(); + req += *it; + it++; - for (; it != categories.end(); it++) - req += wxT("', '") + *it ; + for (; it != categories.end(); it++) + req += wxT("', '") + *it ; - req += wxT("')"); + req += wxT("')"); } - if (firstCond) req += wxT(" AND ") ; else firstCond = true; + if (firstCond) req += wxT(" AND ") ; else firstCond = true; - if (accounts.size()) + if (accounts.size()) { - req += wxT("account IN ('"); - it = accounts.begin(); - req += *it; - it++; + req += wxT("account IN ('"); + it = accounts.begin(); + req += *it; + it++; - for (; it != categories.end(); it++) - req += wxT("', '") + *it ; + for (; it != categories.end(); it++) + req += wxT("', '") + *it ; - req += wxT("')"); + req += wxT("')"); } - else + else { - req += wxT("account IN ('"); - accountIt = user->_accounts.begin(); - req += accountIt->id; - accountIt++; - for (;accountIt != user->_accounts.end(); accountIt++) + req += wxT("account IN ('"); + accountIt = user->_accounts.begin(); + req += accountIt->id; + accountIt++; + for (;accountIt != user->_accounts.end(); accountIt++) { - req += wxT("', '") + accountIt->id ; + req += wxT("', '") + accountIt->id ; } - req += wxT("')"); + req += wxT("')"); } - req += wxT(" ORDER BY year ") ; - req += user->_preferences[wxT("operation_order")] ; - req += wxT(", month ") + user->_preferences[wxT("operation_order")] ; - req += wxT(", day ") + user->_preferences[wxT("operation_order")] ; + req += wxT(" ORDER BY year ") ; + req += user->_preferences[wxT("operation_order")] ; + req += wxT(", month ") + user->_preferences[wxT("operation_order")] ; + req += wxT(", day ") + user->_preferences[wxT("operation_order")] ; - // std::cout << req.mb_str() << "\n"; + // std::cout << req.mb_str() << "\n"; - EXECUTE_SQL_QUERY(req, set, res); + EXECUTE_SQL_QUERY(req, set, res); - while (set.NextRow()) + while (set.NextRow()) { - Operation op; - op.id = set.GetAsString(wxT("id")); - op.account = set.GetAsString(wxT("account")); - op.day = set.GetInt(wxT("day")); - op.month = set.GetInt(wxT("month")); - op.year = set.GetInt(wxT("year")); - op.amount = set.GetDouble(wxT("amount")); - op.description = set.GetAsString(wxT("description")); - op.category = set.GetAsString(wxT("category")); - op.fix_cost = set.GetBool(wxT("fix_cost")); - op.checked = set.GetBool(wxT("checked")); - res->push_back(op); + Operation op; + op.id = set.GetAsString(wxT("id")); + op.account = set.GetAsString(wxT("account")); + op.day = set.GetInt(wxT("day")); + op.month = set.GetInt(wxT("month")); + op.year = set.GetInt(wxT("year")); + op.amount = set.GetDouble(wxT("amount")); + op.description = set.GetAsString(wxT("description")); + op.category = set.GetAsString(wxT("category")); + op.fix_cost = set.GetBool(wxT("fix_cost")); + op.checked = set.GetBool(wxT("checked")); + res->push_back(op); } - return res; + return res; } void Database::GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo, const wxString& yearTo, std::map > >* accountAmounts, std::map* categories) { - wxSQLite3ResultSet set; - wxString req; - std::vector::iterator accountIt; - std::vector::iterator categoryIt; + wxSQLite3ResultSet set; + wxString req; + std::vector::iterator accountIt; + std::vector::iterator categoryIt; - if (!user->_accounts.empty()) + if (!user->_accounts.empty()) { - for (accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++) + for (accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++) { - req = wxT("SELECT month, year, amount FROM account_amount WHERE account ='") + accountIt->id + wxT("'"); - req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))"); - req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))"); + req = wxT("SELECT month, year, amount FROM account_amount WHERE account ='") + accountIt->id + wxT("'"); + req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))"); + req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - while (set.NextRow()) + while (set.NextRow()) { - (*accountAmounts)[accountIt->id][set.GetInt(wxT("year"))][set.GetInt(wxT("month"))] = set.GetInt(wxT("amount")); + (*accountAmounts)[accountIt->id][set.GetInt(wxT("year"))][set.GetInt(wxT("month"))] = set.GetInt(wxT("amount")); } - set.Finalize(); + set.Finalize(); } - for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++) + for (categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++) { - req = wxT("SELECT SUM(amount) as amount FROM operation WHERE category='") + categoryIt->id + wxT("'"); - accountIt = user->_accounts.begin(); - req += wxT(" AND (account IN('") + accountIt->id; - accountIt++; - for (;accountIt != user->_accounts.end(); accountIt++) + req = wxT("SELECT SUM(amount) as amount FROM operation WHERE category='") + categoryIt->id + wxT("'"); + accountIt = user->_accounts.begin(); + req += wxT(" AND (account IN('") + accountIt->id; + accountIt++; + for (;accountIt != user->_accounts.end(); accountIt++) { - req += wxT("', '") + accountIt->id ; + req += wxT("', '") + accountIt->id ; } - req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("')"); + req += wxT("')"); + req += wxT(" OR user='") + user->_id + wxT("')"); - req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))"); - req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))"); - req += wxT(" AND (transfert='' OR transfert IS NULL)"); - req += wxT(" AND amount < 0"); + req += wxT(" AND (year > '") + yearFrom + wxT("' OR (year == '") + yearFrom + wxT("' AND month >= '") + monthFrom + wxT("'))"); + req += wxT(" AND (year < '") + yearTo + wxT("' OR (year == '") + yearTo + wxT("' AND month <= '") + monthTo + wxT("'))"); + req += wxT(" AND (transfert='' OR transfert IS NULL)"); + req += wxT(" AND amount < 0"); - EXECUTE_SQL_QUERY(req, set, ); + EXECUTE_SQL_QUERY(req, set, ); - if (set.NextRow()) + if (set.NextRow()) { - (*categories)[categoryIt->id] = -set.GetDouble(wxT("amount")); + (*categories)[categoryIt->id] = -set.GetDouble(wxT("amount")); } - set.Finalize(); + set.Finalize(); } } } std::map* Database::GetNotChecked(User* user, int month, int year) { - std::vector::iterator accountIt; - std::map* res = new std::map; - wxSQLite3ResultSet set; - wxString req; +std::vector::iterator accountIt; + std::map* res = new std::map; + wxSQLite3ResultSet set; + wxString req; - for (accountIt = user->_accounts.begin() ;accountIt != user->_accounts.end(); accountIt++) + for (accountIt = user->_accounts.begin() ;accountIt != user->_accounts.end(); accountIt++) { - req = wxT("SELECT SUM(amount) AS amount FROM operation WHERE account='") + accountIt->id + wxT("'"); - req += wxT(" AND checked='0'"); - req += wxT(" AND (year < '") + wxString::Format(wxT("%d"), year) + wxT("'") ; - req += wxT(" OR (year == '") + wxString::Format(wxT("%d"), year) + wxT("'") ; - req += wxT(" AND month < '") + wxString::Format(wxT("%d"), month) + wxT("'") ; - req += wxT("))"); + req = wxT("SELECT SUM(amount) AS amount FROM operation WHERE account='") + accountIt->id + wxT("'"); + req += wxT(" AND checked='0'"); + req += wxT(" AND (year < '") + wxString::Format(wxT("%d"), year) + wxT("'") ; + req += wxT(" OR (year == '") + wxString::Format(wxT("%d"), year) + wxT("'") ; + req += wxT(" AND month < '") + wxString::Format(wxT("%d"), month) + wxT("'") ; + req += wxT("))"); - EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, delete res, delete res); + EXECUTE_SQL_QUERY_WITH_CODE(req, set, NULL, delete res, delete res); - if (set.NextRow()) - (*res)[accountIt->id] = set.GetDouble(wxT("amount")); + if (set.NextRow()) + (*res)[accountIt->id] = set.GetDouble(wxT("amount")); } - return res; + return res; } diff --git a/src/model/Database.h b/src/model/Database.h index 7d211fc..c18d4cc 100644 --- a/src/model/Database.h +++ b/src/model/Database.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef DATABASE_H @@ -34,58 +34,58 @@ along with KissCount. If not, see . class Database { - public: - Database(const char* filename); +public: + Database(const char* filename); - std::list GetUsers(); - bool IsValidUser(const wxString& user, const wxString& password); + std::list GetUsers(); + bool IsValidUser(const wxString& user, const wxString& password); - User* LoadUser(const wxString& name); - void LoadYear(User* user, int year); + User* LoadUser(const wxString& name); + void LoadYear(User* user, int year); - void UpdateOperation(Operation& op); - wxString AddOperation(User* user, Operation& op); - void DeleteOperation(Operation& op); - void DeleteOperations(User* user, int month, int year); - double GetAccountAmount(const wxString& id, int month, int year); - void SetAccountAmount(int month, int year, const wxString& accountId, double amount); + void UpdateOperation(Operation& op); + wxString AddOperation(User* user, Operation& op); + void DeleteOperation(Operation& op); + void DeleteOperations(User* user, int month, int year); + double GetAccountAmount(const wxString& id, int month, int year); + void SetAccountAmount(int month, int year, const wxString& accountId, double amount); - wxString AddAccount(User* user, Account& ac); - void UpdateAccount(Account& ac); - void DeleteAccount(Account& ac); + wxString AddAccount(User* user, Account& ac); + void UpdateAccount(Account& ac); + void DeleteAccount(Account& ac); - wxString AddCategory(User* user, Category& category); - void UpdateCategory(Category& category); - void DeleteCategory(User* user, Category& category); + wxString AddCategory(User* user, Category& category); + void UpdateCategory(Category& category); + void DeleteCategory(User* user, Category& category); - std::map > GetAllOperations(User* user); - void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo); + std::map > GetAllOperations(User* user); + void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo); - void ChangePassword(User* user, const wxString& password); - bool UserExists(const wxString& name); - void ChangeName(User* user, const wxString& name); - void NewUser(const wxString& name); + void ChangePassword(User* user, const wxString& password); + bool UserExists(const wxString& name); + void ChangeName(User* user, const wxString& name); + void NewUser(const wxString& name); - void UpdatePreference(User* user, const wxString& preference); + void UpdatePreference(User* user, const wxString& preference); - std::vector* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, - wxString* amountFrom, wxString* amountTo, - std::vector categories, std::vector accounts); + std::vector* Search(User* user, wxString* description, wxDateTime* dateFrom, wxDateTime* dateTo, + wxString* amountFrom, wxString* amountTo, + std::vector categories, std::vector accounts); - void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo, - const wxString& yearTo, std::map > >* accountAmounts, - std::map* categories); + void GetStats(User* user, const wxString& monthFrom, const wxString& yearFrom, const wxString& monthTo, + const wxString& yearTo, std::map > >* accountAmounts, + std::map* categories); - void KillMe(User* user); - bool GetOperation(const wxString& id, Operation* op); - std::map* GetNotChecked(User* user, int month, int year); + void KillMe(User* user); + bool GetOperation(const wxString& id, Operation* op); + std::map* GetNotChecked(User* user, int month, int year); - private: - wxSQLite3Database _db; +private: + wxSQLite3Database _db; - void CreateDatabase(); - wxString HashPassword(const wxString& password); - void LinkOrUnlinkOperation(Operation& op); + void CreateDatabase(); + wxString HashPassword(const wxString& password); + void LinkOrUnlinkOperation(Operation& op); }; #endif diff --git a/src/model/Operation.h b/src/model/Operation.h index ddf49af..be0b2a0 100644 --- a/src/model/Operation.h +++ b/src/model/Operation.h @@ -1,40 +1,40 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef OPERATION_H #define OPERATION_H class Operation { - public: - wxString id; - wxString parent; - unsigned int day; - unsigned int month; - unsigned int year; - double amount; - wxString description; - wxString category; - bool fix_cost; - wxString account; - bool checked; - wxString transfert; - wxString formula; +public: + wxString id; + wxString parent; + unsigned int day; + unsigned int month; + unsigned int year; + double amount; + wxString description; + wxString category; + bool fix_cost; + wxString account; + bool checked; + wxString transfert; + wxString formula; } ; #endif diff --git a/src/model/User.cpp b/src/model/User.cpp index cdf3a43..f7f3048 100644 --- a/src/model/User.cpp +++ b/src/model/User.cpp @@ -1,150 +1,150 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "User.h" User::~User() { - std::map >* >::iterator it; + std::map >* >::iterator it; - for (it = _operations.begin(); it != _operations.end(); it++) + for (it = _operations.begin(); it != _operations.end(); it++) { - if (_operations[it->first]) + if (_operations[it->first]) { - delete it->second; + delete it->second; } } } Category User::GetCategory(wxString& catId) { - Category cat; - std::vector::iterator it; + Category cat; + std::vector::iterator it; - for (it=_categories.begin(); it !=_categories.end(); it++) - if (it->id == catId) - return *it; + for (it=_categories.begin(); it !=_categories.end(); it++) + if (it->id == catId) + return *it; - cat.id = wxT("0"); - cat.parent = wxT("0"); - cat.name = _("Unknown"); - cat.font = wxT(""); - cat.color = wxColour(0xFF, 0xFF, 0xFF); + cat.id = wxT("0"); + cat.parent = wxT("0"); + cat.name = _("Unknown"); + cat.font = wxT(""); + cat.color = wxColour(0xFF, 0xFF, 0xFF); - return cat; + return cat; } wxString User::GetCategoryName(wxString& catId) { - std::vector::iterator it; - for (it=_categories.begin(); it !=_categories.end(); it++) - if (it->id == catId) - return it->name; + std::vector::iterator it; + for (it=_categories.begin(); it !=_categories.end(); it++) + if (it->id == catId) + return it->name; - return _("Unknown") ; + return _("Unknown") ; } wxString User::GetCategoryId(wxString& catName) { - std::vector::iterator it; - for (it=_categories.begin(); it !=_categories.end(); it++) - if (it->name == catName) - return it->id; + std::vector::iterator it; + for (it=_categories.begin(); it !=_categories.end(); it++) + if (it->name == catName) + return it->id; - return wxT("0") ; + return wxT("0") ; } wxString User::GetAccountName(const 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() { - return _categories.size(); + return _categories.size(); } int User::GetAccountsNumber() { - return _accounts.size(); + return _accounts.size(); } int User::GetOperationsNumber(int month, int year) { - return (*_operations[year])[month].size(); + return (*_operations[year])[month].size(); } wxLanguage User::GetLanguage() { - wxString res = _preferences[wxT("language")]; - long val; + wxString res = _preferences[wxT("language")]; + long val; - if (!res.Length()) - return wxLANGUAGE_ENGLISH ; + if (!res.Length()) + return wxLANGUAGE_ENGLISH ; - res.ToLong(&val); + res.ToLong(&val); - return (wxLanguage)val; + return (wxLanguage)val; } void User::LinkOrUnlinkOperation(Operation& op) { - std::vector::iterator it; + std::vector::iterator it; - // Not Linked - if (!op.transfert.Length()) + // Not Linked + if (!op.transfert.Length()) { - for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++) + for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++) { - if (it->id != op.id && it->transfert == op.id) + if (it->id != op.id && it->transfert == op.id) { - it->transfert = wxT(""); - return; + it->transfert = wxT(""); + return; } } } - // Linked - else + // Linked + else { - for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++) + for (it = (*_operations[op.year])[op.month].begin(); it != (*_operations[op.year])[op.month].end(); it++) { - if (it->id != op.id && it->id == op.transfert) + if (it->id != op.id && it->id == op.transfert) { - it->transfert = op.id; - return; + it->transfert = op.id; + return; } } - op.transfert = wxT(""); + op.transfert = wxT(""); } } diff --git a/src/model/User.h b/src/model/User.h index 135c3e9..570e8d1 100644 --- a/src/model/User.h +++ b/src/model/User.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef USER_H @@ -31,27 +31,27 @@ along with KissCount. If not, see . class User { - public: - ~User(); +public: + ~User(); - wxString _id; - wxString _name; - wxString _password; - std::vector _accounts; - std::map >* > _operations; - std::vector _categories; - std::map _preferences; + wxString _id; + wxString _name; + wxString _password; + std::vector _accounts; + std::map >* > _operations; + std::vector _categories; + std::map _preferences; - Category GetCategory(wxString& catId); - wxString GetCategoryName(wxString& catId); - wxString GetCategoryId(wxString& catName); - wxString GetAccountName(const wxString& accountId); - wxString GetAccountId(wxString& accountName); - int GetCategoriesNumber(); - int GetAccountsNumber(); - int GetOperationsNumber(int month, int year); - wxLanguage GetLanguage(); - void LinkOrUnlinkOperation(Operation& op); + Category GetCategory(wxString& catId); + wxString GetCategoryName(wxString& catId); + wxString GetCategoryId(wxString& catName); + wxString GetAccountName(const wxString& accountId); + wxString GetAccountId(wxString& accountName); + int GetCategoriesNumber(); + int GetAccountsNumber(); + int GetOperationsNumber(int month, int year); + wxLanguage GetLanguage(); + void LinkOrUnlinkOperation(Operation& op); }; #endif diff --git a/src/model/model.h b/src/model/model.h index 676f278..9da861f 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef MODEL_H diff --git a/src/sha1.cpp b/src/sha1.cpp index fd212c9..e365a1e 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ /* @@ -75,11 +75,11 @@ along with KissCount. If not, see . */ #if defined(__i386__) || defined(__x86_64__) - #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val)) +#define setW(x, val) (*(volatile unsigned int *)&W(x) = (val)) #elif defined(__GNUC__) && defined(__arm__) - #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) +#define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) #else - #define setW(x, val) (W(x) = (val)) +#define setW(x, val) (W(x) = (val)) #endif /* @@ -89,9 +89,9 @@ along with KissCount. If not, see . * and is faster on architectures with memory alignment issues. */ -#if defined(__i386__) || defined(__x86_64__) || \ - defined(__ppc__) || defined(__ppc64__) || \ - defined(__powerpc__) || defined(__powerpc64__) || \ +#if defined(__i386__) || defined(__x86_64__) || \ + defined(__ppc__) || defined(__ppc64__) || \ + defined(__powerpc__) || defined(__powerpc64__) || \ defined(__s390__) || defined(__s390x__) #define get_be32(p) ntohl(*(unsigned int *)(p)) @@ -99,16 +99,16 @@ along with KissCount. If not, see . #else -#define get_be32(p) ( \ - (*((unsigned char *)(p) + 0) << 24) | \ - (*((unsigned char *)(p) + 1) << 16) | \ - (*((unsigned char *)(p) + 2) << 8) | \ +#define get_be32(p) ( \ + (*((unsigned char *)(p) + 0) << 24) | \ + (*((unsigned char *)(p) + 1) << 16) | \ + (*((unsigned char *)(p) + 2) << 8) | \ (*((unsigned char *)(p) + 3) << 0) ) -#define put_be32(p, v) do { \ - unsigned int __v = (v); \ - *((unsigned char *)(p) + 0) = __v >> 24; \ - *((unsigned char *)(p) + 1) = __v >> 16; \ - *((unsigned char *)(p) + 2) = __v >> 8; \ +#define put_be32(p, v) do { \ + unsigned int __v = (v); \ + *((unsigned char *)(p) + 0) = __v >> 24; \ + *((unsigned char *)(p) + 1) = __v >> 16; \ + *((unsigned char *)(p) + 2) = __v >> 8; \ *((unsigned char *)(p) + 3) = __v >> 0; } while (0) #endif @@ -123,9 +123,9 @@ along with KissCount. If not, see . #define SHA_SRC(t) get_be32(data + t) #define SHA_MIX(t) SHA_ROL(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1) -#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ - unsigned int TEMP = input(t); setW(t, TEMP); \ - E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ +#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ + unsigned int TEMP = input(t); setW(t, TEMP); \ + E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ B = SHA_ROR(B, 2); } while (0) #define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) @@ -136,167 +136,167 @@ along with KissCount. If not, see . static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data) { - unsigned int A,B,C,D,E; - unsigned int array[16]; + unsigned int A,B,C,D,E; + unsigned int array[16]; - A = ctx->H[0]; - B = ctx->H[1]; - C = ctx->H[2]; - D = ctx->H[3]; - E = ctx->H[4]; + A = ctx->H[0]; + B = ctx->H[1]; + C = ctx->H[2]; + D = ctx->H[3]; + E = ctx->H[4]; - /* Round 1 - iterations 0-16 take their input from 'data' */ - T_0_15( 0, A, B, C, D, E); - T_0_15( 1, E, A, B, C, D); - T_0_15( 2, D, E, A, B, C); - T_0_15( 3, C, D, E, A, B); - T_0_15( 4, B, C, D, E, A); - T_0_15( 5, A, B, C, D, E); - T_0_15( 6, E, A, B, C, D); - T_0_15( 7, D, E, A, B, C); - T_0_15( 8, C, D, E, A, B); - T_0_15( 9, B, C, D, E, A); - T_0_15(10, A, B, C, D, E); - T_0_15(11, E, A, B, C, D); - T_0_15(12, D, E, A, B, C); - T_0_15(13, C, D, E, A, B); - T_0_15(14, B, C, D, E, A); - T_0_15(15, A, B, C, D, E); + /* Round 1 - iterations 0-16 take their input from 'data' */ + T_0_15( 0, A, B, C, D, E); + T_0_15( 1, E, A, B, C, D); + T_0_15( 2, D, E, A, B, C); + T_0_15( 3, C, D, E, A, B); + T_0_15( 4, B, C, D, E, A); + T_0_15( 5, A, B, C, D, E); + T_0_15( 6, E, A, B, C, D); + T_0_15( 7, D, E, A, B, C); + T_0_15( 8, C, D, E, A, B); + T_0_15( 9, B, C, D, E, A); + T_0_15(10, A, B, C, D, E); + T_0_15(11, E, A, B, C, D); + T_0_15(12, D, E, A, B, C); + T_0_15(13, C, D, E, A, B); + T_0_15(14, B, C, D, E, A); + T_0_15(15, A, B, C, D, E); - /* Round 1 - tail. Input from 512-bit mixing array */ - T_16_19(16, E, A, B, C, D); - T_16_19(17, D, E, A, B, C); - T_16_19(18, C, D, E, A, B); - T_16_19(19, B, C, D, E, A); + /* Round 1 - tail. Input from 512-bit mixing array */ + T_16_19(16, E, A, B, C, D); + T_16_19(17, D, E, A, B, C); + T_16_19(18, C, D, E, A, B); + T_16_19(19, B, C, D, E, A); - /* Round 2 */ - T_20_39(20, A, B, C, D, E); - T_20_39(21, E, A, B, C, D); - T_20_39(22, D, E, A, B, C); - T_20_39(23, C, D, E, A, B); - T_20_39(24, B, C, D, E, A); - T_20_39(25, A, B, C, D, E); - T_20_39(26, E, A, B, C, D); - T_20_39(27, D, E, A, B, C); - T_20_39(28, C, D, E, A, B); - T_20_39(29, B, C, D, E, A); - T_20_39(30, A, B, C, D, E); - T_20_39(31, E, A, B, C, D); - T_20_39(32, D, E, A, B, C); - T_20_39(33, C, D, E, A, B); - T_20_39(34, B, C, D, E, A); - T_20_39(35, A, B, C, D, E); - T_20_39(36, E, A, B, C, D); - T_20_39(37, D, E, A, B, C); - T_20_39(38, C, D, E, A, B); - T_20_39(39, B, C, D, E, A); + /* Round 2 */ + T_20_39(20, A, B, C, D, E); + T_20_39(21, E, A, B, C, D); + T_20_39(22, D, E, A, B, C); + T_20_39(23, C, D, E, A, B); + T_20_39(24, B, C, D, E, A); + T_20_39(25, A, B, C, D, E); + T_20_39(26, E, A, B, C, D); + T_20_39(27, D, E, A, B, C); + T_20_39(28, C, D, E, A, B); + T_20_39(29, B, C, D, E, A); + T_20_39(30, A, B, C, D, E); + T_20_39(31, E, A, B, C, D); + T_20_39(32, D, E, A, B, C); + T_20_39(33, C, D, E, A, B); + T_20_39(34, B, C, D, E, A); + T_20_39(35, A, B, C, D, E); + T_20_39(36, E, A, B, C, D); + T_20_39(37, D, E, A, B, C); + T_20_39(38, C, D, E, A, B); + T_20_39(39, B, C, D, E, A); - /* Round 3 */ - T_40_59(40, A, B, C, D, E); - T_40_59(41, E, A, B, C, D); - T_40_59(42, D, E, A, B, C); - T_40_59(43, C, D, E, A, B); - T_40_59(44, B, C, D, E, A); - T_40_59(45, A, B, C, D, E); - T_40_59(46, E, A, B, C, D); - T_40_59(47, D, E, A, B, C); - T_40_59(48, C, D, E, A, B); - T_40_59(49, B, C, D, E, A); - T_40_59(50, A, B, C, D, E); - T_40_59(51, E, A, B, C, D); - T_40_59(52, D, E, A, B, C); - T_40_59(53, C, D, E, A, B); - T_40_59(54, B, C, D, E, A); - T_40_59(55, A, B, C, D, E); - T_40_59(56, E, A, B, C, D); - T_40_59(57, D, E, A, B, C); - T_40_59(58, C, D, E, A, B); - T_40_59(59, B, C, D, E, A); + /* Round 3 */ + T_40_59(40, A, B, C, D, E); + T_40_59(41, E, A, B, C, D); + T_40_59(42, D, E, A, B, C); + T_40_59(43, C, D, E, A, B); + T_40_59(44, B, C, D, E, A); + T_40_59(45, A, B, C, D, E); + T_40_59(46, E, A, B, C, D); + T_40_59(47, D, E, A, B, C); + T_40_59(48, C, D, E, A, B); + T_40_59(49, B, C, D, E, A); + T_40_59(50, A, B, C, D, E); + T_40_59(51, E, A, B, C, D); + T_40_59(52, D, E, A, B, C); + T_40_59(53, C, D, E, A, B); + T_40_59(54, B, C, D, E, A); + T_40_59(55, A, B, C, D, E); + T_40_59(56, E, A, B, C, D); + T_40_59(57, D, E, A, B, C); + T_40_59(58, C, D, E, A, B); + T_40_59(59, B, C, D, E, A); - /* Round 4 */ - T_60_79(60, A, B, C, D, E); - T_60_79(61, E, A, B, C, D); - T_60_79(62, D, E, A, B, C); - T_60_79(63, C, D, E, A, B); - T_60_79(64, B, C, D, E, A); - T_60_79(65, A, B, C, D, E); - T_60_79(66, E, A, B, C, D); - T_60_79(67, D, E, A, B, C); - T_60_79(68, C, D, E, A, B); - T_60_79(69, B, C, D, E, A); - T_60_79(70, A, B, C, D, E); - T_60_79(71, E, A, B, C, D); - T_60_79(72, D, E, A, B, C); - T_60_79(73, C, D, E, A, B); - T_60_79(74, B, C, D, E, A); - T_60_79(75, A, B, C, D, E); - T_60_79(76, E, A, B, C, D); - T_60_79(77, D, E, A, B, C); - T_60_79(78, C, D, E, A, B); - T_60_79(79, B, C, D, E, A); + /* Round 4 */ + T_60_79(60, A, B, C, D, E); + T_60_79(61, E, A, B, C, D); + T_60_79(62, D, E, A, B, C); + T_60_79(63, C, D, E, A, B); + T_60_79(64, B, C, D, E, A); + T_60_79(65, A, B, C, D, E); + T_60_79(66, E, A, B, C, D); + T_60_79(67, D, E, A, B, C); + T_60_79(68, C, D, E, A, B); + T_60_79(69, B, C, D, E, A); + T_60_79(70, A, B, C, D, E); + T_60_79(71, E, A, B, C, D); + T_60_79(72, D, E, A, B, C); + T_60_79(73, C, D, E, A, B); + T_60_79(74, B, C, D, E, A); + T_60_79(75, A, B, C, D, E); + T_60_79(76, E, A, B, C, D); + T_60_79(77, D, E, A, B, C); + T_60_79(78, C, D, E, A, B); + T_60_79(79, B, C, D, E, A); - ctx->H[0] += A; - ctx->H[1] += B; - ctx->H[2] += C; - ctx->H[3] += D; - ctx->H[4] += E; + ctx->H[0] += A; + ctx->H[1] += B; + ctx->H[2] += C; + ctx->H[3] += D; + ctx->H[4] += E; } void blk_SHA1_Init(blk_SHA_CTX *ctx) { - ctx->size = 0; + ctx->size = 0; - /* Initialize H with the magic constants (see FIPS180 for constants) */ - ctx->H[0] = 0x67452301; - ctx->H[1] = 0xefcdab89; - ctx->H[2] = 0x98badcfe; - ctx->H[3] = 0x10325476; - ctx->H[4] = 0xc3d2e1f0; + /* Initialize H with the magic constants (see FIPS180 for constants) */ + ctx->H[0] = 0x67452301; + ctx->H[1] = 0xefcdab89; + ctx->H[2] = 0x98badcfe; + ctx->H[3] = 0x10325476; + ctx->H[4] = 0xc3d2e1f0; } void blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) { - int lenW = ctx->size & 63; + int lenW = ctx->size & 63; - ctx->size += len; + ctx->size += len; - /* Read the data into W and process blocks as they get full */ - if (lenW) { - unsigned long left = 64 - lenW; - if (len < left) - left = len; - memcpy(lenW + (char *)ctx->W, data, left); - lenW = (lenW + left) & 63; - len -= left; - data = ((const char *)data + left); - if (lenW) - return; - blk_SHA1_Block(ctx, ctx->W); - } - while (len >= 64) { - blk_SHA1_Block(ctx, (const unsigned int*) data); - data = ((const char *)data + 64); - len -= 64; - } - if (len) - memcpy(ctx->W, data, len); + /* Read the data into W and process blocks as they get full */ + if (lenW) { + unsigned long left = 64 - lenW; + if (len < left) + left = len; + memcpy(lenW + (char *)ctx->W, data, left); + lenW = (lenW + left) & 63; + len -= left; + data = ((const char *)data + left); + if (lenW) + return; + blk_SHA1_Block(ctx, ctx->W); + } + while (len >= 64) { + blk_SHA1_Block(ctx, (const unsigned int*) data); + data = ((const char *)data + 64); + len -= 64; + } + if (len) + memcpy(ctx->W, data, len); } void blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx) { - static const unsigned char pad[64] = { 0x80 }; - unsigned int padlen[2]; - int i; + static const unsigned char pad[64] = { 0x80 }; + unsigned int padlen[2]; + int i; - /* Pad with a binary 1 (ie 0x80), then zeroes, then length */ - padlen[0] = htonl(ctx->size >> 29); - padlen[1] = htonl(ctx->size << 3); + /* Pad with a binary 1 (ie 0x80), then zeroes, then length */ + padlen[0] = htonl(ctx->size >> 29); + padlen[1] = htonl(ctx->size << 3); - i = ctx->size & 63; - blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i))); - blk_SHA1_Update(ctx, padlen, 8); + i = ctx->size & 63; + blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i))); + blk_SHA1_Update(ctx, padlen, 8); - /* Output hash */ - for (i = 0; i < 5; i++) - put_be32(hashout + i*4, ctx->H[i]); + /* Output hash */ + for (i = 0; i < 5; i++) + put_be32(hashout + i*4, ctx->H[i]); } diff --git a/src/sha1.h b/src/sha1.h index dc1c00a..c99cd9f 100644 --- a/src/sha1.h +++ b/src/sha1.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ /* @@ -26,9 +26,9 @@ along with KissCount. If not, see . */ typedef struct { - unsigned long long size; - unsigned int H[5]; - unsigned int W[16]; + unsigned long long size; + unsigned int H[5]; + unsigned int W[16]; } blk_SHA_CTX; void blk_SHA1_Init(blk_SHA_CTX *ctx); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index b3bc069..02e0a70 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "AccountPanel.h" @@ -38,1077 +38,1077 @@ 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 ; - User* user = _kiss->GetUser(); - std::vector::iterator accountIt; - std::vector::iterator categoryIt; - DEFAULT_FONT(font); + wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL); + wxChartPanel* chart ; + int i ; + User* user = _kiss->GetUser(); + std::vector::iterator accountIt; + std::vector::iterator categoryIt; + DEFAULT_FONT(font); - 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 = 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[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(_kiss, this, OPS_GRID_ID); + _grid = new GridAccount(_kiss, this, OPS_GRID_ID); - _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, wxID_ANY); + _statsGrid = new wxGrid(this, wxID_ANY); - chart = new wxChartPanel(this); - chart->SetChart(new Chart(_pie, _("Cost repartition"))); - chart->Fit(); - chart->Layout(); - chart->SetMinSize(// chart->GetSize() - wxSize(200,250)); + chart = new wxChartPanel(this); + chart->SetChart(new Chart(_pie, _("Cost repartition"))); + chart->Fit(); + chart->Layout(); + chart->SetMinSize(// chart->GetSize() + wxSize(200,250)); - _checkCheckMode = new wxCheckBox(this, CHECK_MODE_ID, _("Check mode")); + _checkCheckMode = new wxCheckBox(this, CHECK_MODE_ID, _("Check mode")); - 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); - vbox->Add(_checkCheckMode, 0); - hbox->Add(-1, 10); - hbox->Add(vbox, 0); + 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); + vbox->Add(_checkCheckMode, 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() { - delete[] _categoriesValues; - delete[] _categories; - delete[] _accounts; + delete[] _categoriesValues; + delete[] _categories; + delete[] _accounts; } void AccountPanel::InitStatsGrid(User* user) { - int i; + int i; - DEFAULT_FONT(font); + DEFAULT_FONT(font); - if (!_statsGrid->GetNumberRows()) + if (!_statsGrid->GetNumberRows()) { - _statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2); - _statsGrid->SetColLabelSize(0); - _statsGrid->SetRowLabelSize(0); - _statsGrid->EnableEditing(false); + _statsGrid->CreateGrid(user->GetCategoriesNumber()+6, 2); + _statsGrid->SetColLabelSize(0); + _statsGrid->SetRowLabelSize(0); + _statsGrid->EnableEditing(false); } - else + else { - _statsGrid->DeleteRows(0, _statsGrid->GetNumberRows()); - _statsGrid->InsertRows(0, user->GetCategoriesNumber()+6); + _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++) + for(i=0; iGetCategoriesNumber(); i++) { - _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]); - _statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _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); + 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() { - User* user = _kiss->GetUser(); - int curYear = -1; - wxDateTime curDate; - wxTreeItemId rootNode, curNode; - std::map > ops; - std::map >::iterator it; + User* user = _kiss->GetUser(); + int curYear = -1; + wxDateTime curDate; + wxTreeItemId rootNode, curNode; + std::map > ops; + std::map >::iterator it; - ops = _kiss->GetAllOperations(); + ops = _kiss->GetAllOperations(); - InitStatsGrid(user); + InitStatsGrid(user); - _tree.DeleteAllItems(); - rootNode = _tree.AddRoot(wxT("")); + _tree.DeleteAllItems(); + rootNode = _tree.AddRoot(wxT("")); - curDate.SetToCurrent(); - for(it = ops.begin(); it != ops.end(); it++) + curDate.SetToCurrent(); + for(it = ops.begin(); it != ops.end(); it++) { - if ((int)it->first <= curDate.GetYear()) + if ((int)it->first <= curDate.GetYear()) { - curYear = it->first; - curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); + curYear = it->first; + curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); } - else - _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); + else + _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); } - Fit(); - if (curYear != -1) + Fit(); + if (curYear != -1) { - _tree.SelectItem(curNode, true); - LoadYear(curYear); + _tree.SelectItem(curNode, true); + LoadYear(curYear); } } void AccountPanel::LoadYear(int year, bool showMonth) { - User* user = _kiss->GetUser(); - int curMonth = -1; - wxDateTime curDate; - wxTreeItemId parentNode, curMonthNode; - std::map > ops ; - std::vector::iterator it; + User* user = _kiss->GetUser(); + int curMonth = -1; + wxDateTime curDate; + wxTreeItemId parentNode, curMonthNode; + std::map > ops ; + std::vector::iterator it; - if (user->_operations[year] && _tree.GetChildrenCount(_tree.GetSelection(), true)) + if (user->_operations[year] && _tree.GetChildrenCount(_tree.GetSelection(), true)) { - if (showMonth) - ShowMonth(-1, year); - return; + if (showMonth) + ShowMonth(-1, year); + return; } - _curYear = year ; - _kiss->LoadYear(year); - ops = _kiss->GetAllOperations(); + _curYear = year ; + _kiss->LoadYear(year); + ops = _kiss->GetAllOperations(); - curDate.SetToCurrent(); - parentNode = _tree.GetSelection(); + curDate.SetToCurrent(); + parentNode = _tree.GetSelection(); - for (it = ops[year].begin(); it != ops[year].end(); it++) + for (it = ops[year].begin(); it != ops[year].end(); it++) { - if (curMonth == -1 || (year == curDate.GetYear() && *it <= curDate.GetMonth())) + if (curMonth == -1 || (year == curDate.GetYear() && *it <= curDate.GetMonth())) { - curMonth = *it; - curMonthNode = _tree.AppendItem(parentNode, months[*it]); + curMonth = *it; + curMonthNode = _tree.AppendItem(parentNode, months[*it]); } - else - _tree.AppendItem(parentNode, months[*it]); + else + _tree.AppendItem(parentNode, months[*it]); } - _tree.Expand(parentNode); - Fit(); - if (showMonth) + _tree.Expand(parentNode); + Fit(); + if (showMonth) { - _tree.SelectItem(curMonthNode, true); - ShowMonth(curMonth, year); + _tree.SelectItem(curMonthNode, true); + ShowMonth(curMonth, year); } - _wxUI->Layout(); + _wxUI->Layout(); } #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) { - std::vector operations; - std::vector::iterator it; - _fixCosts = 0; - int curLine = 0; - User* user = _kiss->GetUser(); - DEFAULT_FONT(font); - std::vector::iterator categoryIt; - std::map >::iterator monthIt; - wxDateTime curDate; - curDate.SetToCurrent(); + std::vector operations; + std::vector::iterator it; + _fixCosts = 0; + int curLine = 0; + User* user = _kiss->GetUser(); + DEFAULT_FONT(font); + std::vector::iterator categoryIt; + std::map >::iterator monthIt; + wxDateTime curDate; + curDate.SetToCurrent(); - if (month == -1) + if (month == -1) { - // Near month - if (year == curDate.GetYear()) + // Near month + if (year == curDate.GetYear()) { - for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++) + for (monthIt = user->_operations[year]->begin(); monthIt != user->_operations[year]->end(); monthIt++) { - if ((int)monthIt->first <= curDate.GetMonth()) + if ((int)monthIt->first <= curDate.GetMonth()) { - month = monthIt->first; + month = monthIt->first; } } } - // First month - if (month == -1) + // First month + if (month == -1) { - monthIt = user->_operations[year]->begin(); - if (user->_operations[year]->size() == 0 && year == curDate.GetYear()) - month = curDate.GetMonth(); - else - month = monthIt->first; + monthIt = user->_operations[year]->begin(); + if (user->_operations[year]->size() == 0 && year == curDate.GetYear()) + month = curDate.GetMonth(); + else + month = monthIt->first; } } - _curYear = year; - _curMonth = month; - _wxUI->SetTitle(user->_name + wxT(" - ") + months[month] + wxT(" ") + wxString::Format(wxT("%d"), year)); - _calendar->Enable(true); + _curYear = year; + _curMonth = month; + _wxUI->SetTitle(user->_name + wxT(" - ") + months[month] + wxT(" ") + wxString::Format(wxT("%d"), year)); + _calendar->Enable(true); - if (_grid->GetNumberRows() > 1) - _grid->DeleteRows(1, _grid->GetNumberRows()-1); + if (_grid->GetNumberRows() > 1) + _grid->DeleteRows(1, _grid->GetNumberRows()-1); - // Operations are ordered - _curOperations = &((*user->_operations[year])[month]); + // Operations are ordered + _curOperations = &((*user->_operations[year])[month]); - it = _curOperations->begin(); + it = _curOperations->begin(); - for (;it != _curOperations->end() && it->fix_cost; it++) - InsertOperation(user, &(*it), ++curLine, true); + for (;it != _curOperations->end() && it->fix_cost; it++) + InsertOperation(user, &(*it), ++curLine, true); - InsertOperation(user, NULL, ++curLine, true); - _grid->_fixCosts = _fixCosts--; + InsertOperation(user, NULL, ++curLine, true); + _grid->_fixCosts = _fixCosts--; - for (; it != _curOperations->end(); it++) - InsertOperation(user, &(*it), ++curLine, false); + for (; it != _curOperations->end(); it++) + InsertOperation(user, &(*it), ++curLine, false); - InsertOperation(user, NULL, ++curLine, false); + InsertOperation(user, NULL, ++curLine, false); - _grid->AutoSizeColumn(CATEGORY, false); - _grid->AutoSizeColumn(DATE, false); - _grid->AutoSizeColumn(ACCOUNT, false); - _grid->AutoSizeColumn(DELETE, false); - _grid->AutoSizeColumn(CHECKED, false); + _grid->AutoSizeColumn(CATEGORY, false); + _grid->AutoSizeColumn(DATE, false); + _grid->AutoSizeColumn(ACCOUNT, false); + _grid->AutoSizeColumn(DELETE, false); + _grid->AutoSizeColumn(CHECKED, false); - InitAccountsGrid(user, month, year); + InitAccountsGrid(user, month, year); - _calendar->EnableMonthChange(true); - _calendar->EnableYearChange(true); - if (curDate.GetMonth() == month && curDate.GetYear() == year) - _calendar->SetDate(curDate) ; - else if (curDate.GetMonth() > month || curDate.GetYear() > year) - _calendar->SetDate(curDate.GetLastMonthDay((wxDateTime::Month)month, year)); - else if (curDate.GetMonth() < month || curDate.GetYear() < year) - _calendar->SetDate(wxDateTime(1, (wxDateTime::Month)month, year)); + _calendar->EnableMonthChange(true); + _calendar->EnableYearChange(true); + if (curDate.GetMonth() == month && curDate.GetYear() == year) + _calendar->SetDate(curDate) ; + else if (curDate.GetMonth() > month || curDate.GetYear() > year) + _calendar->SetDate(curDate.GetLastMonthDay((wxDateTime::Month)month, year)); + else if (curDate.GetMonth() < month || curDate.GetYear() < year) + _calendar->SetDate(wxDateTime(1, (wxDateTime::Month)month, year)); - _calendar->EnableMonthChange(false); - _calendar->EnableYearChange(false); - _calendar->SetSize(_calendar->GetMinSize()); + _calendar->EnableMonthChange(false); + _calendar->EnableYearChange(false); + _calendar->SetSize(_calendar->GetMinSize()); - UpdateStats(); + UpdateStats(); - Fit(); - // SetMinSize(GetSize()); + Fit(); + // SetMinSize(GetSize()); } void AccountPanel::InsertOperation(User* user, Operation* op, int line, bool fix) { - std::vector::iterator it; - int curLine, curWeek, week, i; + std::vector::iterator it; + int curLine, curWeek, week, i; - _grid->InsertOperation(user, op, line, fix, _curMonth, _curYear); + _grid->InsertOperation(user, op, line, fix, _curMonth, _curYear); - if (fix) - _fixCosts++; + if (fix) + _fixCosts++; - if (op && !fix) + if (op && !fix) { - for (it = _curOperations->begin(), curLine=1; - it->fix_cost && it != _curOperations->end(); - it++, curLine++) ; + for (it = _curOperations->begin(), curLine=1; + it->fix_cost && it != _curOperations->end(); + it++, curLine++) ; - if (it == _curOperations->end()) return; + 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++) + 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; } } } - _wxUI->Layout(); + _wxUI->Layout(); } void AccountPanel::InitAccountsGrid(User* user, int month, int year) { - std::vector::iterator it; - int curLine = 0; - double value; - int i, a; - DEFAULT_FONT(font); + std::vector::iterator it; + int curLine = 0; + double value; + int i, a; + DEFAULT_FONT(font); - if (_accountsGrid->GetNumberRows()) - _accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows()); + if (_accountsGrid->GetNumberRows()) + _accountsGrid->DeleteRows(0, _accountsGrid->GetNumberRows()); - font.SetWeight(wxFONTWEIGHT_BOLD); + font.SetWeight(wxFONTWEIGHT_BOLD); - for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++) + for (i=0, it = user->_accounts.begin(); it != user->_accounts.end(); i++, it++, curLine++) { - _accountsGrid->AppendRows(); + _accountsGrid->AppendRows(); - _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); - _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); - value = _kiss->GetAccountAmount(it->id, month, year); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2)); - _accountsGrid->SetCellValue(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value)); - for (a=0; aSetReadOnly(curLine, a, a != ACCOUNT_INIT); - _accountsGrid->SetCellFont(curLine, ACCOUNT_CUR, font); + _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); + _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); + value = _kiss->GetAccountAmount(it->id, month, year); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_INIT, new wxGridCellFloatEditor(-1, 2)); + _accountsGrid->SetCellValue(curLine, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value)); + for (a=0; aSetReadOnly(curLine, a, a != ACCOUNT_INIT); + _accountsGrid->SetCellFont(curLine, ACCOUNT_CUR, font); - _accountsInitValues[it->id] = value; - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE); + _accountsInitValues[it->id] = value; + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_INIT, wxALIGN_RIGHT, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_CUR, wxALIGN_RIGHT, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_FINAL, wxALIGN_RIGHT, wxALIGN_CENTRE); } - _accountsGrid->AutoSizeColumns(true); + _accountsGrid->AutoSizeColumns(true); } void AccountPanel::UpdateStats() { - int i; - User* user = _kiss->GetUser(); - std::vector::iterator it; - double curCredit, curDebit, totalCredit, totalDebit, remains, value, value2, percents; - std::map curAccountAmount, finalAccountAmount; - std::map::iterator doubleIt; - std::map::iterator intIt; - std::vector::iterator accountIt; - unsigned int day; - bool checkMode = _checkCheckMode->IsChecked(); - std::map* notChecked = NULL; + int i; + User* user = _kiss->GetUser(); + std::vector::iterator it; + double curCredit, curDebit, totalCredit, totalDebit, remains, value, value2, percents; + std::map curAccountAmount, finalAccountAmount; + std::map::iterator doubleIt; + std::map::iterator intIt; + std::vector::iterator accountIt; + unsigned int day; + bool checkMode = _checkCheckMode->IsChecked(); + std::map* notChecked = NULL; - curCredit = curDebit = totalCredit = totalDebit = percents = 0.0; + curCredit = curDebit = totalCredit = totalDebit = percents = 0.0; - if (checkMode) + if (checkMode) { - notChecked = _kiss->GetNotChecked(_curMonth, _curYear); + notChecked = _kiss->GetNotChecked(_curMonth, _curYear); } - day = _calendar->GetDate().GetDay()-1; + day = _calendar->GetDate().GetDay()-1; - for (i=0; iGetCategoriesNumber(); i++) - _categoriesValues[i] = 0.0; + for (i=0; iGetCategoriesNumber(); i++) + _categoriesValues[i] = 0.0; - for (doubleIt=_accountsInitValues.begin(); doubleIt!=_accountsInitValues.end(); doubleIt++) + for (doubleIt=_accountsInitValues.begin(); doubleIt!=_accountsInitValues.end(); doubleIt++) { - curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; - finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; + curAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; + finalAccountAmount[doubleIt->first] = _accountsInitValues[doubleIt->first]; } - for (it=_curOperations->begin(); it!=_curOperations->end(); it++) + for (it=_curOperations->begin(); it!=_curOperations->end(); it++) { - if (it->amount > 0) + if (it->amount > 0) { - if (day >= it->day) + if (day >= it->day) { - if (!it->transfert.Length()) - curCredit += it->amount; - if (!checkMode || (checkMode && it->checked)) - curAccountAmount[it->account] += it->amount; + if (!it->transfert.Length()) + curCredit += it->amount; + if (!checkMode || (checkMode && it->checked)) + curAccountAmount[it->account] += it->amount; } - if (!it->transfert.Length()) - totalCredit += it->amount; - if (!checkMode || (checkMode && it->checked)) - finalAccountAmount[it->account] += it->amount; + if (!it->transfert.Length()) + totalCredit += it->amount; + if (!checkMode || (checkMode && it->checked)) + finalAccountAmount[it->account] += it->amount; } - else + else { - if (!it->transfert.Length()) - _categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ; - if (day >= it->day) + if (!it->transfert.Length()) + _categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ; + if (day >= it->day) { - if (!it->transfert.Length()) - curDebit += -it->amount; - if (!checkMode || (checkMode && it->checked)) - curAccountAmount[it->account] += it->amount; + if (!it->transfert.Length()) + curDebit += -it->amount; + if (!checkMode || (checkMode && it->checked)) + curAccountAmount[it->account] += it->amount; } - if (!it->transfert.Length()) - totalDebit += -it->amount; - if (!checkMode || (checkMode && it->checked)) - finalAccountAmount[it->account] += it->amount; + if (!it->transfert.Length()) + totalDebit += -it->amount; + if (!checkMode || (checkMode && it->checked)) + finalAccountAmount[it->account] += it->amount; } } - remains = totalCredit - totalDebit; - _statsGrid->SetCellValue(CUR_CREDIT, 1, wxString::Format(wxT("%.2lf"), curCredit)); - _statsGrid->SetCellValue(CUR_DEBIT, 1, wxString::Format(wxT("%.2lf"), curDebit)); - _statsGrid->SetCellValue(TOTAL_CREDIT, 1, wxString::Format(wxT("%.2lf"), totalCredit)); - _statsGrid->SetCellValue(TOTAL_DEBIT, 1, wxString::Format(wxT("%.2lf"), totalDebit)); + remains = totalCredit - totalDebit; + _statsGrid->SetCellValue(CUR_CREDIT, 1, wxString::Format(wxT("%.2lf"), curCredit)); + _statsGrid->SetCellValue(CUR_DEBIT, 1, wxString::Format(wxT("%.2lf"), curDebit)); + _statsGrid->SetCellValue(TOTAL_CREDIT, 1, wxString::Format(wxT("%.2lf"), totalCredit)); + _statsGrid->SetCellValue(TOTAL_DEBIT, 1, wxString::Format(wxT("%.2lf"), totalDebit)); - _statsGrid->SetCellTextColour(REMAINS, 1, (remains >= 0) ? wxColor(0x00, 0xFF, 0x00) : wxColor(0xFF, 0x00, 0x00)); - _statsGrid->SetCellValue(REMAINS, 1, wxString::Format(wxT("%.2lf"), remains)); + _statsGrid->SetCellTextColour(REMAINS, 1, (remains >= 0) ? wxColor(0x00, 0xFF, 0x00) : wxColor(0xFF, 0x00, 0x00)); + _statsGrid->SetCellValue(REMAINS, 1, wxString::Format(wxT("%.2lf"), remains)); - for(i=0; iGetCategoriesNumber()+1; i++) + for(i=0; iGetCategoriesNumber()+1; i++) { - if (totalDebit != 0) - percents = ((double) (_categoriesValues[i]*100))/totalDebit; - else - percents = 0.0; - _statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents)); + if (totalDebit != 0) + percents = ((double) (_categoriesValues[i]*100))/totalDebit; + else + percents = 0.0; + _statsGrid->SetCellValue(CATS_STATS+i, 1, wxString::Format(wxT("%.2lf (%02d %%)"), _categoriesValues[i], (int)percents)); } - for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++) + for (i=0, accountIt=user->_accounts.begin(); accountIt!=user->_accounts.end(); accountIt++, i++) { - if (!checkMode || !notChecked) + if (!checkMode || !notChecked) { - value = _accountsInitValues[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value)); - value = curAccountAmount[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value)); - _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00)); - value = finalAccountAmount[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf"), value)); + value = _accountsInitValues[accountIt->id]; + _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf"), value)); + value = curAccountAmount[accountIt->id]; + _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf"), value)); + _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00)); + value = finalAccountAmount[accountIt->id]; + _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf"), value)); } - else + else { - value = _accountsInitValues[accountIt->id]; - value2 = (*notChecked)[accountIt->id]; + value = _accountsInitValues[accountIt->id]; + value2 = (*notChecked)[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); - value = curAccountAmount[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); - _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00)); - value = finalAccountAmount[accountIt->id]; - _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); + _accountsGrid->SetCellValue(i, ACCOUNT_INIT, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); + value = curAccountAmount[accountIt->id]; + _accountsGrid->SetCellValue(i, ACCOUNT_CUR, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); + _accountsGrid->SetCellTextColour(i, ACCOUNT_CUR, (value >= 0.0) ? wxColor(0x00, 0x00, 0x00) : wxColor(0xFF, 0x00, 0x00)); + value = finalAccountAmount[accountIt->id]; + _accountsGrid->SetCellValue(i, ACCOUNT_FINAL, wxString::Format(wxT("%.2lf (%.2lf)"), value, value+value2)); } } - _accountsGrid->AutoSizeColumn(ACCOUNT_INIT, true); - _accountsGrid->AutoSizeColumn(ACCOUNT_CUR, true); - _accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true); + _accountsGrid->AutoSizeColumn(ACCOUNT_INIT, true); + _accountsGrid->AutoSizeColumn(ACCOUNT_CUR, true); + _accountsGrid->AutoSizeColumn(ACCOUNT_FINAL, true); - if (notChecked) delete notChecked; + if (notChecked) delete notChecked; - _statsGrid->AutoSizeColumn(1, true); + _statsGrid->AutoSizeColumn(1, true); - _pie->DatasetChanged(_dataset); + _pie->DatasetChanged(_dataset); - Layout(); + Layout(); } void AccountPanel::OnOperationModified(wxGridEvent& event) { - User* user = _kiss->GetUser(); - int row = event.GetRow()-1; - int col = event.GetCol(); - Operation new_op, cur_op, op_tmp; - int op_complete = 6, i; - wxString value ; - wxDateTime date; - bool need_insertion = false, fix_op=false; - static bool inModification = false ; - wxColour color ; - unsigned char r, g, b; + User* user = _kiss->GetUser(); + int row = event.GetRow()-1; + int col = event.GetCol(); + Operation new_op, cur_op, op_tmp; + int op_complete = 6, i; + wxString value ; + wxDateTime date; + bool need_insertion = false, fix_op=false; + static bool inModification = false ; + wxColour color ; + unsigned char r, g, b; - // Avoid recursives calls - if (inModification) return; + // Avoid recursives calls + if (inModification) return; - inModification = true ; + inModification = true ; - if (event.GetCol() == DEBIT) - _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); - else if (event.GetCol() == CREDIT) - _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); + if (event.GetCol() == DEBIT) + _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); + else if (event.GetCol() == CREDIT) + _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); - value = _grid->GetCellValue(event.GetRow(), DESCRIPTION); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), DESCRIPTION); + if (value.Length()) { - new_op.description = value; - op_complete--; + new_op.description = value; + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), DATE); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), DATE); + if (value.Length()) { - 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--; + 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.Length()) + value = _grid->GetCellValue(event.GetRow(), DEBIT); + if (value.Length()) { - value.ToDouble(&new_op.amount); - new_op.amount *= -1.0; - op_complete--; + value.ToDouble(&new_op.amount); + new_op.amount *= -1.0; + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CREDIT); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), CREDIT); + if (value.Length()) { - value.ToDouble(&new_op.amount); - op_complete--; + value.ToDouble(&new_op.amount); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CATEGORY); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), CATEGORY); + if (value.Length()) { - new_op.category = user->GetCategoryId(value); - op_complete--; + new_op.category = user->GetCategoryId(value); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), ACCOUNT); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), ACCOUNT); + if (value.Length()) { - new_op.account = user->GetAccountId(value); - op_complete--; + new_op.account = user->GetAccountId(value); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CHECKED); - if (value.Length() && value != wxT("0")) - new_op.checked = true; - else - new_op.checked = false; - op_complete--; + value = _grid->GetCellValue(event.GetRow(), CHECKED); + if (value.Length() && value != wxT("0")) + new_op.checked = true; + else + new_op.checked = false; + op_complete--; - if (event.GetCol() == DESCRIPTION && - (!_grid->GetCellValue(event.GetRow(), CATEGORY).Length() || - !_grid->GetCellValue(event.GetRow(), ACCOUNT).Length())) + if (event.GetCol() == DESCRIPTION && + (!_grid->GetCellValue(event.GetRow(), CATEGORY).Length() || + !_grid->GetCellValue(event.GetRow(), ACCOUNT).Length())) { - if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear)) + if (_kiss->SearchPreviousOperation(&op_tmp, new_op.description, _curMonth, _curYear)) { - new_op.category = op_tmp.category; - new_op.account = op_tmp.account; - _grid->SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category)); - _grid->SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account)); - op_complete -= 2; + new_op.category = op_tmp.category; + new_op.account = op_tmp.account; + _grid->SetCellValue(event.GetRow(), CATEGORY, user->GetCategoryName(new_op.category)); + _grid->SetCellValue(event.GetRow(), ACCOUNT, user->GetAccountName(new_op.account)); + op_complete -= 2; } } - if (col == CHECKED || col == CATEGORY) + if (col == CHECKED || col == CATEGORY) { - color = user->GetCategory(new_op.category).color; + color = user->GetCategory(new_op.category).color; - if (new_op.checked) + 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()); + 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); + SET_ROW_COLOR(event.GetRow(), color); } - if (col == DELETE) + 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) + 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; + _grid->SetCellValue(event.GetRow(), event.GetCol(), wxT("0")); + inModification = false; + return; } } - // Modify a fix operation - if (row < _fixCosts) + // 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; - new_op.transfert = cur_op.transfert; + new_op.id = cur_op.id; + new_op.fix_cost = true; + new_op.transfert = cur_op.transfert; - 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); - _fixCosts--; - _kiss->UpdateOperation(new_op); + need_insertion = true; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); + _fixCosts--; + _kiss->UpdateOperation(new_op); } - else + else { - _kiss->UpdateOperation(new_op); - (*_curOperations)[row] = new_op; + _kiss->UpdateOperation(new_op); + (*_curOperations)[row] = new_op; } - fix_op = true; + fix_op = true; } - // Add a fixCost - else if (row == _fixCosts) + // Add a fixCost + else if (row == _fixCosts) { - if (op_complete) { - inModification = false ; - return ; - } - need_insertion = true; - fix_op = true; - new_op.fix_cost = true; + if (op_complete) { + inModification = false ; + return ; + } + need_insertion = true; + fix_op = true; + new_op.fix_cost = true; - for(i=0; iSetCellValue(event.GetRow(), i, wxT("")); + if (i == CATEGORY) continue; + _grid->SetCellValue(event.GetRow(), i, wxT("")); } - new_op.id = _kiss->AddOperation(new_op); + new_op.id = _kiss->AddOperation(new_op); } - // Modify an operation - else if (row <= user->GetOperationsNumber(_curMonth, _curYear)) + // 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; - new_op.transfert = cur_op.transfert; + row--; + cur_op = (*_curOperations)[row] ; + new_op.id = cur_op.id; + new_op.fix_cost = false; + new_op.transfert = cur_op.transfert; - 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); - _kiss->UpdateOperation(new_op); + need_insertion = true; + _grid->DeleteRows(event.GetRow(), 1); + _curOperations->erase(_curOperations->begin()+row); + _kiss->UpdateOperation(new_op); } - else + else { - _kiss->UpdateOperation(new_op); - (*_curOperations)[row] = new_op; + _kiss->UpdateOperation(new_op); + (*_curOperations)[row] = new_op; } } - // Add an operation - else + // Add an operation + else { - row--; - if (op_complete) { - inModification = false ; - return ; - } - need_insertion = true; - fix_op = false; - new_op.fix_cost = false; + row--; + if (op_complete) { + inModification = false ; + return ; + } + need_insertion = true; + fix_op = false; + new_op.fix_cost = false; - for(i=0; iSetCellValue(event.GetRow(), i, wxT("")); + _grid->SetCellValue(event.GetRow(), i, wxT("")); } - new_op.id = _kiss->AddOperation(new_op); + new_op.id = _kiss->AddOperation(new_op); } - if (need_insertion) + if (need_insertion) { - for(i=0; i<(int)_curOperations->size(); i++) + for(i=0; i<(int)_curOperations->size(); i++) { - if ((*_curOperations)[i].fix_cost && !fix_op) continue; - if (!(*_curOperations)[i].fix_cost && fix_op) break; - if (user->_preferences[wxT("operation_order")] == wxT("ASC")) + if ((*_curOperations)[i].fix_cost && !fix_op) continue; + if (!(*_curOperations)[i].fix_cost && fix_op) break; + if (user->_preferences[wxT("operation_order")] == wxT("ASC")) { - if ((*_curOperations)[i].day > new_op.day) - break; + if ((*_curOperations)[i].day > new_op.day) + break; } - else + else { - if ((*_curOperations)[i].day < new_op.day) - break; + if ((*_curOperations)[i].day < new_op.day) + break; } } - _curOperations->insert(_curOperations->begin()+i ,new_op); - i++; // For header - if (!fix_op) i++; - InsertOperation(user, &new_op, i, fix_op); - if (fix_op) - _grid->_fixCosts = _fixCosts+1; + _curOperations->insert(_curOperations->begin()+i ,new_op); + i++; // For header + if (!fix_op) i++; + InsertOperation(user, &new_op, i, fix_op); + if (fix_op) + _grid->_fixCosts = _fixCosts+1; } - UpdateStats(); - inModification = false ; + UpdateStats(); + inModification = false ; } void AccountPanel::OnAccountModified(wxGridEvent& event) { - User* user = _kiss->GetUser(); - int row = event.GetRow(); - double amount; - wxString id = user->GetAccountId(_accounts[row]); + User* user = _kiss->GetUser(); + int row = event.GetRow(); + double amount; + wxString id = user->GetAccountId(_accounts[row]); - static bool inModification = false; + static bool inModification = false; - if (inModification) return ; + if (inModification) return ; - inModification = true; + inModification = true; - _accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount); + _accountsGrid->GetCellValue(row, event.GetCol()).ToDouble(&amount); - _kiss->SetAccountAmount(_curMonth, _curYear, id, amount); - _accountsInitValues[id] = amount; + _kiss->SetAccountAmount(_curMonth, _curYear, id, amount); + _accountsInitValues[id] = amount; - UpdateStats(); + UpdateStats(); - inModification = false; + inModification = false; } void AccountPanel::OnTreeRightClick(wxTreeEvent& event) { - wxMenu menu(0); + wxMenu menu(0); - menu.Append(MENU_GENERATE_ID, _("Generate month")); - menu.AppendSeparator(); - if (_tree.GetCount() > 1) - menu.Append(MENU_DELETE_ID, _("Delete")); + menu.Append(MENU_GENERATE_ID, _("Generate month")); + menu.AppendSeparator(); + if (_tree.GetCount() > 1) + menu.Append(MENU_DELETE_ID, _("Delete")); - PopupMenu(&menu, event.GetPoint()); + PopupMenu(&menu, event.GetPoint()); } void AccountPanel::OnTreeChange(wxTreeEvent& event) { - int month=-1, year; - int i; - wxString monthString; - static bool inModification = false ; + int month=-1, year; + int i; + wxString monthString; + static bool inModification = false ; - if (inModification) return; + if (inModification) return; - inModification = true; + inModification = true; - monthString = _tree.GetItemText(event.GetItem()); - for (i=0; i<12; i++) - if (monthString == months[i]) - { - month = i; - break; - } + monthString = _tree.GetItemText(event.GetItem()); + for (i=0; i<12; i++) + if (monthString == months[i]) + { + month = i; + break; + } - if (month == -1) + if (month == -1) { - year = wxAtoi(monthString); + year = wxAtoi(monthString); - // Error - if (year == 0) + // Error + if (year == 0) { - inModification = false; - return; + inModification = false; + return; } - if (year == _curYear) + if (year == _curYear) { - inModification = false; - return; + inModification = false; + return; } - // _tree.CollapseAll(); - // _tree.Expand(event.GetItem()); - LoadYear(year, false); + // _tree.CollapseAll(); + // _tree.Expand(event.GetItem()); + LoadYear(year, false); } - else + else { - year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(event.GetItem()))); + year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(event.GetItem()))); - // Error - if (year == 0) + // Error + if (year == 0) { - inModification = false; - return; + inModification = false; + return; } - if (year != _curYear || month != _curMonth) + if (year != _curYear || month != _curMonth) { - ShowMonth(month, year); + ShowMonth(month, year); } } - inModification = false; + inModification = false; } void AccountPanel::GetTreeSelection(int* month, int* year) { - wxString monthString; - int i; + wxString monthString; + int i; - *month = -1; *year = -1; + *month = -1; *year = -1; - monthString = _tree.GetItemText(_tree.GetSelection()); - for (i=0; i<12; i++) - if (monthString == months[i]) - { - *month = i; - break; - } + monthString = _tree.GetItemText(_tree.GetSelection()); + for (i=0; i<12; i++) + if (monthString == months[i]) + { + *month = i; + break; + } - if (*month == -1) + if (*month == -1) { - *year = wxAtoi(monthString); + *year = wxAtoi(monthString); - // Error - if (year == 0) + // Error + if (year == 0) { - *month = -1; - *year = -1; - return; + *month = -1; + *year = -1; + return; } } - else + else { - *year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(_tree.GetSelection()))); + *year = wxAtoi(_tree.GetItemText(_tree.GetItemParent(_tree.GetSelection()))); - // Error - if (year == 0) + // Error + if (year == 0) { - *month = -1; - *year = -1; - return; + *month = -1; + *year = -1; + return; } } } void AccountPanel::OnMenuGenerate(wxCommandEvent& event) { - int month, year; - wxDateTime curDate; + int month, year; + wxDateTime curDate; - curDate.SetToCurrent(); + curDate.SetToCurrent(); - GetTreeSelection(&month, &year); + GetTreeSelection(&month, &year); - if (month == -1 && year == curDate.GetYear()) + if (month == -1 && year == curDate.GetYear()) { - month = _curMonth; + month = _curMonth; } - GenerateDialog g(_kiss, _wxUI, month, year); - g.ShowModal(); + GenerateDialog g(_kiss, _wxUI, month, year); + g.ShowModal(); } void AccountPanel::OnMenuDelete(wxCommandEvent& event) { - int month, year; - wxString message; - wxTreeItemId curNode, node ; - std::map > ops ; + int month, year; + wxString message; + wxTreeItemId curNode, node ; + std::map > ops ; - GetTreeSelection(&month, &year); + GetTreeSelection(&month, &year); - ops = _kiss->GetAllOperations(); + ops = _kiss->GetAllOperations(); - if (ops.size() == 1 && ops[year].size() == 1) + if (ops.size() == 1 && ops[year].size() == 1) { - wxMessageBox(_("It must be at least one month !"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("It must be at least one month !"), _("Error"), wxICON_ERROR | wxOK); + return; } - message = _("Are you sure want to delete "); - if (month != -1) - message += months[month] + wxT(" "); - message += wxString::Format(wxT("%d"), year); + message = _("Are you sure want to delete "); + if (month != -1) + message += months[month] + wxT(" "); + message += wxString::Format(wxT("%d"), year); - message += _(" operations ?"); + message += _(" operations ?"); - wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO); - if (dialog.ShowModal() == wxID_NO) - return; + wxMessageDialog dialog(_wxUI, message, wxT("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) + return; - curNode = _tree.GetSelection(); + curNode = _tree.GetSelection(); - if (ops[year].size() == 1 && month != -1) - curNode = _tree.GetItemParent(curNode); + if (ops[year].size() == 1 && month != -1) + curNode = _tree.GetItemParent(curNode); - _kiss->DeleteOperations(month, year); + _kiss->DeleteOperations(month, year); - node = _tree.GetNextSibling(curNode); + node = _tree.GetNextSibling(curNode); - if (!node.IsOk()) - node = _tree.GetPrevSibling(curNode); + if (!node.IsOk()) + node = _tree.GetPrevSibling(curNode); - _tree.Delete(curNode); + _tree.Delete(curNode); - if (!node.IsOk()) - ChangeUser(); - else + if (!node.IsOk()) + ChangeUser(); + else { - _tree.SelectItem(node); - GetTreeSelection(&month, &year); - if (month == -1) - month = ops[year][0]; - ShowMonth(month, year); + _tree.SelectItem(node); + GetTreeSelection(&month, &year); + if (month == -1) + month = ops[year][0]; + ShowMonth(month, year); } } void AccountPanel::GenerateMonth(int month, int year) { - wxTreeItemId root, years, node ; - wxTreeItemIdValue cookie; - wxString monthString, yearString; - std::map > ops ; - std::vector::iterator it ; - int i; + wxTreeItemId root, years, node ; + wxTreeItemIdValue cookie; + wxString monthString, yearString; + std::map > ops ; + std::vector::iterator it ; + int i; - root = _tree.GetRootItem(); - yearString = wxString::Format(wxT("%d"), year); - monthString = months[month]; + root = _tree.GetRootItem(); + yearString = wxString::Format(wxT("%d"), year); + monthString = months[month]; - ops = _kiss->GetAllOperations(); + ops = _kiss->GetAllOperations(); - if (_tree.GetChildrenCount(root, true) < 1) + if (_tree.GetChildrenCount(root, true) < 1) { - node = _tree.AppendItem(root, yearString); - node = _tree.AppendItem(node, monthString); + node = _tree.AppendItem(root, yearString); + node = _tree.AppendItem(node, monthString); - _tree.SelectItem(node, true); - ShowMonth(month, year); - return ; + _tree.SelectItem(node, true); + ShowMonth(month, year); + return ; } - years = _tree.GetFirstChild(root, cookie); - while (years.IsOk()) + years = _tree.GetFirstChild(root, cookie); + while (years.IsOk()) { - if (_tree.GetItemText(years) == yearString) - break; - if (wxAtoi(_tree.GetItemText(years)) > year) + if (_tree.GetItemText(years) == yearString) + break; + if (wxAtoi(_tree.GetItemText(years)) > year) { - years = _tree.GetPrevSibling(years); - if (!years.IsOk()) - years = _tree.PrependItem(root, yearString); - else - years = _tree.InsertItem(root, years, yearString); - break; + years = _tree.GetPrevSibling(years); + if (!years.IsOk()) + years = _tree.PrependItem(root, yearString); + else + years = _tree.InsertItem(root, years, yearString); + break; } - years = _tree.GetNextSibling(years); + years = _tree.GetNextSibling(years); } - if (!years.IsOk()) + if (!years.IsOk()) { - years = _tree.GetFirstChild(root, cookie); - if (wxAtoi(_tree.GetItemText(years)) > year) - years = _tree.PrependItem(root, yearString); - else - years = _tree.AppendItem(root, yearString); + years = _tree.GetFirstChild(root, cookie); + if (wxAtoi(_tree.GetItemText(years)) > year) + years = _tree.PrependItem(root, yearString); + else + years = _tree.AppendItem(root, yearString); } - if (!_tree.GetChildrenCount(years, true)) - node = _tree.AppendItem(years, monthString); - else + if (!_tree.GetChildrenCount(years, true)) + node = _tree.AppendItem(years, monthString); + else { - for(i=0, it = ops[year].begin(); - it != ops[year].end(); - it++, i++) + for(i=0, it = ops[year].begin(); + it != ops[year].end(); + it++, i++) { - if (*it > month) - break; + if (*it > month) + break; } - if (it == ops[year].end()) - years = _tree.AppendItem(years, monthString); - else - years = _tree.InsertItem(years, i-1, monthString); + if (it == ops[year].end()) + years = _tree.AppendItem(years, monthString); + else + years = _tree.InsertItem(years, i-1, monthString); } - _tree.SelectItem(node, true); - ShowMonth(month, year); + _tree.SelectItem(node, true); + ShowMonth(month, year); } void AccountPanel::OnShow(wxShowEvent& event) { - if (_curMonth != -1) - _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + months[_curMonth] + wxT(" ") + wxString::Format(wxT("%d"), _curYear)); - else - _wxUI->SetTitle(_kiss->GetUser()->_name); + if (_curMonth != -1) + _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + months[_curMonth] + wxT(" ") + wxString::Format(wxT("%d"), _curYear)); + else + _wxUI->SetTitle(_kiss->GetUser()->_name); } void AccountPanel::OnCalendarChange(wxCalendarEvent& event) { - UpdateStats(); + UpdateStats(); } void AccountPanel::OnCheckMode(wxCommandEvent& event) { - UpdateStats(); + UpdateStats(); } diff --git a/src/view/AccountPanel.h b/src/view/AccountPanel.h index 5341f1e..3a0cafe 100644 --- a/src/view/AccountPanel.h +++ b/src/view/AccountPanel.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef ACCOUNTPANEL_H @@ -42,50 +42,50 @@ class KissCount; class AccountPanel: public wxScrolledWindow { - public: - AccountPanel(KissCount* kiss, wxUI *parent); - ~AccountPanel(); - void ChangeUser(); - void LoadYear(int year, bool showMonth=true); - void ShowMonth(int month, int year); - void GenerateMonth(int month, int year); +public: + AccountPanel(KissCount* kiss, wxUI *parent); + ~AccountPanel(); + void ChangeUser(); + void LoadYear(int year, bool showMonth=true); + void ShowMonth(int month, int year); + void GenerateMonth(int month, int year); - void OnOperationModified(wxGridEvent& event); - void OnAccountModified(wxGridEvent& event); - void OnTreeRightClick(wxTreeEvent& event); - void OnTreeChange(wxTreeEvent& event); - void OnMenuGenerate(wxCommandEvent& event); - void OnMenuDelete(wxCommandEvent& event); - void OnShow(wxShowEvent& event); - void OnCalendarChange(wxCalendarEvent& event); + void OnOperationModified(wxGridEvent& event); + void OnAccountModified(wxGridEvent& event); + void OnTreeRightClick(wxTreeEvent& event); + void OnTreeChange(wxTreeEvent& event); + void OnMenuGenerate(wxCommandEvent& event); + void OnMenuDelete(wxCommandEvent& event); + void OnShow(wxShowEvent& event); + void OnCalendarChange(wxCalendarEvent& event); - int _curMonth, _curYear; + int _curMonth, _curYear; - private: - KissCount* _kiss; - wxUI* _wxUI; - wxTreeCtrl _tree; - wxCalendarCtrl* _calendar; - GridAccount* _grid; - wxGrid *_statsGrid, *_accountsGrid; - PiePlot* _pie; - double *_categoriesValues; - wxCheckBox *_checkCheckMode; - std::map _categoriesIndexes; - std::vector* _curOperations; - wxString* _categories, *_accounts; - std::map _accountsInitValues; - CategorySimpleDataset* _dataset; - int _fixCosts; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxTreeCtrl _tree; + wxCalendarCtrl* _calendar; + GridAccount* _grid; + wxGrid *_statsGrid, *_accountsGrid; + PiePlot* _pie; + double *_categoriesValues; + wxCheckBox *_checkCheckMode; + std::map _categoriesIndexes; + std::vector* _curOperations; + wxString* _categories, *_accounts; + std::map _accountsInitValues; + CategorySimpleDataset* _dataset; + int _fixCosts; - void InitStatsGrid(User* user); - void InitAccountsGrid(User* user, int month, int year); - void UpdateStats(); - void InsertOperation(User* user, Operation* op, int line, bool fix); - void GetTreeSelection(int* month, int* year); - void OnCheckMode(wxCommandEvent& event); + void InitStatsGrid(User* user); + void InitAccountsGrid(User* user, int month, int year); + void UpdateStats(); + void InsertOperation(User* user, Operation* op, int line, bool fix); + void GetTreeSelection(int* month, int* year); + void OnCheckMode(wxCommandEvent& event); - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/ButtonPanel.cpp b/src/view/ButtonPanel.cpp index 015c734..020e11d 100644 --- a/src/view/ButtonPanel.cpp +++ b/src/view/ButtonPanel.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "ButtonPanel.h" @@ -33,83 +33,83 @@ END_EVENT_TABLE() ButtonPanel::ButtonPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent) { - wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - _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)); + wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + _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); + SetSizer(hbox); - _account->SetToolTip(_("Operations")); - _stats->SetToolTip(_("Statistics")); - _search->SetToolTip(_("Search")); - _prefs->SetToolTip(_("Preferences")); - _changeUser->SetToolTip(_("Change user")); - _about->SetToolTip(_("About")); - _quit->SetToolTip(_("Quit")); + _account->SetToolTip(_("Operations")); + _stats->SetToolTip(_("Statistics")); + _search->SetToolTip(_("Search")); + _prefs->SetToolTip(_("Preferences")); + _changeUser->SetToolTip(_("Change user")); + _about->SetToolTip(_("About")); + _quit->SetToolTip(_("Quit")); - hbox->Add(_account); - hbox->Add(_stats); - hbox->Add(_search); - hbox->Add(_prefs); - hbox->Add(_changeUser); - hbox->Add(_about); - hbox->Add(_quit); + hbox->Add(_account); + hbox->Add(_stats); + hbox->Add(_search); + hbox->Add(_prefs); + hbox->Add(_changeUser); + hbox->Add(_about); + hbox->Add(_quit); - Fit(); - SetMinSize(GetSize()); + Fit(); + SetMinSize(GetSize()); } ButtonPanel::~ButtonPanel() { - delete _account; - delete _stats; - delete _prefs; - delete _changeUser; + delete _account; + delete _stats; + delete _prefs; + delete _changeUser; } void ButtonPanel::OnButtonAccount(wxCommandEvent& event) { - _wxUI->ShowAccount(); + _wxUI->ShowAccount(); } void ButtonPanel::OnButtonStats(wxCommandEvent& event) { - _wxUI->ShowStats(); + _wxUI->ShowStats(); } void ButtonPanel::OnButtonSearch(wxCommandEvent& event) { - _wxUI->ShowSearch(); + _wxUI->ShowSearch(); } void ButtonPanel::OnButtonPreferences(wxCommandEvent& event) { - _wxUI->ShowPreferences(); + _wxUI->ShowPreferences(); } void ButtonPanel::OnButtonChangeUser(wxCommandEvent& event) { - _wxUI->ChangeUser(); + _wxUI->ChangeUser(); } void ButtonPanel::OnButtonAbout(wxCommandEvent& event) { - wxMessageBox( _("Personal accounting software\n\nCopyright (C) 2010 Grégory Soutadé"), + wxMessageBox( _("Personal accounting software\n\nCopyright (C) 2010 Grégory Soutadé"), wxT("KissCount " APP_VERSION "\n\n"), wxOK | wxICON_INFORMATION, _wxUI ); } void ButtonPanel::OnButtonQuit(wxCommandEvent& event) { - wxMessageDialog dialog(_wxUI, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO); - if (dialog.ShowModal() == wxID_NO) + wxMessageDialog dialog(_wxUI, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) { - return; + return; } - _wxUI->Close(true); + _wxUI->Close(true); } diff --git a/src/view/ButtonPanel.h b/src/view/ButtonPanel.h index 4194de9..010c7e4 100644 --- a/src/view/ButtonPanel.h +++ b/src/view/ButtonPanel.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef BUTTONPANEL_H @@ -33,31 +33,31 @@ class wxUI; class ButtonPanel: public wxPanel { - public: +public: - ButtonPanel(KissCount* kiss, wxUI *parent); - ~ButtonPanel(); + ButtonPanel(KissCount* kiss, wxUI *parent); + ~ButtonPanel(); - void OnButtonAccount(wxCommandEvent& event); - void OnButtonStats(wxCommandEvent& event); - void OnButtonSearch(wxCommandEvent& event); - void OnButtonPreferences(wxCommandEvent& event); - void OnButtonChangeUser(wxCommandEvent& event); - void OnButtonAbout(wxCommandEvent& event); - void OnButtonQuit(wxCommandEvent& event); + void OnButtonAccount(wxCommandEvent& event); + void OnButtonStats(wxCommandEvent& event); + void OnButtonSearch(wxCommandEvent& event); + void OnButtonPreferences(wxCommandEvent& event); + void OnButtonChangeUser(wxCommandEvent& event); + void OnButtonAbout(wxCommandEvent& event); + void OnButtonQuit(wxCommandEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxBitmapButton* _account; - wxBitmapButton* _stats; - wxBitmapButton* _search; - wxBitmapButton* _prefs; - wxBitmapButton* _changeUser; - wxBitmapButton* _about; - wxBitmapButton* _quit; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxBitmapButton* _account; + wxBitmapButton* _stats; + wxBitmapButton* _search; + wxBitmapButton* _prefs; + wxBitmapButton* _changeUser; + wxBitmapButton* _about; + wxBitmapButton* _quit; - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/CalendarEditor.cpp b/src/view/CalendarEditor.cpp index d412996..e66818e 100644 --- a/src/view/CalendarEditor.cpp +++ b/src/view/CalendarEditor.cpp @@ -1,111 +1,111 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "CalendarEditor.h" CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _days(NULL), _editor(NULL) { - wxDateTime date; - int i; + wxDateTime date; + int i; - _maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1; + _maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1; - _days = new wxString[_maxDay]; + _days = new wxString[_maxDay]; - for (i=0; i<_maxDay; i++) - _days[i] = wxString::Format(wxT("%d"), i+1) ; + for (i=0; i<_maxDay; i++) + _days[i] = wxString::Format(wxT("%d"), i+1) ; - _editor = new wxChoice(); + _editor = new wxChoice(); } CalendarEditor::~CalendarEditor() { - delete _editor; - delete[] _days; + delete _editor; + delete[] _days; } void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid) { - // wxDateTime date, dateDef; + // wxDateTime date, dateDef; - // if (!grid->GetCellValue(row, col).Len()) return; + // if (!grid->GetCellValue(row, col).Len()) return; - // if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef)) - // _calendar->SetDate(wxDateTime(_day, _month, _year)); + // if (date.ParseFormat(grid->GetCellValue(row, col), wxT("%d/%m/%Y"), dateDef)) + // _calendar->SetDate(wxDateTime(_day, _month, _year)); } wxGridCellEditor* CalendarEditor::Clone() const { - return new CalendarEditor(_day, _month, _year); + return new CalendarEditor(_day, _month, _year); } void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler) { - _parent = parent; - _editor->Create(parent, id, wxDefaultPosition, wxDefaultSize, _maxDay, _days); - _editor->Select(_day); - _editor->Connect((int)id, (int)wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(CalendarEditor::OnDateChanged), NULL, this); + _parent = parent; + _editor->Create(parent, id, wxDefaultPosition, wxDefaultSize, _maxDay, _days); + _editor->Select(_day); + _editor->Connect((int)id, (int)wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(CalendarEditor::OnDateChanged), NULL, this); } bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid) { - grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ; + grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year)) ; - return true; + return true; } void CalendarEditor::ApplyEdit (int row, int col, wxGrid *grid) { - grid->SetCellValue(row, col, wxString::Format(wxT("%02d/%02d/%d"), _day+1, _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+1, _month+1, _year); + return wxString::Format(wxT("%02d/%02d/%d"), _day+1, _month+1, _year); } void CalendarEditor::Reset() { - _editor->Select(_day); + _editor->Select(_day); } void CalendarEditor::Show (bool show, wxGridCellAttr *attr) { - _editor->Show(show); + _editor->Show(show); } void CalendarEditor::SetSize (const wxRect &rect) { - _editor->SetSize(rect); + _editor->SetSize(rect); } void CalendarEditor::StartingClick() { - Show(true, NULL); + Show(true, NULL); } bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event) { - return true; + return true; } void CalendarEditor::OnDateChanged(wxCommandEvent& event) { - _day = _editor->GetSelection(); + _day = _editor->GetSelection(); } diff --git a/src/view/CalendarEditor.h b/src/view/CalendarEditor.h index d547e59..2bd33c0 100644 --- a/src/view/CalendarEditor.h +++ b/src/view/CalendarEditor.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef CALENDAREDITOR_H @@ -29,33 +29,33 @@ along with KissCount. If not, see . class CalendarEditor : public wxGridCellChoiceEditor, public wxEvtHandler { - public: +public: - CalendarEditor(int day, int month, int year); - ~CalendarEditor(); + CalendarEditor(int day, int month, int year); + ~CalendarEditor(); - void BeginEdit(int row, int col, wxGrid *grid); - wxGridCellEditor* Clone () const; - void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); - bool EndEdit(int row, int col, wxGrid *grid); - void ApplyEdit(int row, int col, wxGrid *grid); - wxString GetValue() const; - void Reset(); - void Show(bool show, wxGridCellAttr *attr=NULL); - void SetSize (const wxRect &rect); - /* void OnCalendarChange(wxCommandEvent& event); */ - void OnDateChanged(wxCommandEvent& event); - void StartingClick(); - bool IsAcceptedKey(wxKeyEvent &event); + void BeginEdit(int row, int col, wxGrid *grid); + wxGridCellEditor* Clone () const; + void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler); + bool EndEdit(int row, int col, wxGrid *grid); + void ApplyEdit(int row, int col, wxGrid *grid); + wxString GetValue() const; + void Reset(); + void Show(bool show, wxGridCellAttr *attr=NULL); + void SetSize (const wxRect &rect); + /* void OnCalendarChange(wxCommandEvent& event); */ + void OnDateChanged(wxCommandEvent& event); + void StartingClick(); + bool IsAcceptedKey(wxKeyEvent &event); - private: - int _day; - int _month; - int _year; - wxWindow *_parent; - wxString* _days; - int _maxDay; - wxChoice* _editor; +private: + int _day; + int _month; + int _year; + wxWindow *_parent; + wxString* _days; + int _maxDay; + wxChoice* _editor; }; #endif diff --git a/src/view/GenerateDialog.cpp b/src/view/GenerateDialog.cpp index 70df8ae..cae65ce 100644 --- a/src/view/GenerateDialog.cpp +++ b/src/view/GenerateDialog.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "GenerateDialog.h" @@ -30,202 +30,202 @@ END_EVENT_TABLE() GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), wxID_ANY, _("Generate month")), _kiss(kiss), _wxUI(parent) { - wxGridBagSizer *gridBagSizer; - wxStaticText* label; - std::map >::iterator it; - int i, a, toSelect=-1; - wxDateTime curDate; - wxCommandEvent event; - std::vector::iterator monthIt; + wxGridBagSizer *gridBagSizer; + wxStaticText* label; + std::map >::iterator it; + int i, a, toSelect=-1; + wxDateTime curDate; + wxCommandEvent event; + std::vector::iterator monthIt; - curDate.SetToCurrent(); + curDate.SetToCurrent(); - gridBagSizer = new wxGridBagSizer(4, 5); + gridBagSizer = new wxGridBagSizer(4, 5); - label = new wxStaticText(this, wxID_ANY, _("From ")); - gridBagSizer->Add(label, wxGBPosition(0, 0)); - _yearFrom = new wxChoice(this, YEAR_FROM_ID); - gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1)); - _monthFrom = new wxChoice(this, MONTH_FROM_ID); - gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2)); + label = new wxStaticText(this, wxID_ANY, _("From ")); + gridBagSizer->Add(label, wxGBPosition(0, 0)); + _yearFrom = new wxChoice(this, YEAR_FROM_ID); + gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1)); + _monthFrom = new wxChoice(this, MONTH_FROM_ID); + gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2)); - label = new wxStaticText(this, wxID_ANY, _("To ")); - gridBagSizer->Add(label, wxGBPosition(1, 0)); - _yearTo = new wxChoice(this, YEAR_TO_ID); - gridBagSizer->Add(_yearTo, wxGBPosition(1, 1)); - _monthTo = new wxChoice(this, MONTH_TO_ID); - gridBagSizer->Add(_monthTo, wxGBPosition(1, 2)); + label = new wxStaticText(this, wxID_ANY, _("To ")); + gridBagSizer->Add(label, wxGBPosition(1, 0)); + _yearTo = new wxChoice(this, YEAR_TO_ID); + gridBagSizer->Add(_yearTo, wxGBPosition(1, 1)); + _monthTo = new wxChoice(this, MONTH_TO_ID); + gridBagSizer->Add(_monthTo, wxGBPosition(1, 2)); - wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); - wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); - gridBagSizer->Add(ok, wxGBPosition(3, 3)); - gridBagSizer->Add(cancel, wxGBPosition(3, 4)); + wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); + wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); + gridBagSizer->Add(ok, wxGBPosition(3, 3)); + gridBagSizer->Add(cancel, wxGBPosition(3, 4)); - _ops = _kiss->GetAllOperations(); + _ops = _kiss->GetAllOperations(); - _yearFrom->Append(wxT("")); - _monthFrom->Append(wxT("")); + _yearFrom->Append(wxT("")); + _monthFrom->Append(wxT("")); - for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++) + for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++) { - _yearFrom->Append(wxString::Format(wxT("%d"), it->first)); - if (year == it->first) - toSelect = i; + _yearFrom->Append(wxString::Format(wxT("%d"), it->first)); + if (year == it->first) + toSelect = i; } - if (toSelect != -1) + if (toSelect != -1) { - _yearFrom->Select(toSelect); - OnYearFromChange(event); - toSelect=0; - if (month != -1) + _yearFrom->Select(toSelect); + OnYearFromChange(event); + toSelect=0; + if (month != -1) { - for(i=0; i<(int)_monthFrom->GetCount(); i++) + for(i=0; i<(int)_monthFrom->GetCount(); i++) { - if (_monthFrom->GetString(i) == months[month]) + if (_monthFrom->GetString(i) == months[month]) { - toSelect = i; - break; + toSelect = i; + break; } } } - _monthFrom->Select(toSelect); + _monthFrom->Select(toSelect); } - else + else { - _yearFrom->Select(0); - OnYearFromChange(event); + _yearFrom->Select(0); + OnYearFromChange(event); } - for(i=2000; i<=2050; i++) - _yearTo->Append(wxString::Format(wxT("%d"), i)); + for(i=2000; i<=2050; i++) + _yearTo->Append(wxString::Format(wxT("%d"), i)); - if (year == -1) + if (year == -1) { - _yearTo->Select(curDate.GetYear()-2000); - OnYearToChange(event); - _monthTo->Select(curDate.GetMonth()-1); + _yearTo->Select(curDate.GetYear()-2000); + OnYearToChange(event); + _monthTo->Select(curDate.GetMonth()-1); } - else + else { - _yearTo->Select(year-2000); - OnYearToChange(event); - if (_ops[year].size()) - month = _ops[year][0]; + _yearTo->Select(year-2000); + OnYearToChange(event); + if (_ops[year].size()) + month = _ops[year][0]; - if (month == -1) - _monthTo->Select(0); - else + if (month == -1) + _monthTo->Select(0); + else { - for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++) + for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++) { - if (i != *monthIt) + if (i != *monthIt) { - a++; - continue; + a++; + continue; } - if (*monthIt > month) - break; - monthIt++; + if (*monthIt > month) + break; + monthIt++; } - _monthTo->Select(a); + _monthTo->Select(a); } } - SetSizer(gridBagSizer); + SetSizer(gridBagSizer); - Layout(); - Center(); + Layout(); + Center(); } void GenerateDialog::OnYearFromChange(wxCommandEvent& event) { - wxString years = _yearFrom->GetString(_yearFrom->GetCurrentSelection()); - int year; - std::vector::iterator it; + wxString years = _yearFrom->GetString(_yearFrom->GetCurrentSelection()); + int year; + std::vector::iterator it; - _monthFrom->Clear(); + _monthFrom->Clear(); - if (!years.Length()) + if (!years.Length()) { - _monthFrom->Append(wxT("")); - return; + _monthFrom->Append(wxT("")); + return; } - year = wxAtoi(years); + year = wxAtoi(years); - for(it=_ops[year].begin(); it!=_ops[year].end(); it++) - _monthFrom->Append(months[*it]); - _monthFrom->Select(0); + for(it=_ops[year].begin(); it!=_ops[year].end(); it++) + _monthFrom->Append(months[*it]); + _monthFrom->Select(0); - Layout(); + Layout(); } void GenerateDialog::OnYearToChange(wxCommandEvent& event) { - int year, i, ok; - std::vector::iterator it; + int year, i, ok; + std::vector::iterator it; - _monthTo->Clear(); + _monthTo->Clear(); - year = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection())); + year = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection())); - for (i=0; i<12; i++) + for (i=0; i<12; i++) { - ok = 1; - for(it=_ops[year].begin(); it!=_ops[year].end(); it++) + ok = 1; + for(it=_ops[year].begin(); it!=_ops[year].end(); it++) { - if (*it == i) + if (*it == i) { - ok=0; break; + ok=0; break; } } - if (ok) - _monthTo->Append(months[i]); + if (ok) + _monthTo->Append(months[i]); } - _monthTo->Select(0); + _monthTo->Select(0); - Layout(); + Layout(); } void GenerateDialog::OnOK(wxCommandEvent& event) { - int monthFrom, yearFrom, monthTo, yearTo, i; + int monthFrom, yearFrom, monthTo, yearTo, i; - if (!_yearFrom->GetString(_yearFrom->GetCurrentSelection()).Length()) + if (!_yearFrom->GetString(_yearFrom->GetCurrentSelection()).Length()) { - monthFrom = -1; - yearFrom = -1; + monthFrom = -1; + yearFrom = -1; } - else + else { - for (i=0; i<12; i++) + for (i=0; i<12; i++) { - if (months[i] == _monthFrom->GetString(_monthFrom->GetCurrentSelection())) + if (months[i] == _monthFrom->GetString(_monthFrom->GetCurrentSelection())) { - monthFrom = i; - break; + monthFrom = i; + break; } } - yearFrom = wxAtoi(_yearFrom->GetString(_yearFrom->GetCurrentSelection())); + yearFrom = wxAtoi(_yearFrom->GetString(_yearFrom->GetCurrentSelection())); } - for (i=0; i<12; i++) + for (i=0; i<12; i++) { - if (months[i] == _monthTo->GetString(_monthTo->GetCurrentSelection())) + if (months[i] == _monthTo->GetString(_monthTo->GetCurrentSelection())) { - monthTo = i; - break; + monthTo = i; + break; } } - yearTo = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection())); + yearTo = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection())); - Close(); - _kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo); + Close(); + _kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo); } void GenerateDialog::OnCancel(wxCommandEvent& event) { - Close(); + Close(); } diff --git a/src/view/GenerateDialog.h b/src/view/GenerateDialog.h index 75f14b2..8187ddc 100644 --- a/src/view/GenerateDialog.h +++ b/src/view/GenerateDialog.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef GENERATEDIALOG_H @@ -34,21 +34,21 @@ class KissCount; class GenerateDialog : public wxDialog { - public: - GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year); +public: + GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year); - void OnYearFromChange(wxCommandEvent& event); - void OnYearToChange(wxCommandEvent& event); - void OnOK(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); + void OnYearFromChange(wxCommandEvent& event); + void OnYearToChange(wxCommandEvent& event); + void OnOK(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxChoice* _yearFrom, *_monthFrom, *_yearTo, *_monthTo; - std::map > _ops; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxChoice* _yearFrom, *_monthFrom, *_yearTo, *_monthTo; + std::map > _ops; - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/GridAccount.cpp b/src/view/GridAccount.cpp index 078c901..d9ffdff 100644 --- a/src/view/GridAccount.cpp +++ b/src/view/GridAccount.cpp @@ -1,189 +1,189 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "GridAccount.h" #define SET_ROW_COLOR(row, color) for(int i=0; iGetUser(); - std::vector::iterator accountIt; - std::vector::iterator categoryIt; + wxBitmap deleteBitmap(wxT(DELETE_ICON)); + wxBitmap checkedBitmap(wxT(CHECKED_ICON)); + DEFAULT_FONT(font); + int i; + User* user = _kiss->GetUser(); + std::vector::iterator accountIt; + std::vector::iterator categoryIt; - CreateGrid(1, NUMBER_COLS_OPS); - SetColLabelSize(0); - SetRowLabelSize(0); + CreateGrid(1, NUMBER_COLS_OPS); + SetColLabelSize(0); + SetRowLabelSize(0); - SetColSize (0, GetColSize(0)*3); - SetDefaultCellFont(font); + SetColSize (0, GetColSize(0)*3); + SetDefaultCellFont(font); - font.SetWeight(wxFONTWEIGHT_BOLD); - wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")}; - for(i=0; iGetAccountsNumber()]; - 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 = new wxString[user->GetCategoriesNumber()] ; + for(i=0, categoryIt = user->_categories.begin(); + categoryIt != user->_categories.end(); + categoryIt++, i++) { - _categories[i] = categoryIt->name ; + _categories[i] = categoryIt->name ; } } GridAccount::~GridAccount() { - delete[] _categories; - delete[] _accounts; + delete[] _categories; + delete[] _accounts; } wxPen GridAccount::GetColGridLinePen (int col) {return wxPen(*wxBLACK, 1, wxSOLID);} wxPen GridAccount::GetRowGridLinePen (int row) { - if (row == 0 || row == _fixCosts || - row == _week1 || - row == _week2 || - row == _week3 || - row == _week4) - return wxPen(*wxBLACK, 1, wxSOLID); + if (row == 0 || row == _fixCosts || + row == _week1 || + row == _week2 || + row == _week3 || + row == _week4) + return wxPen(*wxBLACK, 1, wxSOLID); - return GetCellBackgroundColour(row, 0); + return GetCellBackgroundColour(row, 0); } void GridAccount::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; + } } void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear) { - std::vector::iterator it; - int r, g, b; - wxColour color; - wxDateTime curDate; + std::vector::iterator it; + int r, g, b; + wxColour color; + wxDateTime curDate; - curDate.SetToCurrent(); + curDate.SetToCurrent(); - if (!op && !user->_accounts.size()) return; + if (!op && !user->_accounts.size()) return; - InsertRows(line, 1); + InsertRows(line, 1); - SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2)); - SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2)); - wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false); - SetCellEditor(line, ACCOUNT, accountEditor); - wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false); - SetCellEditor(line, CATEGORY, categoryEditor); + SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2)); + SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2)); + wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false); + SetCellEditor(line, ACCOUNT, accountEditor); + wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false); + SetCellEditor(line, CATEGORY, categoryEditor); - if (fix) + if (fix) { - SetCellValue(line, CATEGORY, _("Fix")); - SetReadOnly(line, CATEGORY); + SetCellValue(line, CATEGORY, _("Fix")); + SetReadOnly(line, CATEGORY); } - if (op) + if (op) { - SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year)); - SetCellValue(line, DESCRIPTION, op->description); - SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year)); - if (op->amount < 0) - SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount)); - else - SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount)); - SetCellValue(line, ACCOUNT, user->GetAccountName(op->account)); - if (!fix) - SetCellValue(line, CATEGORY, user->GetCategoryName(op->category)); - SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ()); - SetCellEditor(line, DELETE, new wxGridCellBoolEditor ()); - SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); - SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ()); + SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year)); + SetCellValue(line, DESCRIPTION, op->description); + SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year)); + if (op->amount < 0) + SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount)); + else + SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount)); + SetCellValue(line, ACCOUNT, user->GetAccountName(op->account)); + if (!fix) + SetCellValue(line, CATEGORY, user->GetCategoryName(op->category)); + SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ()); + SetCellEditor(line, DELETE, new wxGridCellBoolEditor ()); + SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ()); + SetCellEditor(line, CHECKED, new wxGridCellBoolEditor ()); - color = user->GetCategory(op->category).color; + color = user->GetCategory(op->category).color; - if (op->checked) + 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()); - SetCellValue(line, CHECKED, wxT("1")); + 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()); + SetCellValue(line, CHECKED, wxT("1")); } - SET_ROW_COLOR(line, color); + SET_ROW_COLOR(line, color); } - else + else { - SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear)); - if (!fix && - curDate.GetMonth() == curMonth && - curDate.GetYear() == curYear) + SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear)); + if (!fix && + curDate.GetMonth() == curMonth && + curDate.GetYear() == curYear) { - SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear)); - SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear)); + SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear)); + SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear)); } - else - SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear)); + else + SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear)); - if (fix) - SET_ROW_COLOR(line, OWN_YELLOW) - else - SET_ROW_COLOR(line, OWN_GREEN); + if (fix) + SET_ROW_COLOR(line, OWN_YELLOW) + else + SET_ROW_COLOR(line, OWN_GREEN); - SetReadOnly(line, CHECKED, true); - SetReadOnly(line, DELETE, true); + SetReadOnly(line, CHECKED, true); + SetReadOnly(line, DELETE, true); } - SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE); - SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE); - SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE); + SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE); + SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE); + SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE); - Layout(); - SetMinSize(GetMinSize()); + Layout(); + SetMinSize(GetMinSize()); } diff --git a/src/view/GridAccount.h b/src/view/GridAccount.h index 61671b3..dee4dff 100644 --- a/src/view/GridAccount.h +++ b/src/view/GridAccount.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef GRIDACCOUNT_H @@ -33,20 +33,20 @@ enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMB class GridAccount : public wxGrid { - public: - GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id); - ~GridAccount(); +public: + GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id); + ~GridAccount(); - wxPen GetColGridLinePen (int col); - wxPen GetRowGridLinePen (int row); - void SetWeek(int week, int line); - void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear); + wxPen GetColGridLinePen (int col); + wxPen GetRowGridLinePen (int row); + void SetWeek(int week, int line); + void InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear); - int _fixCosts; - int _week1, _week2, _week3, _week4; - private: - KissCount* _kiss; - wxString* _categories, *_accounts; + int _fixCosts; + int _week1, _week2, _week3, _week4; +private: + KissCount* _kiss; + wxString* _categories, *_accounts; }; #endif diff --git a/src/view/PasswordDialog.cpp b/src/view/PasswordDialog.cpp index 88b570a..5d4a21b 100644 --- a/src/view/PasswordDialog.cpp +++ b/src/view/PasswordDialog.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "PasswordDialog.h" @@ -28,64 +28,64 @@ END_EVENT_TABLE() PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), wxID_ANY, _("Change password")), _kiss(kiss), _wxUI(parent) { - wxGridBagSizer *gridBagSizer; - wxStaticText* label; + wxGridBagSizer *gridBagSizer; + wxStaticText* label; - gridBagSizer = new wxGridBagSizer(5, 3); + gridBagSizer = new wxGridBagSizer(5, 3); - label = new wxStaticText(this, wxID_ANY, _("Old password ")); - gridBagSizer->Add(label, wxGBPosition(0, 0)); - _oldPassword = new wxTextCtrl(this, OLD_PASSWORD_ID); - gridBagSizer->Add(_oldPassword, wxGBPosition(0, 1)); + label = new wxStaticText(this, wxID_ANY, _("Old password ")); + gridBagSizer->Add(label, wxGBPosition(0, 0)); + _oldPassword = new wxTextCtrl(this, OLD_PASSWORD_ID); + gridBagSizer->Add(_oldPassword, wxGBPosition(0, 1)); - label = new wxStaticText(this, wxID_ANY, _("New password ")); - gridBagSizer->Add(label, wxGBPosition(1, 0)); - _newPassword = new wxTextCtrl(this, NEW_PASSWORD_ID); - gridBagSizer->Add(_newPassword, wxGBPosition(1, 1)); + label = new wxStaticText(this, wxID_ANY, _("New password ")); + gridBagSizer->Add(label, wxGBPosition(1, 0)); + _newPassword = new wxTextCtrl(this, NEW_PASSWORD_ID); + gridBagSizer->Add(_newPassword, wxGBPosition(1, 1)); - label = new wxStaticText(this, wxID_ANY, _("Confirm password ")); - gridBagSizer->Add(label, wxGBPosition(2, 0)); - _confirmPassword = new wxTextCtrl(this, CONFIRM_PASSWORD_ID); - gridBagSizer->Add(_confirmPassword, wxGBPosition(2, 1)); + label = new wxStaticText(this, wxID_ANY, _("Confirm password ")); + gridBagSizer->Add(label, wxGBPosition(2, 0)); + _confirmPassword = new wxTextCtrl(this, CONFIRM_PASSWORD_ID); + gridBagSizer->Add(_confirmPassword, wxGBPosition(2, 1)); - _oldPassword->SetWindowStyle(wxTE_PASSWORD); - _newPassword->SetWindowStyle(wxTE_PASSWORD); - _confirmPassword->SetWindowStyle(wxTE_PASSWORD); + _oldPassword->SetWindowStyle(wxTE_PASSWORD); + _newPassword->SetWindowStyle(wxTE_PASSWORD); + _confirmPassword->SetWindowStyle(wxTE_PASSWORD); - wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); - wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); - gridBagSizer->Add(ok, wxGBPosition(4, 1)); - gridBagSizer->Add(cancel, wxGBPosition(4, 2)); + wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK")); + wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel")); + gridBagSizer->Add(ok, wxGBPosition(4, 1)); + gridBagSizer->Add(cancel, wxGBPosition(4, 2)); - SetSizer(gridBagSizer); + SetSizer(gridBagSizer); - Layout(); - Center(); + Layout(); + Center(); } void PasswordDialog::OnOK(wxCommandEvent& event) { - User* user = _kiss->GetUser(); + User* user = _kiss->GetUser(); - if (!_kiss->IsValidUser(user->_name, _oldPassword->GetLineText(0))) + if (!_kiss->IsValidUser(user->_name, _oldPassword->GetLineText(0))) { - wxMessageBox(_("Invalid old password"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("Invalid old password"), _("Error"), wxICON_ERROR | wxOK); + return; } - if (_newPassword->GetLineText(0) != _confirmPassword->GetLineText(0)) + if (_newPassword->GetLineText(0) != _confirmPassword->GetLineText(0)) { - wxMessageBox(_("Please retype new password"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("Please retype new password"), _("Error"), wxICON_ERROR | wxOK); + return; } - _kiss->ChangePassword(_newPassword->GetLineText(0)); + _kiss->ChangePassword(_newPassword->GetLineText(0)); - wxMessageBox(_("Password changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK); - Close(); + wxMessageBox(_("Password changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + Close(); } void PasswordDialog::OnCancel(wxCommandEvent& event) { - Close(); + Close(); } diff --git a/src/view/PasswordDialog.h b/src/view/PasswordDialog.h index c2eaa71..e52d468 100644 --- a/src/view/PasswordDialog.h +++ b/src/view/PasswordDialog.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef PASSWORDDIALOG_H @@ -34,17 +34,17 @@ class KissCount; class PasswordDialog : public wxDialog { - public: - PasswordDialog(KissCount* kiss, wxUI *parent); +public: + PasswordDialog(KissCount* kiss, wxUI *parent); - void OnOK(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); + void OnOK(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxTextCtrl* _oldPassword, *_newPassword, *_confirmPassword; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxTextCtrl* _oldPassword, *_newPassword, *_confirmPassword; - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index dec1e86..f71722a 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "PreferencesPanel.h" @@ -38,551 +38,551 @@ END_EVENT_TABLE() PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent) { - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); - //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder; - User* user = _kiss->GetUser(); - wxGridBagSizer *gridBagSizer; - wxStaticText* label; - wxButton* buttonChangeName, *buttonChangePassword, *killMe; - wxStaticBoxSizer * staticBoxSizer; + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL); + //wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + wxStaticBox* staticUser, *staticAccount, *staticCategories, *staticLanguage, *staticOperationOrder; + User* user = _kiss->GetUser(); + wxGridBagSizer *gridBagSizer; + wxStaticText* label; + wxButton* buttonChangeName, *buttonChangePassword, *killMe; + wxStaticBoxSizer * staticBoxSizer; - SetSizer(vbox); + SetSizer(vbox); - staticUser = new wxStaticBox(this, wxID_ANY, _("User")); - staticAccount = new wxStaticBox(this, wxID_ANY, _("Accounts")); - staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories")); - staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language")); - staticOperationOrder = new wxStaticBox(this, wxID_ANY, _("Operation order")); + staticUser = new wxStaticBox(this, wxID_ANY, _("User")); + staticAccount = new wxStaticBox(this, wxID_ANY, _("Accounts")); + staticCategories = new wxStaticBox(this, wxID_ANY, _("Categories")); + staticLanguage = new wxStaticBox(this, wxID_ANY, _("Language")); + staticOperationOrder = new wxStaticBox(this, wxID_ANY, _("Operation order")); - // 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, wxID_ANY, _("Name")); - gridBagSizer->Add(label, wxGBPosition(0, 0)); + label = new wxStaticText(this, wxID_ANY, _("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); - hbox1->Add(staticBoxSizer); - hbox1->Add(-1, 20); + hbox1->Add(staticBoxSizer); + hbox1->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); - hbox1->Add(staticBoxSizer); - hbox1->Add(-1, 20); + hbox1->Add(staticBoxSizer); + hbox1->Add(-1, 20); - vbox->Add(hbox1); - vbox->Add(-1, 20); + vbox->Add(hbox1); + vbox->Add(-1, 20); - // Operation Order - staticBoxSizer = new wxStaticBoxSizer (staticOperationOrder, wxVERTICAL); + // Operation Order + staticBoxSizer = new wxStaticBoxSizer (staticOperationOrder, wxVERTICAL); - _operationOrder = new wxComboBox(this, OPERATION_ORDER_ID); - _operationOrder->SetWindowStyle(wxCB_READONLY); + _operationOrder = new wxComboBox(this, OPERATION_ORDER_ID); + _operationOrder->SetWindowStyle(wxCB_READONLY); - staticBoxSizer->Add(_operationOrder); + staticBoxSizer->Add(_operationOrder); - hbox2->Add(staticBoxSizer); - hbox2->Add(-1, 20); + hbox2->Add(staticBoxSizer); + hbox2->Add(-1, 20); - InitOperationOrder(user); + InitOperationOrder(user); - // Language - staticBoxSizer = new wxStaticBoxSizer (staticLanguage, wxVERTICAL); + // Language + staticBoxSizer = new wxStaticBoxSizer (staticLanguage, wxVERTICAL); - _language = new wxBitmapComboBox(this, LANGUAGE_ID); - _language->SetWindowStyle(wxCB_READONLY); + _language = new wxBitmapComboBox(this, LANGUAGE_ID); + _language->SetWindowStyle(wxCB_READONLY); - staticBoxSizer->Add(_language); + staticBoxSizer->Add(_language); - hbox2->Add(staticBoxSizer); - hbox2->Add(-1, 20); + hbox2->Add(staticBoxSizer); + hbox2->Add(-1, 20); - InitLanguage(user); + InitLanguage(user); - _language->Fit(); + _language->Fit(); - vbox->Add(hbox2); + vbox->Add(hbox2); - 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++) + for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++) { - _accountsGrid->AppendRows(); + _accountsGrid->AppendRows(); - _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); - _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); + _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); + _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?wxT("1"):wxT("0")); - _accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0")); + _accountsGrid->SetCellRenderer(curLine, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellValue(curLine, ACCOUNT_SHARED, (it->shared)?wxT("1"):wxT("0")); + _accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0")); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); } - _accountsGrid->AutoSizeColumns(true); - _accountsGrid->AppendRows(); + _accountsGrid->AutoSizeColumns(true); + _accountsGrid->AppendRows(); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_SHARED, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_DELETE, true); + _accountsGrid->SetReadOnly(curLine, ACCOUNT_SHARED, true); + _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); + _accountsGrid->SetReadOnly(curLine, ACCOUNT_DELETE, true); } #define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color); \ + _categoriesGrid->SetCellBackgroundColour(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::InitLanguage(User* user) { - int i, select=0; + int i, select=0; - for (i=0; iAppend(languages[i].name, wxBitmap(languages[i].icon)); - if (languages[i].language == _wxUI->_language) - select = i; + _language->Append(languages[i].name, wxBitmap(languages[i].icon)); + if (languages[i].language == _wxUI->_language) + select = i; } - _language->Select(select); + _language->Select(select); } void PreferencesPanel::InitOperationOrder(User* user) { - _operationOrder->Append(_("Ascending")); - _operationOrder->Append(_("Descending")); + _operationOrder->Append(_("Ascending")); + _operationOrder->Append(_("Descending")); - if (user->_preferences[wxT("operation_order")] == wxT("ASC")) - _operationOrder->Select(0); - else - _operationOrder->Select(1); + if (user->_preferences[wxT("operation_order")] == wxT("ASC")) + _operationOrder->Select(0); + else + _operationOrder->Select(1); } void PreferencesPanel::OnAccountModified(wxGridEvent& event) { - int op_complete = 2; - wxString value ; - Account new_account, account; - User* user = _kiss->GetUser(); - int row = event.GetRow(); - int col = event.GetCol(); - static bool inModification = false ; - int i; + int op_complete = 2; + wxString value ; + Account new_account, account; + User* user = _kiss->GetUser(); + int row = event.GetRow(); + int col = event.GetCol(); + static bool inModification = false ; + int i; - if (inModification) return; + if (inModification) return; - inModification = true; + inModification = true; - value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME); - if (value.Length()) + value = _accountsGrid->GetCellValue(row, ACCOUNT_NAME); + if (value.Length()) { - new_account.name = value; - op_complete--; + new_account.name = value; + op_complete--; } - value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER); - if (value.Length()) + value = _accountsGrid->GetCellValue(row, ACCOUNT_NUMBER); + if (value.Length()) { - new_account.number = value; - op_complete--; + new_account.number = value; + op_complete--; } - value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED); - if (value.Length() && value != wxT("0")) - new_account.shared = true; - else - new_account.shared = false; + value = _accountsGrid->GetCellValue(row, ACCOUNT_SHARED); + if (value.Length() && value != wxT("0")) + new_account.shared = true; + else + new_account.shared = false; - value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT); - if (value.Length() && value != wxT("0")) - new_account._default = true; - else - new_account._default = false; + value = _accountsGrid->GetCellValue(row, ACCOUNT_DEFAULT); + if (value.Length() && value != wxT("0")) + new_account._default = true; + else + new_account._default = false; - if (col == ACCOUNT_DEFAULT) + if (col == ACCOUNT_DEFAULT) { - new_account.id = user->_accounts[row].id; + new_account.id = user->_accounts[row].id; - for (i=0; iGetAccountsNumber(); i++) + for (i=0; iGetAccountsNumber(); i++) { - if (i != row) + if (i != row) { - account = user->_accounts[i]; - if (account._default) + account = user->_accounts[i]; + if (account._default) { - account._default = false; - _kiss->UpdateAccount(account); - _accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT("")); - break; + account._default = false; + _kiss->UpdateAccount(account); + _accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT("")); + break; } } - _kiss->UpdateAccount(new_account); + _kiss->UpdateAccount(new_account); } } - // Account modification - if (user->GetAccountsNumber() && row < user->GetAccountsNumber()) + // Account modification + if (user->GetAccountsNumber() && row < user->GetAccountsNumber()) { - new_account.id = user->_accounts[row].id; + new_account.id = user->_accounts[row].id; - if (col == ACCOUNT_DELETE) + if (col == ACCOUNT_DELETE) { - if (user->_accounts.size() == 1) + if (user->_accounts.size() == 1) { - wxMessageBox(_("It must be at least one account !"), _("Error"), wxICON_ERROR | wxOK); - _accountsGrid->SetCellValue(row, col, wxT("0")); - return; + wxMessageBox(_("It must be at least one account !"), _("Error"), wxICON_ERROR | wxOK); + _accountsGrid->SetCellValue(row, col, wxT("0")); + return; } - wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+new_account.name, wxT("KissCount"), wxYES_NO); - if (dialog.ShowModal() == wxID_NO) + wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+new_account.name, wxT("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) { - _accountsGrid->SetCellValue(row, col, wxT("0")); + _accountsGrid->SetCellValue(row, col, wxT("0")); } - else + else { - _accountsGrid->DeleteRows(row, 1); - _kiss->DeleteAccount(new_account); + _accountsGrid->DeleteRows(row, 1); + _kiss->DeleteAccount(new_account); } - _wxUI->Layout(); - inModification = false; - _wxUI->NeedReload(); - return; + _wxUI->Layout(); + inModification = false; + _wxUI->NeedReload(); + return; } - if (user->GetAccountId(new_account.name) != new_account.id) + if (user->GetAccountId(new_account.name) != new_account.id) { - wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); - _accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name); - inModification = false; - return ; + wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + _accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name); + inModification = false; + return ; } - _kiss->UpdateAccount(new_account); + _kiss->UpdateAccount(new_account); } - // New account - else + // New account + else { - if (op_complete) + if (op_complete) { - inModification = false; - return ; + inModification = false; + return ; } - if (user->GetAccountId(new_account.name) != wxT("0")) + if (user->GetAccountId(new_account.name) != wxT("0")) { - wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); - inModification = false; - return ; + wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + inModification = false; + return ; } - _accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellAlignment(row, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellRenderer(row, ACCOUNT_SHARED, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_SHARED, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellAlignment(row, ACCOUNT_SHARED, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetReadOnly(row, ACCOUNT_SHARED, false); - _accountsGrid->SetReadOnly(row, ACCOUNT_DEFAULT, false); - _accountsGrid->SetReadOnly(row, ACCOUNT_DELETE, false); + _accountsGrid->SetReadOnly(row, ACCOUNT_SHARED, false); + _accountsGrid->SetReadOnly(row, ACCOUNT_DEFAULT, false); + _accountsGrid->SetReadOnly(row, ACCOUNT_DELETE, false); - if (!user->GetAccountsNumber()) + if (!user->GetAccountsNumber()) { - new_account._default = true; - _accountsGrid->SetCellValue(row, ACCOUNT_DEFAULT, wxT("1")); + new_account._default = true; + _accountsGrid->SetCellValue(row, ACCOUNT_DEFAULT, wxT("1")); } - _accountsGrid->AutoSizeColumns(true); - _accountsGrid->AppendRows(); + _accountsGrid->AutoSizeColumns(true); + _accountsGrid->AppendRows(); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_SHARED, true); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_DEFAULT, true); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_DELETE, true); + _accountsGrid->SetReadOnly(row+1, ACCOUNT_SHARED, true); + _accountsGrid->SetReadOnly(row+1, ACCOUNT_DEFAULT, true); + _accountsGrid->SetReadOnly(row+1, ACCOUNT_DELETE, true); - _kiss->AddAccount(new_account); + _kiss->AddAccount(new_account); } - _wxUI->Layout(); - _wxUI->NeedReload(); - inModification = false; + _wxUI->Layout(); + _wxUI->NeedReload(); + inModification = false; } void PreferencesPanel::OnCategoryModified(wxGridEvent& event) { - int op_complete = 1; - wxString value; - User* user = _kiss->GetUser(); - int row = event.GetRow(); - int col = event.GetCol(); - static bool inModification = false ; - Category new_cat; + int op_complete = 1; + wxString value; + User* user = _kiss->GetUser(); + int row = event.GetRow(); + int col = event.GetCol(); + static bool inModification = false ; + Category new_cat; - if (inModification) return; + if (inModification) return; - inModification = true; + inModification = true; - value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME); - if (value.Length()) + value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME); + if (value.Length()) { - new_cat.name = value; - op_complete--; + new_cat.name = value; + op_complete--; } - new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col); - new_cat.font = wxT(""); - new_cat.parent = wxT("0"); + new_cat.color = _categoriesGrid->GetCellBackgroundColour(row, col); + new_cat.font = wxT(""); + new_cat.parent = wxT("0"); - // Categories modification - if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber()) + // Categories modification + if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber()) { - new_cat.id = user->_categories[row].id; - if (col == CATEGORY_DELETE) + new_cat.id = user->_categories[row].id; + if (col == CATEGORY_DELETE) { - wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_cat.name, wxT("KissCount"), wxYES_NO); - if (dialog.ShowModal() == wxID_NO) + wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+new_cat.name, wxT("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) { - _categoriesGrid->SetCellValue(row, col, wxT("0")); + _categoriesGrid->SetCellValue(row, col, wxT("0")); } - else + else { - _categoriesGrid->DeleteRows(row, 1); - _kiss->DeleteCategory(user->_categories[row]); + _categoriesGrid->DeleteRows(row, 1); + _kiss->DeleteCategory(user->_categories[row]); } - _wxUI->Layout(); - _wxUI->NeedReload(); - inModification = false; - return; + _wxUI->Layout(); + _wxUI->NeedReload(); + inModification = false; + return; } - if (user->GetCategoryId(new_cat.name) != new_cat.id) + if (user->GetCategoryId(new_cat.name) != new_cat.id) { - wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); - _categoriesGrid->SetCellValue(row, CATEGORY_NAME, user->_categories[row].name); - inModification = false; - return ; + wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + _categoriesGrid->SetCellValue(row, CATEGORY_NAME, user->_categories[row].name); + inModification = false; + return ; } - _kiss->UpdateCategory(new_cat); + _kiss->UpdateCategory(new_cat); } - // New category - else + // New category + else { - if (op_complete) + if (op_complete) { - inModification = false; - return ; + inModification = false; + return ; } - if (user->GetCategoryId(new_cat.name) != wxT("0")) + if (user->GetCategoryId(new_cat.name) != wxT("0")) { - wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); - inModification = false; - return ; + wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + inModification = false; + return ; } - _kiss->AddCategory(new_cat); - _categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, false); - _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); - _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); - _categoriesGrid->SetCellRenderer(row, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + _kiss->AddCategory(new_cat); + _categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, false); + _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); + _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); + _categoriesGrid->SetCellRenderer(row, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); + _categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellBoolEditor ()); - _categoriesGrid->SetCellAlignment(row, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); - _categoriesGrid->SetCellAlignment(row, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _categoriesGrid->SetCellAlignment(row, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(row, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(row, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE); + _categoriesGrid->SetCellAlignment(row, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - row++; - _categoriesGrid->AppendRows(); - _categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, true); - _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, true); - _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, true); - SET_ROW_COLOR(row, OWN_GREEN); + row++; + _categoriesGrid->AppendRows(); + _categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, true); + _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, true); + _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, true); + SET_ROW_COLOR(row, OWN_GREEN); } - _wxUI->Layout(); - _wxUI->NeedReload(); - return; + _wxUI->Layout(); + _wxUI->NeedReload(); + return; } void PreferencesPanel::OnChangeName(wxCommandEvent& event) { - User* user = _kiss->GetUser(); - wxString name = _name->GetLineText(0); + User* user = _kiss->GetUser(); + wxString name = _name->GetLineText(0); - if (name == user->_name) - return; + if (name == user->_name) + return; - if (!name.size()) + if (!name.size()) { - wxMessageBox(_("Invalid name"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("Invalid name"), _("Error"), wxICON_ERROR | wxOK); + return; } - if (_kiss->UserExists(name)) + if (_kiss->UserExists(name)) { - wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK); + return; } - _kiss->ChangeName(name); + _kiss->ChangeName(name); - wxMessageBox(_("Name changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK); - _wxUI->NeedReload(); - _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") +_("Preferences")); + wxMessageBox(_("Name changed"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + _wxUI->NeedReload(); + _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") +_("Preferences")); } void PreferencesPanel::OnChangePassword(wxCommandEvent& event) { - PasswordDialog p(_kiss, _wxUI); - p.ShowModal(); + PasswordDialog p(_kiss, _wxUI); + p.ShowModal(); } void PreferencesPanel::OnOperationOrderChange(wxCommandEvent& event) { - if (_operationOrder->GetCurrentSelection() == 0) - _kiss->SetOperationOrder(wxT("ASC")); - else - _kiss->SetOperationOrder(wxT("DESC")); + if (_operationOrder->GetCurrentSelection() == 0) + _kiss->SetOperationOrder(wxT("ASC")); + else + _kiss->SetOperationOrder(wxT("DESC")); - _wxUI->NeedReload(); + _wxUI->NeedReload(); } void PreferencesPanel::OnLanguageChange(wxCommandEvent& event) { - wxLanguage language = languages[_language->GetSelection()].language; - if (_wxUI->SetLanguage(language) || language == wxLANGUAGE_ENGLISH) + wxLanguage language = languages[_language->GetSelection()].language; + if (_wxUI->SetLanguage(language) || language == wxLANGUAGE_ENGLISH) { - _wxUI->NeedReload(); - _kiss->SetLanguage(language); - wxMessageBox(_("Language successfully changed, please go to another panel"), _("KissCount"), wxICON_INFORMATION | wxOK); + _wxUI->NeedReload(); + _kiss->SetLanguage(language); + wxMessageBox(_("Language successfully changed, please go to another panel"), _("KissCount"), wxICON_INFORMATION | wxOK); } - else - wxMessageBox(_("Language not changed"), _("KissCount"), wxICON_ERROR | wxOK); + else + wxMessageBox(_("Language not changed"), _("KissCount"), wxICON_ERROR | wxOK); } void PreferencesPanel::OnShow(wxShowEvent& event) { - _wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Preferences")); + _wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Preferences")); } void PreferencesPanel::OnKillMe(wxCommandEvent& event) { - User* user = _kiss->GetUser(); + User* user = _kiss->GetUser(); - wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+user->_name+_(" profil ?"), wxT("KissCount"), wxYES_NO); - if (dialog.ShowModal() == wxID_NO) + wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+user->_name+_(" profil ?"), wxT("KissCount"), wxYES_NO); + if (dialog.ShowModal() == wxID_NO) { - return; + return; } - _kiss->KillMe(); + _kiss->KillMe(); } diff --git a/src/view/PreferencesPanel.h b/src/view/PreferencesPanel.h index d69880b..a743849 100644 --- a/src/view/PreferencesPanel.h +++ b/src/view/PreferencesPanel.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef PREFERENCESPANEL_H @@ -40,34 +40,34 @@ class KissCount; class PreferencesPanel: public wxPanel { - public: - PreferencesPanel(KissCount* kiss, wxUI *parent); - void ChangeUser(); +public: + PreferencesPanel(KissCount* kiss, wxUI *parent); + void ChangeUser(); - void OnAccountModified(wxGridEvent& event); - void OnCategoryModified(wxGridEvent& event); - void OnChangeName(wxCommandEvent& event); - void OnChangePassword(wxCommandEvent& event); - void OnOperationOrderChange(wxCommandEvent& event); - void OnLanguageChange(wxCommandEvent& event); - void OnShow(wxShowEvent& event); - void OnKillMe(wxCommandEvent& event); + void OnAccountModified(wxGridEvent& event); + void OnCategoryModified(wxGridEvent& event); + void OnChangeName(wxCommandEvent& event); + void OnChangePassword(wxCommandEvent& event); + void OnOperationOrderChange(wxCommandEvent& event); + void OnLanguageChange(wxCommandEvent& event); + void OnShow(wxShowEvent& event); + void OnKillMe(wxCommandEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxGrid* _accountsGrid; - wxGrid* _categoriesGrid; - wxTextCtrl* _name; - wxBitmapComboBox* _language; - wxComboBox* _operationOrder; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxGrid* _accountsGrid; + wxGrid* _categoriesGrid; + wxTextCtrl* _name; + wxBitmapComboBox* _language; + wxComboBox* _operationOrder; - void InitAccounts(User* user); - void InitCategories(User* user); - void InitLanguage(User* user); - void InitOperationOrder(User* user); + void InitAccounts(User* user); + void InitCategories(User* user); + void InitLanguage(User* user); + void InitOperationOrder(User* user); - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/SearchPanel.cpp b/src/view/SearchPanel.cpp index 7a45062..edd321d 100644 --- a/src/view/SearchPanel.cpp +++ b/src/view/SearchPanel.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "AccountPanel.h" @@ -31,347 +31,347 @@ END_EVENT_TABLE() #define SET_ROW_COLOR(row, color) for(int i=0; iSetCellBackgroundColour(row, i, color); \ + _grid->SetCellBackgroundColour(row, i, color); \ } SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : wxScrolledWindow(&(*parent)), _kiss(kiss), _wxUI(parent), _operations(NULL) { - DEFAULT_FONT(font); - User* user = _kiss->GetUser(); - std::vector::iterator accountIt; - std::vector::iterator categoryIt; - wxDateTime firstOfMonth; + DEFAULT_FONT(font); + User* user = _kiss->GetUser(); + std::vector::iterator accountIt; + std::vector::iterator categoryIt; + wxDateTime firstOfMonth; - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - SetSizer(vbox); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + SetSizer(vbox); - _checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from")); - _checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to")); + _checkDateFrom = new wxCheckBox(this, wxID_ANY, _("Date from")); + _checkDateTo = new wxCheckBox(this, wxID_ANY, _("Date to")); - _checkDateFrom->SetValue(wxT("1")); - _checkDateTo->SetValue(wxT("1")); + _checkDateFrom->SetValue(wxT("1")); + _checkDateTo->SetValue(wxT("1")); - wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 9); + wxGridBagSizer *gridBagSizer = new wxGridBagSizer(3, 9); - firstOfMonth.SetToCurrent(); - firstOfMonth.SetDay(1); - _calendarFrom = new wxCalendarCtrl(this, CALENDAR_FROM_ID, firstOfMonth, wxDefaultPosition, wxDefaultSize, - wxCAL_MONDAY_FIRST); - _calendarTo = new wxCalendarCtrl(this, CALENDAR_TO_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, - wxCAL_MONDAY_FIRST); + firstOfMonth.SetToCurrent(); + firstOfMonth.SetDay(1); + _calendarFrom = new wxCalendarCtrl(this, CALENDAR_FROM_ID, firstOfMonth, wxDefaultPosition, wxDefaultSize, + wxCAL_MONDAY_FIRST); + _calendarTo = new wxCalendarCtrl(this, CALENDAR_TO_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, + wxCAL_MONDAY_FIRST); - _description = new wxTextCtrl(this, wxID_ANY); - wxSize size = _description->GetSize(); - size.SetWidth(size.GetWidth()*2); - _description->SetMinSize(size); - _amountFrom = new wxTextCtrl(this, wxID_ANY); - _amountTo = new wxTextCtrl(this, wxID_ANY); + _description = new wxTextCtrl(this, wxID_ANY); + wxSize size = _description->GetSize(); + size.SetWidth(size.GetWidth()*2); + _description->SetMinSize(size); + _amountFrom = new wxTextCtrl(this, wxID_ANY); + _amountTo = new wxTextCtrl(this, wxID_ANY); - _category = new wxCheckListBox(this, wxID_ANY); - for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++) - _category->Append(categoryIt->name); - _account = new wxCheckListBox(this, wxID_ANY); - for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++) - _account->Append(accountIt->name); + _category = new wxCheckListBox(this, wxID_ANY); + for(categoryIt = user->_categories.begin(); categoryIt != user->_categories.end(); categoryIt++) + _category->Append(categoryIt->name); + _account = new wxCheckListBox(this, wxID_ANY); + for(accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++) + _account->Append(accountIt->name); - _searchButton = new wxButton(this, SEARCH_ID, _("Search")); + _searchButton = new wxButton(this, SEARCH_ID, _("Search")); - wxStaticText* labelDescription = new wxStaticText(this, wxID_ANY, _("Description")); - wxStaticText* labelAmountFrom = new wxStaticText(this, wxID_ANY, _("Amount from")); - wxStaticText* labelAmountTo = new wxStaticText(this, wxID_ANY, _("Amount to")); - wxStaticText* labelCategory = new wxStaticText(this, wxID_ANY, _("Category")); - wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account")); + wxStaticText* labelDescription = new wxStaticText(this, wxID_ANY, _("Description")); + wxStaticText* labelAmountFrom = new wxStaticText(this, wxID_ANY, _("Amount from")); + wxStaticText* labelAmountTo = new wxStaticText(this, wxID_ANY, _("Amount to")); + wxStaticText* labelCategory = new wxStaticText(this, wxID_ANY, _("Category")); + wxStaticText* labelAccount = new wxStaticText(this, wxID_ANY, _("Account")); - gridBagSizer->Add(labelDescription, wxGBPosition(0, 0)); - gridBagSizer->Add(_description, wxGBPosition(1, 0)); - gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1)); - gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1)); - gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2)); - gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2)); - gridBagSizer->Add(labelAmountFrom, wxGBPosition(0, 3)); - gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3)); - gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4)); - gridBagSizer->Add(_amountTo, wxGBPosition(1, 4)); - gridBagSizer->Add(labelCategory, wxGBPosition(0, 5)); - gridBagSizer->Add(_category, wxGBPosition(1, 5)); - gridBagSizer->Add(labelAccount, wxGBPosition(0, 6)); - gridBagSizer->Add(_account, wxGBPosition(1, 6)); - gridBagSizer->Add(_searchButton, wxGBPosition(2, 0)); + gridBagSizer->Add(labelDescription, wxGBPosition(0, 0)); + gridBagSizer->Add(_description, wxGBPosition(1, 0)); + gridBagSizer->Add(_checkDateFrom, wxGBPosition(0, 1)); + gridBagSizer->Add(_calendarFrom, wxGBPosition(1, 1)); + gridBagSizer->Add(_checkDateTo, wxGBPosition(0, 2)); + gridBagSizer->Add(_calendarTo, wxGBPosition(1, 2)); + gridBagSizer->Add(labelAmountFrom, wxGBPosition(0, 3)); + gridBagSizer->Add(_amountFrom, wxGBPosition(1, 3)); + gridBagSizer->Add(labelAmountTo, wxGBPosition(0, 4)); + gridBagSizer->Add(_amountTo, wxGBPosition(1, 4)); + gridBagSizer->Add(labelCategory, wxGBPosition(0, 5)); + gridBagSizer->Add(_category, wxGBPosition(1, 5)); + gridBagSizer->Add(labelAccount, wxGBPosition(0, 6)); + gridBagSizer->Add(_account, wxGBPosition(1, 6)); + gridBagSizer->Add(_searchButton, wxGBPosition(2, 0)); - vbox->Add(gridBagSizer); - vbox->Add(-1, 20); + vbox->Add(gridBagSizer); + vbox->Add(-1, 20); - _grid = new GridAccount(_kiss, this, GRID_ID); + _grid = new GridAccount(_kiss, this, GRID_ID); - vbox->Add(_grid); + vbox->Add(_grid); - Fit(); + Fit(); - SetMinSize(wxSize(1024, 640)); - SetScrollbars(10, 10, 100/10, 100/10); + SetMinSize(wxSize(1024, 640)); + SetScrollbars(10, 10, 100/10, 100/10); - Hide(); + Hide(); } SearchPanel::~SearchPanel() { - if (_operations) delete _operations; + if (_operations) delete _operations; } void SearchPanel::OnButtonSearch(wxCommandEvent& event) { - wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL; - std::vector categories, accounts; - wxDateTime *dateFrom=NULL, *dateTo=NULL; - User* user= _kiss->GetUser(); - int i; - std::vector::iterator it; - double af, at; + wxString *description=NULL, *amountFrom=NULL, *amountTo=NULL; + std::vector categories, accounts; + wxDateTime *dateFrom=NULL, *dateTo=NULL; + User* user= _kiss->GetUser(); + int i; + std::vector::iterator it; + double af, at; - if (_calendarFrom->GetDate() > _calendarTo->GetDate()) + if (_calendarFrom->GetDate() > _calendarTo->GetDate()) { - wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("Invalid date range"), _("Error"), wxICON_ERROR | wxOK); + return; } - if (_amountFrom->GetLineText(0).Length()) + if (_amountFrom->GetLineText(0).Length()) { - amountFrom = new wxString; - *amountFrom = _amountFrom->GetLineText(0); - if (!amountFrom->ToDouble(&af)) + amountFrom = new wxString; + *amountFrom = _amountFrom->GetLineText(0); + if (!amountFrom->ToDouble(&af)) { - wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK); - delete amountFrom; - return; + wxMessageBox(_("Invalid amount from"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + return; } - if (af < 0) af *= -1; + if (af < 0) af *= -1; } - if (_amountTo->GetLineText(0).Length()) + if (_amountTo->GetLineText(0).Length()) { - amountTo = new wxString; - *amountTo = _amountTo->GetLineText(0); - if (!amountTo->ToDouble(&at)) + amountTo = new wxString; + *amountTo = _amountTo->GetLineText(0); + if (!amountTo->ToDouble(&at)) { - wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK); - delete amountFrom; - delete amountTo; - return; + wxMessageBox(_("Invalid amount to"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + delete amountTo; + return; } - if (at < 0) at *= -1; + if (at < 0) at *= -1; } - if (amountFrom && amountTo && af > at) + if (amountFrom && amountTo && af > at) { - wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK); - delete amountFrom; - delete amountTo; - return; + wxMessageBox(_("Invalid amount range"), _("Error"), wxICON_ERROR | wxOK); + delete amountFrom; + delete amountTo; + return; } - _grid->DeleteRows(1, _grid->GetNumberRows()-1); + _grid->DeleteRows(1, _grid->GetNumberRows()-1); - if (_description->GetLineText(0).Length()) + if (_description->GetLineText(0).Length()) { - description = new wxString; - *description = _description->GetLineText(0); + description = new wxString; + *description = _description->GetLineText(0); } - if (_checkDateFrom->IsChecked()) + if (_checkDateFrom->IsChecked()) { - dateFrom = new wxDateTime; - *dateFrom = _calendarFrom->GetDate(); + dateFrom = new wxDateTime; + *dateFrom = _calendarFrom->GetDate(); } - if (_checkDateTo->IsChecked()) + if (_checkDateTo->IsChecked()) { - dateTo = new wxDateTime; - *dateTo = _calendarTo->GetDate(); + dateTo = new wxDateTime; + *dateTo = _calendarTo->GetDate(); } - if (dateFrom && dateTo && *dateFrom > *dateTo) + if (dateFrom && dateTo && *dateFrom > *dateTo) { - ; + ; } - for(i=0; iGetCategoriesNumber(); i++) - if (_category->IsChecked(i)) - categories.push_back(user->_categories[i].id); + for(i=0; iGetCategoriesNumber(); i++) + if (_category->IsChecked(i)) + categories.push_back(user->_categories[i].id); - for(i=0; iGetAccountsNumber(); i++) - if (_account->IsChecked(i)) - accounts.push_back(user->_accounts[i].id); + for(i=0; iGetAccountsNumber(); i++) + if (_account->IsChecked(i)) + accounts.push_back(user->_accounts[i].id); - if (_operations) - delete _operations; + if (_operations) + delete _operations; - _operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); + _operations = _kiss->Search(description, dateFrom, dateTo, amountFrom, amountTo, categories, accounts); - if (_operations->size() > 1) - wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); - else if (_operations->size() == 1) - wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); - else + if (_operations->size() > 1) + wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + else if (_operations->size() == 1) + wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + else { - wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); - return; + wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); + return; } - for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++) + for(i=1, it = _operations->begin(); it != _operations->end(); it++, i++) { - _grid->InsertOperation(user, &(*it), i, false, 0, 0); + _grid->InsertOperation(user, &(*it), i, false, 0, 0); } - _grid->AutoSizeColumn(CATEGORY, false); - _grid->AutoSizeColumn(DATE, false); - _grid->AutoSizeColumn(ACCOUNT, false); - _grid->AutoSizeColumn(DELETE, false); - _grid->AutoSizeColumn(CHECKED, false); + _grid->AutoSizeColumn(CATEGORY, false); + _grid->AutoSizeColumn(DATE, false); + _grid->AutoSizeColumn(ACCOUNT, false); + _grid->AutoSizeColumn(DELETE, false); + _grid->AutoSizeColumn(CHECKED, false); - _wxUI->Layout(); + _wxUI->Layout(); } void SearchPanel::OnShow(wxShowEvent& event) { - _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search")); + _wxUI->SetTitle(_kiss->GetUser()->_name + wxT(" - ") + _("Search")); } void SearchPanel::OnCalendarFromChange(wxCalendarEvent& event) { - _checkDateFrom->SetValue(true); + _checkDateFrom->SetValue(true); } void SearchPanel::OnCalendarToChange(wxCalendarEvent& event) { - _checkDateTo->SetValue(true); + _checkDateTo->SetValue(true); } void SearchPanel::OnOperationModified(wxGridEvent& event) { - User* user = _kiss->GetUser(); - int row = event.GetRow()-1; - int col = event.GetCol(); - Operation new_op, cur_op; - int op_complete = 6; - wxString value ; - wxDateTime date; - static bool inModification = false ; - wxColour color ; - unsigned char r, g, b; + User* user = _kiss->GetUser(); + int row = event.GetRow()-1; + int col = event.GetCol(); + Operation new_op, cur_op; + int op_complete = 6; + wxString value ; + wxDateTime date; + static bool inModification = false ; + wxColour color ; + unsigned char r, g, b; - // Avoid recursives calls - if (inModification) return; + // Avoid recursives calls + if (inModification) return; - inModification = true ; + inModification = true ; - if (event.GetCol() == DEBIT) - _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); - else if (event.GetCol() == CREDIT) - _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); + if (event.GetCol() == DEBIT) + _grid->SetCellValue(event.GetRow(), CREDIT, wxT("")); + else if (event.GetCol() == CREDIT) + _grid->SetCellValue(event.GetRow(), DEBIT, wxT("")); - value = _grid->GetCellValue(event.GetRow(), DESCRIPTION); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), DESCRIPTION); + if (value.Length()) { - new_op.description = value; - op_complete--; + new_op.description = value; + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), DATE); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), DATE); + if (value.Length()) { - 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--; + 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.Length()) + value = _grid->GetCellValue(event.GetRow(), DEBIT); + if (value.Length()) { - value.ToDouble(&new_op.amount); - new_op.amount *= -1.0; - op_complete--; + value.ToDouble(&new_op.amount); + new_op.amount *= -1.0; + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CREDIT); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), CREDIT); + if (value.Length()) { - value.ToDouble(&new_op.amount); - op_complete--; + value.ToDouble(&new_op.amount); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CATEGORY); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), CATEGORY); + if (value.Length()) { - new_op.category = user->GetCategoryId(value); - op_complete--; + new_op.category = user->GetCategoryId(value); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), ACCOUNT); - if (value.Length()) + value = _grid->GetCellValue(event.GetRow(), ACCOUNT); + if (value.Length()) { - new_op.account = user->GetAccountId(value); - op_complete--; + new_op.account = user->GetAccountId(value); + op_complete--; } - value = _grid->GetCellValue(event.GetRow(), CHECKED); - if (value.Length() && value != wxT("0")) - new_op.checked = true; - else - new_op.checked = false; - op_complete--; + value = _grid->GetCellValue(event.GetRow(), CHECKED); + if (value.Length() && value != wxT("0")) + new_op.checked = true; + else + new_op.checked = false; + op_complete--; - if (col == CHECKED || col == CATEGORY) + if (col == CHECKED || col == CATEGORY) { - color = user->GetCategory(new_op.category).color; + color = user->GetCategory(new_op.category).color; - if (new_op.checked) + 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()); + 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); + SET_ROW_COLOR(event.GetRow(), color); } - if (col == DELETE) + 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) + 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")); - _wxUI->NeedReload(); - inModification = false; - return; + _grid->SetCellValue(event.GetRow(), event.GetCol(), wxT("0")); + _wxUI->NeedReload(); + inModification = false; + return; } } - // Modify an operation - cur_op = (*_operations)[row] ; - new_op.id = cur_op.id; - new_op.fix_cost = false; - new_op.transfert = cur_op.transfert; + // Modify an operation + cur_op = (*_operations)[row] ; + new_op.id = cur_op.id; + new_op.fix_cost = false; + new_op.transfert = cur_op.transfert; - if (col == DELETE) + if (col == DELETE) { - _grid->DeleteRows(event.GetRow(), 1); - _kiss->DeleteOperation(cur_op); - _operations->erase(_operations->begin()+row); - _wxUI->NeedReload(); - inModification = false ; - return ; + _grid->DeleteRows(event.GetRow(), 1); + _kiss->DeleteOperation(cur_op); + _operations->erase(_operations->begin()+row); + _wxUI->NeedReload(); + inModification = false ; + return ; } - (*_operations)[row] = new_op; - _kiss->UpdateOperation(new_op); + (*_operations)[row] = new_op; + _kiss->UpdateOperation(new_op); - _wxUI->NeedReload(); + _wxUI->NeedReload(); - inModification = false ; + inModification = false ; } diff --git a/src/view/SearchPanel.h b/src/view/SearchPanel.h index dfcfc37..7ef12fe 100644 --- a/src/view/SearchPanel.h +++ b/src/view/SearchPanel.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef SEARCHPANEL_H @@ -40,27 +40,27 @@ class GridAccount; class SearchPanel: public wxScrolledWindow { - public: - SearchPanel(KissCount* kiss, wxUI *parent); - ~SearchPanel(); +public: + SearchPanel(KissCount* kiss, wxUI *parent); + ~SearchPanel(); - void OnButtonSearch(wxCommandEvent& event); - void OnOperationModified(wxGridEvent& event); - void OnShow(wxShowEvent& event); - void OnCalendarFromChange(wxCalendarEvent& event); - void OnCalendarToChange(wxCalendarEvent& event); + void OnButtonSearch(wxCommandEvent& event); + void OnOperationModified(wxGridEvent& event); + void OnShow(wxShowEvent& event); + void OnCalendarFromChange(wxCalendarEvent& event); + void OnCalendarToChange(wxCalendarEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - std::vector *_operations; - wxCalendarCtrl* _calendarFrom, *_calendarTo; - GridAccount *_grid; - wxCheckBox *_checkDateFrom, *_checkDateTo; - wxTextCtrl* _description, *_amountFrom, *_amountTo; - wxCheckListBox* _category, *_account; - wxButton* _searchButton; - DECLARE_EVENT_TABLE(); +private: + KissCount* _kiss; + wxUI* _wxUI; + std::vector *_operations; + wxCalendarCtrl* _calendarFrom, *_calendarTo; + GridAccount *_grid; + wxCheckBox *_checkDateFrom, *_checkDateTo; + wxTextCtrl* _description, *_amountFrom, *_amountTo; + wxCheckListBox* _category, *_account; + wxButton* _searchButton; + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/StatsPanel.cpp b/src/view/StatsPanel.cpp index 64ded12..b59059b 100644 --- a/src/view/StatsPanel.cpp +++ b/src/view/StatsPanel.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "StatsPanel.h" @@ -28,280 +28,280 @@ END_EVENT_TABLE() StatsPanel::StatsPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _plot(NULL), _chart(NULL) { - wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); - _hbox2 = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); - _vbox2 = new wxBoxSizer(wxVERTICAL); - int i; - User* user = _kiss->GetUser(); - std::vector::iterator accountIt; - std::vector::iterator categoryIt; - std::map > operations; - std::map >::iterator it; + wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); + _hbox2 = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); + _vbox2 = new wxBoxSizer(wxVERTICAL); + int i; + User* user = _kiss->GetUser(); + std::vector::iterator accountIt; + std::vector::iterator categoryIt; + std::map > operations; + std::map >::iterator it; - SetSizer(vbox); + SetSizer(vbox); - _monthFrom = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, months); - _yearFrom = new wxChoice (this, RANGE_ID); - _monthTo = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, months); - _yearTo = new wxChoice (this, RANGE_ID); + _monthFrom = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, months); + _yearFrom = new wxChoice (this, RANGE_ID); + _monthTo = new wxChoice (this, RANGE_ID, wxDefaultPosition, wxDefaultSize, 12, months); + _yearTo = new wxChoice (this, RANGE_ID); - operations = _kiss->GetAllOperations(); + operations = _kiss->GetAllOperations(); - for(i=0, it = operations.begin(); it != operations.end(); it++, i++) + for(i=0, it = operations.begin(); it != operations.end(); it++, i++) { - _yearFrom->Append(wxString::Format(wxT("%d"), it->first)); - _yearTo->Append(wxString::Format(wxT("%d"), it->first)); + _yearFrom->Append(wxString::Format(wxT("%d"), it->first)); + _yearTo->Append(wxString::Format(wxT("%d"), it->first)); } - _monthFrom->Select(0); - _monthTo->Select(11); - _yearFrom->Select(i); - _yearTo->Select(i); + _monthFrom->Select(0); + _monthTo->Select(11); + _yearFrom->Select(i); + _yearTo->Select(i); - wxStaticText* label = new wxStaticText(this, wxID_ANY, _("From")); - hbox->Add(label); - hbox->Add(-1, 10); - hbox->Add(_monthFrom); - hbox->Add(_yearFrom); + wxStaticText* label = new wxStaticText(this, wxID_ANY, _("From")); + hbox->Add(label); + hbox->Add(-1, 10); + hbox->Add(_monthFrom); + hbox->Add(_yearFrom); - hbox->Add(-1, 30); - label = new wxStaticText(this, wxID_ANY, _("To")); - hbox->Add(label); - hbox->Add(-1, 10); - hbox->Add(_monthTo); - hbox->Add(_yearTo); + hbox->Add(-1, 30); + label = new wxStaticText(this, wxID_ANY, _("To")); + hbox->Add(label); + hbox->Add(-1, 10); + hbox->Add(_monthTo); + hbox->Add(_yearTo); - _account = new wxCheckListBox(this, ACCOUNTS_ID); - for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++) + _account = new wxCheckListBox(this, ACCOUNTS_ID); + for(i=0, accountIt = user->_accounts.begin(); accountIt != user->_accounts.end(); accountIt++, i++) { - _account->Append(accountIt->name); - _account->Check(i); + _account->Append(accountIt->name); + _account->Check(i); } - _categories = new wxString[user->GetCategoriesNumber()] ; - for(i=0, categoryIt = user->_categories.begin(); - categoryIt != user->_categories.end(); - categoryIt++, i++) + _categories = new wxString[user->GetCategoriesNumber()] ; + for(i=0, categoryIt = user->_categories.begin(); + categoryIt != user->_categories.end(); + categoryIt++, i++) { - _categoriesIndexes[categoryIt->id] = i; - _categories[i] = categoryIt->name ; + _categoriesIndexes[categoryIt->id] = i; + _categories[i] = categoryIt->name ; } - DEFAULT_FONT(font); + DEFAULT_FONT(font); - _statsGrid = new wxGrid(this, wxID_ANY); + _statsGrid = new wxGrid(this, wxID_ANY); - _statsGrid->CreateGrid(user->GetCategoriesNumber(), 2); - _statsGrid->SetColLabelSize(0); - _statsGrid->SetRowLabelSize(0); - _statsGrid->EnableEditing(false); + _statsGrid->CreateGrid(user->GetCategoriesNumber(), 2); + _statsGrid->SetColLabelSize(0); + _statsGrid->SetRowLabelSize(0); + _statsGrid->EnableEditing(false); - _statsGrid->SetDefaultCellFont(font); - _statsGrid->AutoSizeColumn(0, true); + _statsGrid->SetDefaultCellFont(font); + _statsGrid->AutoSizeColumn(0, true); - for(i=0; iGetCategoriesNumber(); i++) + for(i=0; iGetCategoriesNumber(); i++) { - _statsGrid->SetCellValue(i, 0, _categories[i]); - _statsGrid->SetCellAlignment(i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); + _statsGrid->SetCellValue(i, 0, _categories[i]); + _statsGrid->SetCellAlignment(i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); } - _vbox2->Add(_account); - _vbox2->Add(-1, 10); - _vbox2->Add(_statsGrid); + _vbox2->Add(_account); + _vbox2->Add(-1, 10); + _vbox2->Add(_statsGrid); - _pie = new PiePlot(); + _pie = new PiePlot(); - _dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber()); - ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors)); + _dataset = new CategorySimpleDataset(_categories, user->GetCategoriesNumber()); + ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors)); - _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)); - wxChartPanel* chart = new wxChartPanel(this); - chart->SetChart(new Chart(_pie, _("Cost repartition"))); - chart->Fit(); - chart->Layout(); - chart->SetMinSize(// chart->GetSize() - wxSize(200,250)); + wxChartPanel* chart = new wxChartPanel(this); + chart->SetChart(new Chart(_pie, _("Cost repartition"))); + chart->Fit(); + chart->Layout(); + chart->SetMinSize(// chart->GetSize() + wxSize(200,250)); - wxCommandEvent event ; - OnRangeChange(event); + wxCommandEvent event ; + OnRangeChange(event); - _vbox2->Add(-1, 10); - _vbox2->Add(chart); + _vbox2->Add(-1, 10); + _vbox2->Add(chart); - vbox->Add(hbox); - vbox->Add(_hbox2); + vbox->Add(hbox); + vbox->Add(_hbox2); - Fit(); + Fit(); - Hide(); + Hide(); } void StatsPanel::UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearTo) { - std::map > > accountAmounts; - std::map categories; - std::map::iterator categoriesIt; - std::map > >::iterator accountIdIt; - std::map >::iterator accountYearIt; - double total; - int size, i, a, b, percents, account; - double *amounts; - wxString value; - User* user = _kiss->GetUser(); + std::map > > accountAmounts; + std::map categories; + std::map::iterator categoriesIt; + std::map > >::iterator accountIdIt; + std::map >::iterator accountYearIt; + double total; + int size, i, a, b, percents, account; + double *amounts; + wxString value; + User* user = _kiss->GetUser(); - if (_chart) + if (_chart) { - _hbox2->Detach(_chart); - _hbox2->Detach(_vbox2); - delete _chart; + _hbox2->Detach(_chart); + _hbox2->Detach(_vbox2); + delete _chart; } - _kiss->GetStats(monthFrom, yearFrom, monthTo, yearTo, &accountAmounts, &categories); + _kiss->GetStats(monthFrom, yearFrom, monthTo, yearTo, &accountAmounts, &categories); - // first step: create plot - _plot = new XYPlot(); + // first step: create plot + _plot = new XYPlot(); - // create dataset - XYSimpleDataset *dataset = new XYSimpleDataset(); + // create dataset + XYSimpleDataset *dataset = new XYSimpleDataset(); - // Line on 0 all over the years - size = ((yearTo - yearFrom) + 1) * 12; - amounts = new double[size*2]; - for (a=0; a<(size/12); a++) + // Line on 0 all over the years + size = ((yearTo - yearFrom) + 1) * 12; + amounts = new double[size*2]; + for (a=0; a<(size/12); a++) { - for(b=0; b<12; b++) + for(b=0; b<12; b++) { - amounts[a*12*2+b*2+0] = a*12+b; - amounts[a*12*2+b*2+1] = 0; + amounts[a*12*2+b*2+0] = a*12+b; + amounts[a*12*2+b*2+1] = 0; } } - dataset->AddSerie((double *) amounts, size); - delete[] amounts; + dataset->AddSerie((double *) amounts, size); + delete[] amounts; - for (account = 0, i = 0, accountIdIt = accountAmounts.begin(); accountIdIt != accountAmounts.end(); - accountIdIt++, i++, account++) + for (account = 0, i = 0, accountIdIt = accountAmounts.begin(); accountIdIt != accountAmounts.end(); + accountIdIt++, i++, account++) { - if (!((wxCheckListBox*)_account)->IsChecked(account)) + if (!((wxCheckListBox*)_account)->IsChecked(account)) { - i-- ; - continue; + i-- ; + continue; } - size = accountAmounts[accountIdIt->first].size(); - amounts = new double[size*12*2]; - size = 0; - for(a = 0, accountYearIt = accountAmounts[accountIdIt->first].begin(); - accountYearIt != accountAmounts[accountIdIt->first].end(); - accountYearIt++, a++) + size = accountAmounts[accountIdIt->first].size(); + amounts = new double[size*12*2]; + size = 0; + for(a = 0, accountYearIt = accountAmounts[accountIdIt->first].begin(); + accountYearIt != accountAmounts[accountIdIt->first].end(); + accountYearIt++, a++) { - for(b = 0; b<12; b++) + for(b = 0; b<12; b++) { - if (!accountAmounts[accountIdIt->first][accountYearIt->first].count(b)) - continue; - amounts[size*2+0] = a*12+b; - amounts[size*2+1] = accountAmounts[accountIdIt->first][accountYearIt->first][b]; - size++; + if (!accountAmounts[accountIdIt->first][accountYearIt->first].count(b)) + continue; + amounts[size*2+0] = a*12+b; + amounts[size*2+1] = accountAmounts[accountIdIt->first][accountYearIt->first][b]; + size++; } } - dataset->AddSerie((double *) amounts, size); - // set serie names to be displayed on legend - dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt->first)); - delete[] amounts; + dataset->AddSerie((double *) amounts, size); + // set serie names to be displayed on legend + dataset->SetSerieName(i+1, user->GetAccountName(accountIdIt->first)); + delete[] amounts; } - // create line renderer and set it to dataset - XYLineRenderer *renderer = new XYLineRenderer(true, true); - dataset->SetRenderer(renderer); + // create line renderer and set it to dataset + XYLineRenderer *renderer = new XYLineRenderer(true, true); + dataset->SetRenderer(renderer); - // add our dataset to plot - _plot->AddDataset(dataset); + // add our dataset to plot + _plot->AddDataset(dataset); - // create left and bottom number axes - NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT); - NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM); + // create left and bottom number axes + NumberAxis *leftAxis = new NumberAxis(AXIS_LEFT); + NumberAxis *bottomAxis = new NumberAxis(AXIS_BOTTOM); - // add axes to plot - _plot->AddAxis(leftAxis); - _plot->AddAxis(bottomAxis); + // add axes to plot + _plot->AddAxis(leftAxis); + _plot->AddAxis(bottomAxis); - // link axes and dataset - _plot->LinkDataVerticalAxis(0, 0); - _plot->LinkDataHorizontalAxis(0, 0); + // link axes and dataset + _plot->LinkDataVerticalAxis(0, 0); + _plot->LinkDataHorizontalAxis(0, 0); - // set legend - _plot->SetLegend(new Legend(wxCENTER, wxRIGHT)); + // set legend + _plot->SetLegend(new Legend(wxCENTER, wxRIGHT)); - _chart = new wxChartPanel(this); - _chart->SetChart(new Chart(_plot, _("Accounts"))); - _chart->Fit(); - _chart->Layout(); - _chart->SetMinSize(// chart->GetSize() - wxSize(750,550)); + _chart = new wxChartPanel(this); + _chart->SetChart(new Chart(_plot, _("Accounts"))); + _chart->Fit(); + _chart->Layout(); + _chart->SetMinSize(// chart->GetSize() + wxSize(750,550)); - _hbox2->Add(_chart); + _hbox2->Add(_chart); - total = 0.0; - for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++) - total += categoriesIt->second; + total = 0.0; + for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++) + total += categoriesIt->second; - for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++) + for(categoriesIt = categories.begin(); categoriesIt != categories.end(); categoriesIt++) { - _categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second; - if (total) - percents = ((double) (categoriesIt->second*100))/total; - else - percents = 0; - value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents); - _statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value); + _categoriesValues[_categoriesIndexes[categoriesIt->first]] = categoriesIt->second; + if (total) + percents = ((double) (categoriesIt->second*100))/total; + else + percents = 0; + value = wxString::Format(wxT("%0.2lf (%02d%%)"), categoriesIt->second, percents); + _statsGrid->SetCellValue(_categoriesIndexes[categoriesIt->first], 1, value); } - _statsGrid->AutoSizeColumn(0, true); - _statsGrid->AutoSizeColumn(1, true); + _statsGrid->AutoSizeColumn(0, true); + _statsGrid->AutoSizeColumn(1, true); - _pie->DatasetChanged(_dataset); + _pie->DatasetChanged(_dataset); - _hbox2->Add(_vbox2); + _hbox2->Add(_vbox2); - Layout(); + Layout(); } void StatsPanel::OnShow(wxShowEvent& event) { - _wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Statistics")); + _wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + _("Statistics")); } void StatsPanel::OnRangeChange(wxCommandEvent& event) { - int monthFrom, monthTo, yearFrom, yearTo; + int monthFrom, monthTo, yearFrom, yearTo; - monthFrom = _monthFrom->GetCurrentSelection(); - _yearFrom->GetStringSelection().ToLong((long*)&yearFrom); - monthTo = _monthTo->GetCurrentSelection(); - _yearTo->GetStringSelection().ToLong((long*)&yearTo); + monthFrom = _monthFrom->GetCurrentSelection(); + _yearFrom->GetStringSelection().ToLong((long*)&yearFrom); + monthTo = _monthTo->GetCurrentSelection(); + _yearTo->GetStringSelection().ToLong((long*)&yearTo); - if (yearTo > yearFrom || - (yearFrom == yearTo && monthFrom >= monthTo)) + if (yearTo > yearFrom || + (yearFrom == yearTo && monthFrom >= monthTo)) { - wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("Invalide date range"), _("KissCount"), wxICON_ERROR | wxOK); + return; } - UpdateStats(monthFrom, yearFrom, monthTo, yearTo); + UpdateStats(monthFrom, yearFrom, monthTo, yearTo); } void StatsPanel::OnAccountsChange(wxCommandEvent& event) { - OnRangeChange(event); + OnRangeChange(event); } diff --git a/src/view/StatsPanel.h b/src/view/StatsPanel.h index 7daaee8..b4fd2af 100644 --- a/src/view/StatsPanel.h +++ b/src/view/StatsPanel.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef STATSPANEL_H @@ -43,34 +43,34 @@ class KissCount; class StatsPanel: public wxPanel //public wxScrolledWindow { - public: - StatsPanel(KissCount* kiss, wxUI *parent); - //~StatsPanel(); +public: + StatsPanel(KissCount* kiss, wxUI *parent); + //~StatsPanel(); - void OnShow(wxShowEvent& event); + void OnShow(wxShowEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxCalendarCtrl* _calendarFrom, *_calendarTo; - wxChoice* _monthFrom, *_yearFrom, *_monthTo, *_yearTo; - wxGrid *_statsGrid; - PiePlot* _pie; - double *_categoriesValues; - CategorySimpleDataset* _dataset; - XYPlot *_plot ; - wxString* _categories; - std::map _categoriesIndexes; - wxBoxSizer *_hbox2, *_vbox2; - wxChartPanel* _chart; - wxCheckListBox* _account; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxCalendarCtrl* _calendarFrom, *_calendarTo; + wxChoice* _monthFrom, *_yearFrom, *_monthTo, *_yearTo; + wxGrid *_statsGrid; + PiePlot* _pie; + double *_categoriesValues; + CategorySimpleDataset* _dataset; + XYPlot *_plot ; + wxString* _categories; + std::map _categoriesIndexes; + wxBoxSizer *_hbox2, *_vbox2; + wxChartPanel* _chart; + wxCheckListBox* _account; - void UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearTo); + void UpdateStats(int monthFrom, int yearFrom, int monthTo, int yearTo); - void OnRangeChange(wxCommandEvent& event); - void OnAccountsChange(wxCommandEvent& event); + void OnRangeChange(wxCommandEvent& event); + void OnAccountsChange(wxCommandEvent& event); - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/SupportedLanguages.cpp b/src/view/SupportedLanguages.cpp index 36fe08d..dde3792 100644 --- a/src/view/SupportedLanguages.cpp +++ b/src/view/SupportedLanguages.cpp @@ -1,26 +1,26 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "SupportedLanguages.h" language languages[NB_SUPPORTED_LANGUAGES] = { - { wxT("English"), wxT(ICONS_PATH "/United Kingdom.png"), wxLANGUAGE_ENGLISH}, - { wxT("Français"), wxT(ICONS_PATH "/France.png"), wxLANGUAGE_FRENCH} + { wxT("English"), wxT(ICONS_PATH "/United Kingdom.png"), wxLANGUAGE_ENGLISH}, + { wxT("Français"), wxT(ICONS_PATH "/France.png"), wxLANGUAGE_FRENCH} }; diff --git a/src/view/SupportedLanguages.h b/src/view/SupportedLanguages.h index 71669a5..44019c0 100644 --- a/src/view/SupportedLanguages.h +++ b/src/view/SupportedLanguages.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef SUPPORTEDLANGUAGES_H @@ -23,9 +23,9 @@ along with KissCount. If not, see . #include typedef struct { - wxString name; - wxString icon; - wxLanguage language; + wxString name; + wxString icon; + wxLanguage language; } language ; #define NB_SUPPORTED_LANGUAGES 2 diff --git a/src/view/UsersDialog.cpp b/src/view/UsersDialog.cpp index f4adfd7..f4f1dbf 100644 --- a/src/view/UsersDialog.cpp +++ b/src/view/UsersDialog.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "UsersDialog.h" @@ -29,96 +29,96 @@ END_EVENT_TABLE() UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent) { - wxGridBagSizer *gridBagSizer; - wxStaticText* label; - wxCommandEvent event; + wxGridBagSizer *gridBagSizer; + wxStaticText* label; + wxCommandEvent event; - gridBagSizer = new wxGridBagSizer(4, 4); + gridBagSizer = new wxGridBagSizer(4, 4); - label = new wxStaticText(this, -1, _("User ")); - gridBagSizer->Add(label, wxGBPosition(0, 0)); - _users = new wxChoice(this, wxID_ANY); - gridBagSizer->Add(_users, wxGBPosition(0, 1)); + label = new wxStaticText(this, -1, _("User ")); + gridBagSizer->Add(label, wxGBPosition(0, 0)); + _users = new wxChoice(this, wxID_ANY); + gridBagSizer->Add(_users, wxGBPosition(0, 1)); - label = new wxStaticText(this, -1, _("Password ")); - gridBagSizer->Add(label, wxGBPosition(1, 0)); - _password = new wxTextCtrl(this, wxID_ANY); - gridBagSizer->Add(_password, wxGBPosition(1, 1)); + label = new wxStaticText(this, -1, _("Password ")); + gridBagSizer->Add(label, wxGBPosition(1, 0)); + _password = new wxTextCtrl(this, wxID_ANY); + gridBagSizer->Add(_password, wxGBPosition(1, 1)); - _password->SetWindowStyle(wxTE_PASSWORD); + _password->SetWindowStyle(wxTE_PASSWORD); - 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)); + 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)); - std::list users_list = _kiss->GetUsers(); + std::list users_list = _kiss->GetUsers(); - for(std::list::iterator i = users_list.begin(); i != users_list.end(); i++) + for(std::list::iterator i = users_list.begin(); i != users_list.end(); i++) { - _users->Append(*i); + _users->Append(*i); } - _users->Select(0); + _users->Select(0); - SetSizer(gridBagSizer); + SetSizer(gridBagSizer); - _users->SetFocus(); - Layout(); - Center(); + _users->SetFocus(); + Layout(); + Center(); - if (users_list.size() == 0) - OnNewUser(event); - else - ShowModal(); + if (users_list.size() == 0) + OnNewUser(event); + else + ShowModal(); } void UsersDialog::OnOK(wxCommandEvent& event) { - // No users in database - if (!_users->GetStringSelection().Length()) + // No users in database + if (!_users->GetStringSelection().Length()) { - return; + return; } - if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0))) + if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0))) { - wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK); + wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK); } - else + else { - _kiss->LoadUser(_users->GetStringSelection()); - Close(); + _kiss->LoadUser(_users->GetStringSelection()); + Close(); } } void UsersDialog::OnCancel(wxCommandEvent& event) { - Close(); + Close(); } void UsersDialog::OnNewUser(wxCommandEvent& event) { - wxString name; - wxTextEntryDialog u(this, wxT(""), _("New User")); + wxString name; + wxTextEntryDialog u(this, wxT(""), _("New User")); - if (u.ShowModal() == wxID_CANCEL) - return; + if (u.ShowModal() == wxID_CANCEL) + return; - name = u.GetValue(); + name = u.GetValue(); - if (!name.size()) return; + if (!name.size()) return; - if (_kiss->UserExists(name)) + if (_kiss->UserExists(name)) { - wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK); - return; + wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK); + return; } - _kiss->NewUser(name); - _kiss->LoadUser(name); + _kiss->NewUser(name); + _kiss->LoadUser(name); - Close(); + Close(); } diff --git a/src/view/UsersDialog.h b/src/view/UsersDialog.h index 682ef00..4799826 100644 --- a/src/view/UsersDialog.h +++ b/src/view/UsersDialog.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef USERSDIALOG_H @@ -34,20 +34,20 @@ class KissCount; class UsersDialog : public wxDialog { - public: - UsersDialog(KissCount* kiss, wxUI *parent); +public: + UsersDialog(KissCount* kiss, wxUI *parent); - void OnOK(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); - void OnNewUser(wxCommandEvent& event); + void OnOK(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnNewUser(wxCommandEvent& event); - private: - KissCount* _kiss; - wxUI* _wxUI; - wxChoice* _users; - wxTextCtrl* _password; +private: + KissCount* _kiss; + wxUI* _wxUI; + wxChoice* _users; + wxTextCtrl* _password; - DECLARE_EVENT_TABLE(); + DECLARE_EVENT_TABLE(); }; #endif diff --git a/src/view/view.h b/src/view/view.h index 163da1a..f475a42 100644 --- a/src/view/view.h +++ b/src/view/view.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef VIEW_H diff --git a/src/view/wxGridCellBitmapRenderer.cpp b/src/view/wxGridCellBitmapRenderer.cpp index 725d8f5..e48319f 100644 --- a/src/view/wxGridCellBitmapRenderer.cpp +++ b/src/view/wxGridCellBitmapRenderer.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "wxGridCellBitmapRenderer.h" @@ -26,18 +26,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/src/view/wxGridCellBitmapRenderer.h b/src/view/wxGridCellBitmapRenderer.h index 083dd38..d0f97ee 100644 --- a/src/view/wxGridCellBitmapRenderer.h +++ b/src/view/wxGridCellBitmapRenderer.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef WXGRIDCELLBITMAPRENDERER_H @@ -26,15 +26,15 @@ along with KissCount. If not, see . 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/src/view/wxUI.cpp b/src/view/wxUI.cpp index 9d0c0fd..95c5962 100644 --- a/src/view/wxUI.cpp +++ b/src/view/wxUI.cpp @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #include "wxUI.h" @@ -34,187 +34,187 @@ wxColour categoryColors[12] = {wxColour(0x00, 0x45, 0x86), wxColour(0x00, 0x84, 0xD1)}; wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame(NULL, wxID_ANY, title, pos, size), _kiss(kiss), _accountPanel(NULL), _statsPanel(NULL), - _searchPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL), _locale(NULL), _needReload(false) + : wxFrame(NULL, wxID_ANY, title, pos, size), _kiss(kiss), _accountPanel(NULL), _statsPanel(NULL), + _searchPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL), _locale(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() { - if (_accountPanel) delete _accountPanel; - if (_preferencesPanel) delete _preferencesPanel; - if (_searchPanel) delete _searchPanel; - if (_statsPanel) delete _statsPanel; - if (_locale) delete _locale; + if (_accountPanel) delete _accountPanel; + if (_preferencesPanel) delete _preferencesPanel; + if (_searchPanel) delete _searchPanel; + if (_statsPanel) delete _statsPanel; + if (_locale) delete _locale; } bool wxUI::SetLanguage(long language) { - bool res = true; + bool res = true; - if (_locale) delete _locale; - _locale = NULL; + if (_locale) delete _locale; + _locale = NULL; - // load language if possible, fall back to english otherwise - if(wxLocale::IsAvailable(language)) + // load language if possible, fall back to english otherwise + if(wxLocale::IsAvailable(language)) { - _locale = new wxLocale( language, wxLOCALE_CONV_ENCODING ); + _locale = new wxLocale( language, wxLOCALE_CONV_ENCODING ); #ifdef __WXGTK__ - _locale->AddCatalogLookupPathPrefix(wxT("./ressources/po")); + _locale->AddCatalogLookupPathPrefix(wxT("./ressources/po")); #endif - _locale->AddCatalog(wxT("french")); - _locale->AddCatalog(wxT("kisscount")); + _locale->AddCatalog(wxT("french")); + _locale->AddCatalog(wxT("kisscount")); - _language = (wxLanguage) language; + _language = (wxLanguage) language; } - if (_locale == NULL || !_locale->IsOk()) + if (_locale == NULL || !_locale->IsOk()) { - if (_locale) delete _locale; - _locale = new wxLocale(); + if (_locale) delete _locale; + _locale = new wxLocale(); #ifdef __WXGTK__ - _locale->AddCatalogLookupPathPrefix(wxT("./ressources/po")); + _locale->AddCatalogLookupPathPrefix(wxT("./ressources/po")); #endif - _locale->AddCatalog(wxT("kisscount")); + _locale->AddCatalog(wxT("kisscount")); - _language = wxLANGUAGE_ENGLISH; - res = false; + _language = wxLANGUAGE_ENGLISH; + res = false; } - months[0] = _("january"); - months[1] = _("february"); - months[2] = _("march"); - months[3] = _("april"); - months[4] = _("may"); - months[5] = _("june"); - months[6] = _("july"); - months[7] = _("august"); - months[8] = _("september"); - months[9] = _("october"); - months[10] = _("november"); - months[11] = _("december") ; + months[0] = _("january"); + months[1] = _("february"); + months[2] = _("march"); + months[3] = _("april"); + months[4] = _("may"); + months[5] = _("june"); + months[6] = _("july"); + months[7] = _("august"); + months[8] = _("september"); + months[9] = _("october"); + months[10] = _("november"); + months[11] = _("december") ; - return res; + return res; } void wxUI::ShowAccount() { - ShowPanel(_accountPanel); + ShowPanel(_accountPanel); } void wxUI::ShowSearch() { - ShowPanel(_searchPanel); + ShowPanel(_searchPanel); } void wxUI::ShowStats() { - ShowPanel(_statsPanel); + ShowPanel(_statsPanel); } void wxUI::ShowPreferences() { - ShowPanel(_preferencesPanel); + ShowPanel(_preferencesPanel); } void wxUI::ChangeUser() { - UsersDialog u(_kiss, this); + UsersDialog u(_kiss, this); } void wxUI::LoadUser() { - User* user = _kiss->GetUser(); - wxShowEvent event; + User* user = _kiss->GetUser(); + wxShowEvent event; - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel = NULL; + _hbox->Detach(_curPanel); + _curPanel = NULL; } - if (_accountPanel) - delete _accountPanel; + if (_accountPanel) + delete _accountPanel; - if (_preferencesPanel) - delete _preferencesPanel; + if (_preferencesPanel) + delete _preferencesPanel; - if (_searchPanel) - delete _searchPanel; + if (_searchPanel) + delete _searchPanel; - if (_statsPanel) - delete _statsPanel; + if (_statsPanel) + delete _statsPanel; - if (user->_preferences[wxT("language")].Length()) - SetLanguage(user->GetLanguage()); + if (user->_preferences[wxT("language")].Length()) + SetLanguage(user->GetLanguage()); - _accountPanel = new AccountPanel(_kiss, this); - _statsPanel = new StatsPanel(_kiss, this); - _searchPanel = new SearchPanel(_kiss, this); - _preferencesPanel = new PreferencesPanel(_kiss, this); + _accountPanel = new AccountPanel(_kiss, this); + _statsPanel = new StatsPanel(_kiss, this); + _searchPanel = new SearchPanel(_kiss, this); + _preferencesPanel = new PreferencesPanel(_kiss, this); - ShowPanel(_accountPanel); - _accountPanel->OnShow(event); + ShowPanel(_accountPanel); + _accountPanel->OnShow(event); } void wxUI::ShowPanel(wxPanel* panel) { - int month, year, account=0, preferences=0, search=0, stats=0; - wxShowEvent event; + int month, year, account=0, preferences=0, search=0, stats=0; + wxShowEvent event; - if (!panel) return; + if (!panel) return; - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel->Hide(); + _hbox->Detach(_curPanel); + _curPanel->Hide(); } - if (_needReload) + if (_needReload) { - if (panel == _accountPanel) + if (panel == _accountPanel) { - account = 1; - month = _accountPanel->_curMonth; - year = _accountPanel->_curYear; + account = 1; + month = _accountPanel->_curMonth; + year = _accountPanel->_curYear; } - if (panel == _preferencesPanel) + if (panel == _preferencesPanel) { - preferences = 1; + preferences = 1; } - if (panel == _searchPanel) + if (panel == _searchPanel) { - search = 1; + search = 1; } - if (panel == _statsPanel) + if (panel == _statsPanel) { - stats = 1; + stats = 1; } delete _accountPanel; @@ -224,72 +224,72 @@ void wxUI::ShowPanel(wxPanel* panel) _accountPanel = new AccountPanel(_kiss, this); if (year != -1) - { + { _kiss->LoadYear(year, true); _accountPanel->ShowMonth(month, year); - } + } _preferencesPanel = new PreferencesPanel(_kiss, this); _searchPanel = new SearchPanel(_kiss, this); _statsPanel = new StatsPanel(_kiss, this); if (account) - { + { _accountPanel->OnShow(event); panel = _accountPanel; - } + } else if (preferences) - { + { _preferencesPanel->OnShow(event); panel = _preferencesPanel; - } + } else if (search) - { + { _searchPanel->OnShow(event); panel = _searchPanel; - } + } else if (stats) - { + { _statsPanel->OnShow(event); panel = _statsPanel; - } + } - _needReload = false; + _needReload = false; } - _curPanel = panel; - _hbox->Add(panel); - _curPanel->Show(); - Layout(); + _curPanel = panel; + _hbox->Add(panel); + _curPanel->Show(); + Layout(); } void wxUI::GenerateMonth(int month, int year) { - _accountPanel->GenerateMonth(month, year); + _accountPanel->GenerateMonth(month, year); } void wxUI::KillMe() { - if (_curPanel) + if (_curPanel) { - _hbox->Detach(_curPanel); - _curPanel = NULL; + _hbox->Detach(_curPanel); + _curPanel = NULL; } - if (_accountPanel) - delete _accountPanel; + if (_accountPanel) + delete _accountPanel; - if (_preferencesPanel) - delete _preferencesPanel; + if (_preferencesPanel) + delete _preferencesPanel; - if (_searchPanel) - delete _searchPanel; + if (_searchPanel) + delete _searchPanel; - _accountPanel = NULL; - _preferencesPanel = NULL; - _searchPanel = NULL; + _accountPanel = NULL; + _preferencesPanel = NULL; + _searchPanel = NULL; } void wxUI::NeedReload() { - _needReload = true; + _needReload = true; } diff --git a/src/view/wxUI.h b/src/view/wxUI.h index 398ae95..93f80c3 100644 --- a/src/view/wxUI.h +++ b/src/view/wxUI.h @@ -1,20 +1,20 @@ /* -Copyright 2010 Grégory Soutadé + Copyright 2010 Grégory Soutadé -This file is part of KissCount. + This file is part of KissCount. -KissCount is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + KissCount is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -KissCount is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + KissCount is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with KissCount. If not, see . + You should have received a copy of the GNU General Public License + along with KissCount. If not, see . */ #ifndef WXUI_H @@ -40,39 +40,39 @@ extern wxColour categoryColors[12]; class wxUI: public wxFrame { - public: +public: - wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size); - ~wxUI(); + wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size); + ~wxUI(); - bool SetLanguage(long language); + bool SetLanguage(long language); - void ChangeUser(); - void LoadUser(); + void ChangeUser(); + void LoadUser(); - void ShowAccount(); - void ShowStats(); - void ShowSearch(); - void ShowPreferences(); - void GenerateMonth(int month, int year); + void ShowAccount(); + void ShowStats(); + void ShowSearch(); + void ShowPreferences(); + void GenerateMonth(int month, int year); - void KillMe(); + void KillMe(); - void ShowPanel(wxPanel* panel); - void NeedReload(); + void ShowPanel(wxPanel* panel); + void NeedReload(); - wxLanguage _language; + wxLanguage _language; - private: - KissCount *_kiss; - wxBoxSizer *_hbox; - AccountPanel *_accountPanel; - StatsPanel *_statsPanel; - SearchPanel *_searchPanel; - PreferencesPanel *_preferencesPanel; - wxPanel *_curPanel; - wxLocale *_locale; - bool _needReload; +private: + KissCount *_kiss; + wxBoxSizer *_hbox; + AccountPanel *_accountPanel; + StatsPanel *_statsPanel; + SearchPanel *_searchPanel; + PreferencesPanel *_preferencesPanel; + wxPanel *_curPanel; + wxLocale *_locale; + bool _needReload; }; #endif