Lot of user management code
This commit is contained in:
parent
e72e36f27d
commit
ceaf9a836e
@ -132,23 +132,45 @@ void KissCount::DeleteAccount(struct Account ac)
|
|||||||
|
|
||||||
wxString KissCount::AddCategory(struct category category)
|
wxString KissCount::AddCategory(struct category category)
|
||||||
{
|
{
|
||||||
return _db->AddCategory(_user, category);
|
wxString id;
|
||||||
|
id = _db->AddCategory(_user, category);
|
||||||
|
category.id = id;
|
||||||
|
|
||||||
|
_user->_preferences._categories.push_back(category);
|
||||||
|
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KissCount::UpdateCategory(wxString oldName, struct category category)
|
void KissCount::UpdateCategory(wxString oldName, struct category category)
|
||||||
{
|
{
|
||||||
wxString color;
|
wxString color;
|
||||||
|
std::vector<struct category>::iterator it;
|
||||||
|
|
||||||
color = _("#") ;
|
color = _("#") ;
|
||||||
color += wxString::Format(_("%02X"), category.color.Red());
|
color += wxString::Format(_("%02X"), category.color.Red());
|
||||||
color += wxString::Format(_("%02X"), category.color.Green());
|
color += wxString::Format(_("%02X"), category.color.Green());
|
||||||
color += wxString::Format(_("%02X"), category.color.Blue());
|
color += wxString::Format(_("%02X"), category.color.Blue());
|
||||||
|
|
||||||
_db->UpdateCategory(_user, oldName, category.name, color);
|
_db->UpdateCategory(_user, oldName, category.name, color);
|
||||||
|
|
||||||
|
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
|
||||||
|
if (_user->_preferences._categories[i].name == oldName)
|
||||||
|
{
|
||||||
|
_user->_preferences._categories[i] = category;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KissCount::DeleteCategory(struct category category)
|
void KissCount::DeleteCategory(struct category category)
|
||||||
{
|
{
|
||||||
_db->DeleteCategory(_user, category);
|
_db->DeleteCategory(_user, category);
|
||||||
|
|
||||||
|
for (int i=0; i<(int)_user->_preferences._categories.size();i++)
|
||||||
|
if (_user->_preferences._categories[i].name == category.name)
|
||||||
|
{
|
||||||
|
_user->_preferences._categories.erase(_user->_preferences._categories.begin()+i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, std::vector<int> > KissCount::GetAllOperations()
|
std::map<int, std::vector<int> > KissCount::GetAllOperations()
|
||||||
@ -184,3 +206,44 @@ void KissCount::GenerateMonth(int monthFrom, int yearFrom, int monthTo, int year
|
|||||||
}
|
}
|
||||||
_wxUI->GenerateMonth(monthTo, yearTo);
|
_wxUI->GenerateMonth(monthTo, yearTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KissCount::ChangePassword(wxString password)
|
||||||
|
{
|
||||||
|
_db->ChangePassword(_user, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KissCount::UserExists(wxString name)
|
||||||
|
{
|
||||||
|
return _db->UserExists(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KissCount::ChangeName(wxString name)
|
||||||
|
{
|
||||||
|
_db->ChangeName(_user, name);
|
||||||
|
_user->_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KissCount::NewUser(wxString name)
|
||||||
|
{
|
||||||
|
wxDateTime curDate;
|
||||||
|
struct Account ac = {_(""), _("Account 1"), _(""), false, true};
|
||||||
|
|
||||||
|
_db->NewUser(name);
|
||||||
|
if (_user) delete _user;
|
||||||
|
_user = _db->LoadUser(name) ;
|
||||||
|
|
||||||
|
curDate.SetToCurrent();
|
||||||
|
|
||||||
|
AddAccount(ac);
|
||||||
|
|
||||||
|
_db->GenerateMonth(_user, -1, -1, (int)curDate.GetMonth(), curDate.GetYear());
|
||||||
|
}
|
||||||
|
|
||||||
|
void KissCount::KillMe()
|
||||||
|
{
|
||||||
|
_wxUI->KillMe();
|
||||||
|
_db->KillMe(_user);
|
||||||
|
delete _user;
|
||||||
|
_user = NULL;
|
||||||
|
_wxUI->ChangeUser();
|
||||||
|
}
|
||||||
|
@ -19,6 +19,10 @@ class KissCount
|
|||||||
bool IsValidUser(wxString user, wxString password);
|
bool IsValidUser(wxString user, wxString password);
|
||||||
void LoadUser(wxString user);
|
void LoadUser(wxString user);
|
||||||
User* GetUser();
|
User* GetUser();
|
||||||
|
void ChangePassword(wxString password);
|
||||||
|
bool UserExists(wxString name);
|
||||||
|
void ChangeName(wxString name);
|
||||||
|
void NewUser(wxString name);
|
||||||
|
|
||||||
void LoadYear(int year, bool force=false);
|
void LoadYear(int year, bool force=false);
|
||||||
|
|
||||||
@ -40,6 +44,7 @@ class KissCount
|
|||||||
std::map<int, std::vector<int> > GetAllOperations();
|
std::map<int, std::vector<int> > GetAllOperations();
|
||||||
|
|
||||||
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
void GenerateMonth(int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||||
|
void KillMe();
|
||||||
private:
|
private:
|
||||||
wxUI* _wxUI;
|
wxUI* _wxUI;
|
||||||
Database* _db;
|
Database* _db;
|
||||||
|
@ -102,6 +102,23 @@ void Database::CreateDatabase()
|
|||||||
init_script.close();
|
init_script.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxString Database::HashPassword(wxString password)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
for(int i=0; i<20; i++)
|
||||||
|
wxSHA += wxString::Format(wxT("%02x"), (int)sha[i]);
|
||||||
|
|
||||||
|
return wxSHA;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<wxString> Database::GetUsers()
|
std::list<wxString> Database::GetUsers()
|
||||||
{
|
{
|
||||||
std::list<wxString> res;
|
std::list<wxString> res;
|
||||||
@ -124,18 +141,10 @@ std::list<wxString> Database::GetUsers()
|
|||||||
bool Database::IsValidUser(wxString user, wxString password)
|
bool Database::IsValidUser(wxString user, wxString password)
|
||||||
{
|
{
|
||||||
bool res;
|
bool res;
|
||||||
blk_SHA_CTX sha_ctx;
|
wxString req;
|
||||||
unsigned char sha[20];
|
|
||||||
wxString req, wxSHA;
|
|
||||||
wxSQLite3ResultSet set;
|
wxSQLite3ResultSet set;
|
||||||
|
|
||||||
blk_SHA1_Init(&sha_ctx);
|
req = _("SELECT name FROM user WHERE name='") + user + _("' AND password='") + HashPassword(password) + _("'");
|
||||||
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]);
|
|
||||||
req = _("SELECT name FROM user WHERE name='") + user + _("' AND password='") + wxSHA + _("'");
|
|
||||||
|
|
||||||
EXECUTE_SQL_QUERY(req, set, false);
|
EXECUTE_SQL_QUERY(req, set, false);
|
||||||
|
|
||||||
@ -454,6 +463,7 @@ wxString Database::AddAccount(User* user, struct Account ac)
|
|||||||
EXECUTE_SQL_UPDATE(req, _("0"));
|
EXECUTE_SQL_UPDATE(req, _("0"));
|
||||||
|
|
||||||
req = _("SELECT id FROM account WHERE name='") + ac.name + _("'") ;
|
req = _("SELECT id FROM account WHERE name='") + ac.name + _("'") ;
|
||||||
|
req += _("AND user='") + user->_id + _("'");
|
||||||
|
|
||||||
EXECUTE_SQL_QUERY(req , set, _("0"));
|
EXECUTE_SQL_QUERY(req , set, _("0"));
|
||||||
|
|
||||||
@ -701,3 +711,128 @@ void Database::GenerateMonth(User* user, int monthFrom, int yearFrom, int monthT
|
|||||||
EXECUTE_SQL_UPDATE(req, );
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::ChangePassword(User* user, wxString password)
|
||||||
|
{
|
||||||
|
wxString req;
|
||||||
|
|
||||||
|
req = _("UPDATE user SET ") ;
|
||||||
|
req += _("password='") + HashPassword(password) + _("'");
|
||||||
|
req += _(" WHERE name='") + user->_name + _("'");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Database::UserExists(wxString name)
|
||||||
|
{
|
||||||
|
wxSQLite3ResultSet set;
|
||||||
|
wxString req;
|
||||||
|
bool res=false;
|
||||||
|
|
||||||
|
req = _("SELECT name FROM user WHERE name='") + name + _("'") ;
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req , set, false);
|
||||||
|
|
||||||
|
if (set.NextRow())
|
||||||
|
res = true;
|
||||||
|
else
|
||||||
|
res = false;
|
||||||
|
|
||||||
|
set.Finalize();
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Database::ChangeName(User* user, wxString name)
|
||||||
|
{
|
||||||
|
wxString req;
|
||||||
|
|
||||||
|
req = _("UPDATE user SET ") ;
|
||||||
|
req += _("name='") + name + _("'");
|
||||||
|
req += _(" WHERE name='") + user->_name + _("'");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Database::NewUser(wxString name)
|
||||||
|
{
|
||||||
|
wxString req, id;
|
||||||
|
wxSQLite3ResultSet set;
|
||||||
|
|
||||||
|
req = _("INSERT INTO user ('name', 'password') VALUES ('") ;
|
||||||
|
req += name + _("'");
|
||||||
|
req += _(", '") + HashPassword(_("")) + _("'");
|
||||||
|
req += _(")");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
req = _("SELECT id FROM user WHERE ");
|
||||||
|
req += _("name='") + name + _("'");
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req , set, );
|
||||||
|
|
||||||
|
set.NextRow();
|
||||||
|
id = set.GetAsString(_("id"));
|
||||||
|
|
||||||
|
set.Finalize();
|
||||||
|
|
||||||
|
req = _("SELECT * FROM default_preference");
|
||||||
|
|
||||||
|
EXECUTE_SQL_QUERY(req, set,);
|
||||||
|
|
||||||
|
while (set.NextRow())
|
||||||
|
{
|
||||||
|
req = _("INSERT INTO preference ('user', 'type', 'name', 'value') VALUES ('") ;
|
||||||
|
req += id + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("type")) + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("name")) + _("'");
|
||||||
|
req += _(", '") + set.GetAsString(_("value")) + _("'");
|
||||||
|
req += _(")");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
set.Finalize();
|
||||||
|
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Database::KillMe(User* user)
|
||||||
|
{
|
||||||
|
wxString req;
|
||||||
|
std::vector<Account>::iterator it;
|
||||||
|
|
||||||
|
req = _("DELETE FROM preference WHERE user='") + user->_id + _("'");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
if (!user->_accounts.empty())
|
||||||
|
{
|
||||||
|
it = user->_accounts.begin();
|
||||||
|
req = _("DELETE FROM account_amount WHERE account IN('") + it->id;
|
||||||
|
it++;
|
||||||
|
for (;it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
req += _("', '") + it->id ;
|
||||||
|
}
|
||||||
|
req += _("')");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
it = user->_accounts.begin();
|
||||||
|
req = _("DELETE FROM operation WHERE account IN('") + it->id;
|
||||||
|
it++;
|
||||||
|
for (;it != user->_accounts.end(); it++)
|
||||||
|
{
|
||||||
|
req += _("', '") + it->id ;
|
||||||
|
}
|
||||||
|
req += _("')");
|
||||||
|
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
|
||||||
|
req = _("DELETE FROM account WHERE user='") + user->_id + _("'");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
|
||||||
|
req = _("DELETE FROM user WHERE id='") + user->_id + _("'");
|
||||||
|
EXECUTE_SQL_UPDATE(req, );
|
||||||
|
}
|
||||||
|
@ -42,10 +42,17 @@ class Database
|
|||||||
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
std::map<int, std::vector<int> > GetAllOperations(User* user);
|
||||||
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
void GenerateMonth(User* user, int monthFrom, int yearFrom, int monthTo, int yearTo);
|
||||||
|
|
||||||
|
void ChangePassword(User* user, wxString password);
|
||||||
|
bool UserExists(wxString name);
|
||||||
|
void ChangeName(User* user, wxString name);
|
||||||
|
void NewUser(wxString name);
|
||||||
|
|
||||||
|
void KillMe(User* user);
|
||||||
private:
|
private:
|
||||||
wxSQLite3Database _db;
|
wxSQLite3Database _db;
|
||||||
|
|
||||||
void CreateDatabase();
|
void CreateDatabase();
|
||||||
|
wxString HashPassword(wxString password);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,7 @@ struct category
|
|||||||
class Preferences
|
class Preferences
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<category> _categories;
|
std::vector<struct category> _categories;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,9 +15,10 @@ EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
|||||||
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
||||||
EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
|
EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
|
||||||
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
|
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
|
||||||
|
EVT_SHOW(AccountPanel::OnShow)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
|
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*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 *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||||
@ -110,9 +111,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|||||||
_accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value"));
|
_accountsGrid->SetColLabelValue(ACCOUNT_CUR, _("Current value"));
|
||||||
_accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value"));
|
_accountsGrid->SetColLabelValue(ACCOUNT_FINAL, _("Final value"));
|
||||||
|
|
||||||
_statsGrid = new wxGrid(this, -1);
|
_accountsGrid->AutoSizeColumns(true);
|
||||||
|
|
||||||
InitStatsGrid(user);
|
_statsGrid = new wxGrid(this, -1);
|
||||||
|
|
||||||
chart = new wxChartPanel(this);
|
chart = new wxChartPanel(this);
|
||||||
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
chart->SetChart(new Chart(_pie, _("Cost repartition")));
|
||||||
@ -158,7 +159,10 @@ void AccountPanel::InitStatsGrid(User* user)
|
|||||||
_statsGrid->EnableEditing(false);
|
_statsGrid->EnableEditing(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
|
{
|
||||||
|
_statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
|
||||||
|
_statsGrid->InsertRows(0, user->GetCategoriesNumber()+6);
|
||||||
|
}
|
||||||
|
|
||||||
_statsGrid->SetDefaultCellFont(font);
|
_statsGrid->SetDefaultCellFont(font);
|
||||||
|
|
||||||
@ -197,6 +201,8 @@ void AccountPanel::ChangeUser()
|
|||||||
wxDateTime curDate;
|
wxDateTime curDate;
|
||||||
wxTreeItemId rootNode, curNode;
|
wxTreeItemId rootNode, curNode;
|
||||||
|
|
||||||
|
InitStatsGrid(user);
|
||||||
|
|
||||||
_tree.DeleteAllItems();
|
_tree.DeleteAllItems();
|
||||||
rootNode = _tree.AddRoot(_(""));
|
rootNode = _tree.AddRoot(_(""));
|
||||||
|
|
||||||
@ -348,6 +354,8 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
|
|||||||
int r, g, b;
|
int r, g, b;
|
||||||
wxColour color;
|
wxColour color;
|
||||||
|
|
||||||
|
if (!op && !user->_accounts.size()) return;
|
||||||
|
|
||||||
_grid->InsertRows(line, 1);
|
_grid->InsertRows(line, 1);
|
||||||
|
|
||||||
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
|
||||||
@ -783,7 +791,6 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
|
|||||||
|
|
||||||
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
|
||||||
{
|
{
|
||||||
// ShowMonth(2010,4);
|
|
||||||
wxMenu menu(0);
|
wxMenu menu(0);
|
||||||
|
|
||||||
menu.Append(MENU_GENERATE_ID, _("Generate month"));
|
menu.Append(MENU_GENERATE_ID, _("Generate month"));
|
||||||
@ -914,6 +921,14 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
|
|||||||
|
|
||||||
GetTreeSelection(&month, &year);
|
GetTreeSelection(&month, &year);
|
||||||
|
|
||||||
|
ops = _kiss->GetAllOperations();
|
||||||
|
|
||||||
|
if (ops.size() == 1 && ops[year].size() == 1)
|
||||||
|
{
|
||||||
|
wxMessageBox(_("It must be at least one month"), _("Error"), wxICON_ERROR | wxOK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
message = _("Are you sure want to delete ");
|
message = _("Are you sure want to delete ");
|
||||||
if (month != -1)
|
if (month != -1)
|
||||||
message += months[month] + _(" ");
|
message += months[month] + _(" ");
|
||||||
@ -926,7 +941,6 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
curNode = _tree.GetSelection();
|
curNode = _tree.GetSelection();
|
||||||
ops = _kiss->GetAllOperations();
|
|
||||||
|
|
||||||
if (ops[year].size() == 1 && month != -1)
|
if (ops[year].size() == 1 && month != -1)
|
||||||
curNode = _tree.GetItemParent(curNode);
|
curNode = _tree.GetItemParent(curNode);
|
||||||
@ -1018,3 +1032,11 @@ void AccountPanel::GenerateMonth(int month, int year)
|
|||||||
_tree.SelectItem(node, true);
|
_tree.SelectItem(node, true);
|
||||||
ShowMonth(month, year);
|
ShowMonth(month, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccountPanel::OnShow(wxShowEvent& event)
|
||||||
|
{
|
||||||
|
if (_curMonth != -1)
|
||||||
|
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") + months[_curMonth] + _(" ") + wxString::Format(wxT("%d"), _curYear));
|
||||||
|
else
|
||||||
|
_wxUI->SetTitle(_kiss->GetUser()->_name);
|
||||||
|
}
|
||||||
|
@ -44,6 +44,9 @@ public:
|
|||||||
void OnTreeChange(wxTreeEvent& event);
|
void OnTreeChange(wxTreeEvent& event);
|
||||||
void OnMenuGenerate(wxCommandEvent& event);
|
void OnMenuGenerate(wxCommandEvent& event);
|
||||||
void OnMenuDelete(wxCommandEvent& event);
|
void OnMenuDelete(wxCommandEvent& event);
|
||||||
|
void OnShow(wxShowEvent& event);
|
||||||
|
|
||||||
|
int _curMonth, _curYear;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount* _kiss;
|
KissCount* _kiss;
|
||||||
@ -55,7 +58,6 @@ private:
|
|||||||
double *_categoriesValues;
|
double *_categoriesValues;
|
||||||
std::map<wxString, int> _categoriesIndexes;
|
std::map<wxString, int> _categoriesIndexes;
|
||||||
std::vector<operation>* _curOperations;
|
std::vector<operation>* _curOperations;
|
||||||
int _curMonth, _curYear;
|
|
||||||
wxString* _categories, *_accounts;
|
wxString* _categories, *_accounts;
|
||||||
std::map<wxString, double> _accountsInitValues;
|
std::map<wxString, double> _accountsInitValues;
|
||||||
CategorySimpleDataset* _dataset;
|
CategorySimpleDataset* _dataset;
|
||||||
|
@ -78,3 +78,12 @@ void CalendarEditor::OnCalendarChange(wxCommandEvent& event)
|
|||||||
_day = _calendar->GetDate().GetDay();
|
_day = _calendar->GetDate().GetDay();
|
||||||
//_calendar->Show(false);
|
//_calendar->Show(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CalendarEditor::StartingClick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,8 @@ public:
|
|||||||
void Show(bool show, wxGridCellAttr *attr=NULL);
|
void Show(bool show, wxGridCellAttr *attr=NULL);
|
||||||
void SetSize (const wxRect &rect);
|
void SetSize (const wxRect &rect);
|
||||||
void OnCalendarChange(wxCommandEvent& event);
|
void OnCalendarChange(wxCommandEvent& event);
|
||||||
|
void StartingClick();
|
||||||
|
bool IsAcceptedKey(wxKeyEvent &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int _day;
|
int _day;
|
||||||
|
@ -15,7 +15,8 @@ public:
|
|||||||
if (row == 0 || row == _fixCosts ||
|
if (row == 0 || row == _fixCosts ||
|
||||||
row == _week1 ||
|
row == _week1 ||
|
||||||
row == _week2 ||
|
row == _week2 ||
|
||||||
row == _week3)
|
row == _week3 ||
|
||||||
|
row == _week4)
|
||||||
return wxPen(*wxBLACK, 1, wxSOLID);
|
return wxPen(*wxBLACK, 1, wxSOLID);
|
||||||
|
|
||||||
return GetCellBackgroundColour(row, 0);
|
return GetCellBackgroundColour(row, 0);
|
||||||
@ -26,10 +27,11 @@ public:
|
|||||||
case 1: _week1 = line; break;
|
case 1: _week1 = line; break;
|
||||||
case 2: _week2 = line; break;
|
case 2: _week2 = line; break;
|
||||||
case 3: _week3 = line; break;
|
case 3: _week3 = line; break;
|
||||||
|
case 4: _week4 = line; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int _fixCosts;
|
int _fixCosts;
|
||||||
int _week1, _week2, _week3;
|
int _week1, _week2, _week3, _week4;
|
||||||
private:
|
private:
|
||||||
std::list<int> _col;
|
std::list<int> _col;
|
||||||
};
|
};
|
||||||
|
@ -3,11 +3,15 @@
|
|||||||
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT};
|
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT};
|
||||||
enum {CATEGORY_NAME, CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
|
enum {CATEGORY_NAME, CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
|
||||||
|
|
||||||
enum {CATEGORIES_GRID_ID=20, ACCOUNTS_GRID_ID};
|
enum {CATEGORIES_GRID_ID=20, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel)
|
BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel)
|
||||||
EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified)
|
EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName)
|
||||||
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified)
|
EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword)
|
||||||
|
EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe)
|
||||||
|
EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified)
|
||||||
|
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified)
|
||||||
|
EVT_SHOW(PreferencesPanel::OnShow)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent)
|
PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _kiss(kiss), _wxUI(parent)
|
||||||
@ -18,9 +22,8 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
|
|||||||
User* user = _kiss->GetUser();
|
User* user = _kiss->GetUser();
|
||||||
wxGridBagSizer *gridBagSizer;
|
wxGridBagSizer *gridBagSizer;
|
||||||
wxStaticText* label;
|
wxStaticText* label;
|
||||||
wxButton* buttonChangeName, *buttonChangePassword;
|
wxButton* buttonChangeName, *buttonChangePassword, *killMe;
|
||||||
wxStaticBoxSizer * staticBoxSizer;
|
wxStaticBoxSizer * staticBoxSizer;
|
||||||
wxTextCtrl* name;
|
|
||||||
|
|
||||||
SetSizer(vbox);
|
SetSizer(vbox);
|
||||||
|
|
||||||
@ -37,14 +40,16 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
|
|||||||
label = new wxStaticText(this, -1, _("Name"));
|
label = new wxStaticText(this, -1, _("Name"));
|
||||||
gridBagSizer->Add(label, wxGBPosition(0, 0));
|
gridBagSizer->Add(label, wxGBPosition(0, 0));
|
||||||
|
|
||||||
name = new wxTextCtrl(this, -1, user->_name);
|
_name = new wxTextCtrl(this, NAME_ID, user->_name);
|
||||||
gridBagSizer->Add(name, wxGBPosition(0, 1));
|
gridBagSizer->Add(_name, wxGBPosition(0, 1));
|
||||||
|
|
||||||
buttonChangeName = new wxButton(this, -1, _("Change Name"));
|
buttonChangeName = new wxButton(this, CHANGE_NAME_ID, _("Change Name"));
|
||||||
buttonChangePassword = new wxButton(this, -1, _("Change Password"));
|
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(buttonChangeName, wxGBPosition(1, 0));
|
||||||
gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1));
|
gridBagSizer->Add(buttonChangePassword, wxGBPosition(1, 1));
|
||||||
|
gridBagSizer->Add(killMe, wxGBPosition(1, 2));
|
||||||
|
|
||||||
vbox->Add(staticBoxSizer);
|
vbox->Add(staticBoxSizer);
|
||||||
vbox->Add(-1, 20);
|
vbox->Add(-1, 20);
|
||||||
@ -160,6 +165,7 @@ void PreferencesPanel::InitCategories(User* user)
|
|||||||
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, 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->SetReadOnly(0, CATEGORY_DELETE, true);
|
||||||
_categoriesGrid->AutoSizeColumns(true);
|
_categoriesGrid->AutoSizeColumns(true);
|
||||||
|
|
||||||
@ -253,6 +259,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
|
|||||||
|
|
||||||
_wxUI->Layout();
|
_wxUI->Layout();
|
||||||
inModification = false;
|
inModification = false;
|
||||||
|
_wxUI->NeedReload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_kiss->UpdateAccount(new_account);
|
_kiss->UpdateAccount(new_account);
|
||||||
@ -303,7 +310,8 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
|
|||||||
|
|
||||||
_kiss->AddAccount(new_account);
|
_kiss->AddAccount(new_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_wxUI->NeedReload();
|
||||||
inModification = false;
|
inModification = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,6 +356,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
_wxUI->Layout();
|
_wxUI->Layout();
|
||||||
|
_wxUI->NeedReload();
|
||||||
inModification = false;
|
inModification = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -390,5 +399,57 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
|
|||||||
_wxUI->Layout();
|
_wxUI->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_wxUI->NeedReload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreferencesPanel::OnChangeName(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
wxString name = _name->GetLineText(0);
|
||||||
|
|
||||||
|
if (name == user->_name)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!name.size())
|
||||||
|
{
|
||||||
|
wxMessageBox(_("Invalid name"), _("Error"), wxICON_ERROR | wxOK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_kiss->UserExists(name))
|
||||||
|
{
|
||||||
|
wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_kiss->ChangeName(name);
|
||||||
|
|
||||||
|
wxMessageBox(_("Name changed"), _("KissCount"), wxICON_INFORMATION | wxOK);
|
||||||
|
_wxUI->NeedReload();
|
||||||
|
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") +_("Preferences"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferencesPanel::OnChangePassword(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
PasswordDialog p(_kiss, _wxUI);
|
||||||
|
p.ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferencesPanel::OnShow(wxShowEvent& event)
|
||||||
|
{
|
||||||
|
_wxUI->SetTitle(_kiss->GetUser()->_name + _(" - ") +_("Preferences"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreferencesPanel::OnKillMe(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
User* user = _kiss->GetUser();
|
||||||
|
|
||||||
|
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete ")+user->_name+_(" account ?"), _("KissCount"), wxYES_NO);
|
||||||
|
if (dialog.ShowModal() == wxID_NO)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_kiss->KillMe();
|
||||||
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <controller/KissCount.h>
|
#include <controller/KissCount.h>
|
||||||
#include "wxUI.h"
|
#include "wxUI.h"
|
||||||
#include <model/model.h>
|
#include <model/model.h>
|
||||||
|
#include "PasswordDialog.h"
|
||||||
|
|
||||||
class wxUI;
|
class wxUI;
|
||||||
class KissCount;
|
class KissCount;
|
||||||
@ -24,12 +25,17 @@ public:
|
|||||||
|
|
||||||
void OnAccountModified(wxGridEvent& event);
|
void OnAccountModified(wxGridEvent& event);
|
||||||
void OnCategoryModified(wxGridEvent& event);
|
void OnCategoryModified(wxGridEvent& event);
|
||||||
|
void OnChangeName(wxCommandEvent& event);
|
||||||
|
void OnChangePassword(wxCommandEvent& event);
|
||||||
|
void OnShow(wxShowEvent& event);
|
||||||
|
void OnKillMe(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount* _kiss;
|
KissCount* _kiss;
|
||||||
wxUI* _wxUI;
|
wxUI* _wxUI;
|
||||||
wxGrid* _accountsGrid;
|
wxGrid* _accountsGrid;
|
||||||
wxGrid* _categoriesGrid;
|
wxGrid* _categoriesGrid;
|
||||||
|
wxTextCtrl* _name;
|
||||||
|
|
||||||
void InitAccounts(User* user);
|
void InitAccounts(User* user);
|
||||||
void InitCategories(User* user);
|
void InitCategories(User* user);
|
||||||
|
@ -1,54 +1,53 @@
|
|||||||
#include "UsersDialog.h"
|
#include "UsersDialog.h"
|
||||||
|
|
||||||
enum {ID_BUTTON_OK=1, ID_BUTTON_CANCEL};
|
enum {ID_BUTTON_OK=1, ID_BUTTON_CANCEL, ID_BUTTON_NEW_USER};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(UsersDialog, wxDialog)
|
BEGIN_EVENT_TABLE(UsersDialog, wxDialog)
|
||||||
EVT_BUTTON(ID_BUTTON_OK, UsersDialog::OnOK)
|
EVT_BUTTON(ID_BUTTON_OK, UsersDialog::OnOK)
|
||||||
EVT_BUTTON(ID_BUTTON_CANCEL, UsersDialog::OnCancel)
|
EVT_BUTTON(ID_BUTTON_CANCEL, UsersDialog::OnCancel)
|
||||||
|
EVT_BUTTON(ID_BUTTON_NEW_USER, UsersDialog::OnNewUser)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent)
|
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent)
|
||||||
{
|
{
|
||||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
wxGridBagSizer *gridBagSizer;
|
||||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
wxStaticText* label;
|
||||||
wxBoxSizer *vbox1 = new wxBoxSizer(wxVERTICAL);
|
|
||||||
wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
|
|
||||||
|
|
||||||
_users = new wxChoice(this, wxID_ANY);
|
gridBagSizer = new wxGridBagSizer(4, 4);
|
||||||
_password = new wxTextCtrl(this, wxID_ANY);
|
|
||||||
|
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));
|
||||||
|
|
||||||
_password->SetWindowStyle(wxTE_PASSWORD);
|
_password->SetWindowStyle(wxTE_PASSWORD);
|
||||||
|
|
||||||
wxButton* ok = new wxButton(this, ID_BUTTON_OK, _("OK"));
|
wxButton* ok = new wxButton(this, ID_BUTTON_OK, _("OK"));
|
||||||
wxButton* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel"));
|
wxButton* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel"));
|
||||||
|
wxButton* newUser = new wxButton(this, ID_BUTTON_NEW_USER, _("New User"));
|
||||||
|
gridBagSizer->Add(ok, wxGBPosition(3, 1));
|
||||||
|
gridBagSizer->Add(cancel, wxGBPosition(3, 2));
|
||||||
|
gridBagSizer->Add(newUser, wxGBPosition(3, 3));
|
||||||
|
|
||||||
std::list<wxString> users_list = _kiss->GetUsers();
|
std::list<wxString> users_list = _kiss->GetUsers();
|
||||||
|
|
||||||
|
for(std::list<wxString>::iterator i = users_list.begin(); i != users_list.end(); i++)
|
||||||
|
{
|
||||||
|
_users->Append(*i);
|
||||||
|
}
|
||||||
|
|
||||||
for(std::list<wxString>::iterator i = users_list.begin(); i != users_list.end(); i++)
|
_users->Select(0);
|
||||||
{
|
|
||||||
_users->Append(*i);
|
|
||||||
}
|
|
||||||
|
|
||||||
_users->Select(0);
|
SetSizer(gridBagSizer);
|
||||||
|
|
||||||
vbox1->Add(_users);
|
_users->SetFocus();
|
||||||
vbox1->Add(-1, 10);
|
Layout();
|
||||||
vbox1->Add(_password);
|
Center();
|
||||||
hbox->Add(vbox1, 0, wxEXPAND, 10);
|
|
||||||
|
|
||||||
hbox1->Add(ok);
|
|
||||||
hbox1->Add(-1, 10);
|
|
||||||
hbox1->Add(cancel);
|
|
||||||
|
|
||||||
vbox->Add(hbox, 0, wxALIGN_RIGHT | wxRIGHT | wxTOP, 10);
|
|
||||||
vbox->Add(-1, 40);
|
|
||||||
vbox->Add(hbox1, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
|
|
||||||
|
|
||||||
SetSizer(vbox);
|
|
||||||
|
|
||||||
_users->SetFocus();
|
|
||||||
Layout();
|
|
||||||
Center();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UsersDialog::OnOK(wxCommandEvent& event)
|
void UsersDialog::OnOK(wxCommandEvent& event)
|
||||||
@ -56,12 +55,12 @@ void UsersDialog::OnOK(wxCommandEvent& event)
|
|||||||
// No users in database
|
// No users in database
|
||||||
if (!_users->GetStringSelection().Length())
|
if (!_users->GetStringSelection().Length())
|
||||||
{
|
{
|
||||||
Close();
|
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
|
||||||
{
|
{
|
||||||
@ -74,3 +73,27 @@ void UsersDialog::OnCancel(wxCommandEvent& event)
|
|||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UsersDialog::OnNewUser(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
wxString name;
|
||||||
|
wxTextEntryDialog u(this, _(""), _("New User"));
|
||||||
|
|
||||||
|
if (u.ShowModal() == wxID_CANCEL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
name = u.GetValue();
|
||||||
|
|
||||||
|
if (!name.size()) return;
|
||||||
|
|
||||||
|
if (_kiss->UserExists(name))
|
||||||
|
{
|
||||||
|
wxMessageBox(_("User ") + name + _(" already exists"), _("Error"), wxICON_ERROR | wxOK);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_kiss->NewUser(name);
|
||||||
|
_kiss->LoadUser(name);
|
||||||
|
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include <wx/choice.h>
|
#include <wx/choice.h>
|
||||||
#include <wx/textctrl.h>
|
#include <wx/textctrl.h>
|
||||||
|
#include <wx/textdlg.h>
|
||||||
#include <controller/KissCount.h>
|
#include <controller/KissCount.h>
|
||||||
#include "wxUI.h"
|
#include "wxUI.h"
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ public:
|
|||||||
|
|
||||||
void OnOK(wxCommandEvent& event);
|
void OnOK(wxCommandEvent& event);
|
||||||
void OnCancel(wxCommandEvent& event);
|
void OnCancel(wxCommandEvent& event);
|
||||||
|
void OnNewUser(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount* _kiss;
|
KissCount* _kiss;
|
||||||
|
@ -8,7 +8,8 @@ END_EVENT_TABLE()
|
|||||||
wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ;
|
wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ;
|
||||||
|
|
||||||
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
|
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL)
|
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL),
|
||||||
|
_needReload(false)
|
||||||
{
|
{
|
||||||
_hbox = new wxBoxSizer(wxVERTICAL);
|
_hbox = new wxBoxSizer(wxVERTICAL);
|
||||||
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
|
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
|
||||||
@ -80,14 +81,16 @@ void wxUI::LoadUser()
|
|||||||
if (_preferencesPanel)
|
if (_preferencesPanel)
|
||||||
delete _preferencesPanel;
|
delete _preferencesPanel;
|
||||||
|
|
||||||
_accountPanel = new AccountPanel(_kiss, this);
|
|
||||||
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
_preferencesPanel = new PreferencesPanel(_kiss, this);
|
||||||
|
_accountPanel = new AccountPanel(_kiss, this);
|
||||||
|
|
||||||
ShowPanel(_accountPanel);
|
ShowPanel(_accountPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxUI::ShowPanel(wxPanel* panel)
|
void wxUI::ShowPanel(wxPanel* panel)
|
||||||
{
|
{
|
||||||
|
int month, year;
|
||||||
|
|
||||||
if (!panel) return;
|
if (!panel) return;
|
||||||
|
|
||||||
if (_curPanel)
|
if (_curPanel)
|
||||||
@ -96,6 +99,16 @@ void wxUI::ShowPanel(wxPanel* panel)
|
|||||||
_curPanel->Hide();
|
_curPanel->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (panel == _accountPanel && _needReload)
|
||||||
|
{
|
||||||
|
month = _accountPanel->_curMonth;
|
||||||
|
year = _accountPanel->_curYear;
|
||||||
|
delete _accountPanel;
|
||||||
|
panel = _accountPanel = new AccountPanel(_kiss, this);
|
||||||
|
_accountPanel->ShowMonth(month, year);
|
||||||
|
_needReload = false;
|
||||||
|
}
|
||||||
|
|
||||||
_curPanel = panel;
|
_curPanel = panel;
|
||||||
_hbox->Add(panel);
|
_hbox->Add(panel);
|
||||||
_curPanel->Show();
|
_curPanel->Show();
|
||||||
@ -106,3 +119,26 @@ void wxUI::GenerateMonth(int month, int year)
|
|||||||
{
|
{
|
||||||
_accountPanel->GenerateMonth(month, year);
|
_accountPanel->GenerateMonth(month, year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxUI::KillMe()
|
||||||
|
{
|
||||||
|
if (_curPanel)
|
||||||
|
{
|
||||||
|
_hbox->Detach(_curPanel);
|
||||||
|
_curPanel = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_accountPanel)
|
||||||
|
delete _accountPanel;
|
||||||
|
|
||||||
|
if (_preferencesPanel)
|
||||||
|
delete _preferencesPanel;
|
||||||
|
|
||||||
|
_accountPanel = NULL;
|
||||||
|
_preferencesPanel = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxUI::NeedReload()
|
||||||
|
{
|
||||||
|
_needReload = true;
|
||||||
|
}
|
||||||
|
@ -32,13 +32,17 @@ public:
|
|||||||
void ShowPreferences();
|
void ShowPreferences();
|
||||||
void GenerateMonth(int month, int year);
|
void GenerateMonth(int month, int year);
|
||||||
|
|
||||||
|
void KillMe();
|
||||||
|
|
||||||
|
void NeedReload();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KissCount *_kiss;
|
KissCount *_kiss;
|
||||||
wxBoxSizer *_hbox;
|
wxBoxSizer *_hbox;
|
||||||
AccountPanel *_accountPanel;
|
AccountPanel *_accountPanel;
|
||||||
PreferencesPanel *_preferencesPanel;
|
PreferencesPanel *_preferencesPanel;
|
||||||
wxPanel *_curPanel;
|
wxPanel *_curPanel;
|
||||||
|
bool _needReload;
|
||||||
void ShowPanel(wxPanel* panel);
|
void ShowPanel(wxPanel* panel);
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user