Lot of user management code

This commit is contained in:
2010-06-27 21:39:49 +02:00
parent e72e36f27d
commit ceaf9a836e
16 changed files with 449 additions and 70 deletions

View File

@@ -15,9 +15,10 @@ EVT_TREE_SEL_CHANGED(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
EVT_SHOW(AccountPanel::OnShow)
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 *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_FINAL, _("Final value"));
_statsGrid = new wxGrid(this, -1);
_accountsGrid->AutoSizeColumns(true);
InitStatsGrid(user);
_statsGrid = new wxGrid(this, -1);
chart = new wxChartPanel(this);
chart->SetChart(new Chart(_pie, _("Cost repartition")));
@@ -158,7 +159,10 @@ void AccountPanel::InitStatsGrid(User* user)
_statsGrid->EnableEditing(false);
}
else
_statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
{
_statsGrid->DeleteRows(0, _statsGrid->GetNumberRows());
_statsGrid->InsertRows(0, user->GetCategoriesNumber()+6);
}
_statsGrid->SetDefaultCellFont(font);
@@ -197,6 +201,8 @@ void AccountPanel::ChangeUser()
wxDateTime curDate;
wxTreeItemId rootNode, curNode;
InitStatsGrid(user);
_tree.DeleteAllItems();
rootNode = _tree.AddRoot(_(""));
@@ -348,6 +354,8 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
int r, g, b;
wxColour color;
if (!op && !user->_accounts.size()) return;
_grid->InsertRows(line, 1);
_grid->SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(-1, 2));
@@ -783,7 +791,6 @@ void AccountPanel::OnAccountModified(wxGridEvent& event)
void AccountPanel::OnTreeRightClick(wxTreeEvent& event)
{
// ShowMonth(2010,4);
wxMenu menu(0);
menu.Append(MENU_GENERATE_ID, _("Generate month"));
@@ -914,6 +921,14 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
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 ");
if (month != -1)
message += months[month] + _(" ");
@@ -926,7 +941,6 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event)
return;
curNode = _tree.GetSelection();
ops = _kiss->GetAllOperations();
if (ops[year].size() == 1 && month != -1)
curNode = _tree.GetItemParent(curNode);
@@ -1018,3 +1032,11 @@ void AccountPanel::GenerateMonth(int month, int year)
_tree.SelectItem(node, true);
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);
}

View File

@@ -44,6 +44,9 @@ public:
void OnTreeChange(wxTreeEvent& event);
void OnMenuGenerate(wxCommandEvent& event);
void OnMenuDelete(wxCommandEvent& event);
void OnShow(wxShowEvent& event);
int _curMonth, _curYear;
private:
KissCount* _kiss;
@@ -55,7 +58,6 @@ private:
double *_categoriesValues;
std::map<wxString, int> _categoriesIndexes;
std::vector<operation>* _curOperations;
int _curMonth, _curYear;
wxString* _categories, *_accounts;
std::map<wxString, double> _accountsInitValues;
CategorySimpleDataset* _dataset;

View File

@@ -78,3 +78,12 @@ void CalendarEditor::OnCalendarChange(wxCommandEvent& event)
_day = _calendar->GetDate().GetDay();
//_calendar->Show(false);
}
void CalendarEditor::StartingClick()
{
}
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
{
return true;
}

View File

@@ -24,6 +24,8 @@ public:
void Show(bool show, wxGridCellAttr *attr=NULL);
void SetSize (const wxRect &rect);
void OnCalendarChange(wxCommandEvent& event);
void StartingClick();
bool IsAcceptedKey(wxKeyEvent &event);
private:
int _day;

View File

@@ -15,7 +15,8 @@ public:
if (row == 0 || row == _fixCosts ||
row == _week1 ||
row == _week2 ||
row == _week3)
row == _week3 ||
row == _week4)
return wxPen(*wxBLACK, 1, wxSOLID);
return GetCellBackgroundColour(row, 0);
@@ -26,10 +27,11 @@ public:
case 1: _week1 = line; break;
case 2: _week2 = line; break;
case 3: _week3 = line; break;
case 4: _week4 = line; break;
}
}
int _fixCosts;
int _week1, _week2, _week3;
int _week1, _week2, _week3, _week4;
private:
std::list<int> _col;
};

View File

@@ -3,11 +3,15 @@
enum {ACCOUNT_NAME, ACCOUNT_NUMBER, ACCOUNT_SHARED, ACCOUNT_DEFAULT, ACCOUNT_DELETE, NUMBER_COLS_ACCOUNT};
enum {CATEGORY_NAME, CATEGORY_COLOR, CATEGORY_FONT, CATEGORY_DELETE, NUMBER_COLS_CATEGORY};
enum {CATEGORIES_GRID_ID=20, ACCOUNTS_GRID_ID};
enum {CATEGORIES_GRID_ID=20, ACCOUNTS_GRID_ID, NAME_ID, CHANGE_NAME_ID, CHANGE_PASSWORD_ID, KILL_ME_ID};
BEGIN_EVENT_TABLE(PreferencesPanel, wxPanel)
EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified)
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified)
EVT_BUTTON(CHANGE_NAME_ID, PreferencesPanel::OnChangeName)
EVT_BUTTON(CHANGE_PASSWORD_ID, PreferencesPanel::OnChangePassword)
EVT_BUTTON(KILL_ME_ID, PreferencesPanel::OnKillMe)
EVT_GRID_CMD_CELL_CHANGE(CATEGORIES_GRID_ID, PreferencesPanel::OnCategoryModified)
EVT_GRID_CMD_CELL_CHANGE(ACCOUNTS_GRID_ID, PreferencesPanel::OnAccountModified)
EVT_SHOW(PreferencesPanel::OnShow)
END_EVENT_TABLE()
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();
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
wxButton* buttonChangeName, *buttonChangePassword;
wxButton* buttonChangeName, *buttonChangePassword, *killMe;
wxStaticBoxSizer * staticBoxSizer;
wxTextCtrl* name;
SetSizer(vbox);
@@ -37,14 +40,16 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*p
label = new wxStaticText(this, -1, _("Name"));
gridBagSizer->Add(label, wxGBPosition(0, 0));
name = new wxTextCtrl(this, -1, 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, -1, _("Change Name"));
buttonChangePassword = new wxButton(this, -1, _("Change Password"));
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));
vbox->Add(staticBoxSizer);
vbox->Add(-1, 20);
@@ -160,6 +165,7 @@ void PreferencesPanel::InitCategories(User* user)
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
}
_categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true);
_categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true);
_categoriesGrid->AutoSizeColumns(true);
@@ -253,6 +259,7 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
_wxUI->Layout();
inModification = false;
_wxUI->NeedReload();
return;
}
_kiss->UpdateAccount(new_account);
@@ -303,7 +310,8 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
_kiss->AddAccount(new_account);
}
_wxUI->NeedReload();
inModification = false;
}
@@ -348,6 +356,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
}
_wxUI->Layout();
_wxUI->NeedReload();
inModification = false;
return;
}
@@ -390,5 +399,57 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
_wxUI->Layout();
}
_wxUI->NeedReload();
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();
}

View File

@@ -12,6 +12,7 @@
#include <controller/KissCount.h>
#include "wxUI.h"
#include <model/model.h>
#include "PasswordDialog.h"
class wxUI;
class KissCount;
@@ -24,12 +25,17 @@ public:
void OnAccountModified(wxGridEvent& event);
void OnCategoryModified(wxGridEvent& event);
void OnChangeName(wxCommandEvent& event);
void OnChangePassword(wxCommandEvent& event);
void OnShow(wxShowEvent& event);
void OnKillMe(wxCommandEvent& event);
private:
KissCount* _kiss;
wxUI* _wxUI;
wxGrid* _accountsGrid;
wxGrid* _categoriesGrid;
wxTextCtrl* _name;
void InitAccounts(User* user);
void InitCategories(User* user);

View File

@@ -1,54 +1,53 @@
#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)
EVT_BUTTON(ID_BUTTON_OK, UsersDialog::OnOK)
EVT_BUTTON(ID_BUTTON_CANCEL, UsersDialog::OnCancel)
EVT_BUTTON(ID_BUTTON_NEW_USER, UsersDialog::OnNewUser)
END_EVENT_TABLE()
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : wxDialog(&(*parent), -1, _("Users")), _kiss(kiss), _wxUI(parent)
{
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *vbox1 = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *hbox1 = new wxBoxSizer(wxHORIZONTAL);
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
_users = new wxChoice(this, wxID_ANY);
_password = new wxTextCtrl(this, wxID_ANY);
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, _("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* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel"));
wxButton* ok = new wxButton(this, ID_BUTTON_OK, _("OK"));
wxButton* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel"));
wxButton* newUser = new wxButton(this, ID_BUTTON_NEW_USER, _("New User"));
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->Append(*i);
}
_users->Select(0);
_users->Select(0);
SetSizer(gridBagSizer);
vbox1->Add(_users);
vbox1->Add(-1, 10);
vbox1->Add(_password);
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();
_users->SetFocus();
Layout();
Center();
}
void UsersDialog::OnOK(wxCommandEvent& event)
@@ -56,12 +55,12 @@ void UsersDialog::OnOK(wxCommandEvent& event)
// No users in database
if (!_users->GetStringSelection().Length())
{
Close();
return;
}
if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0)))
{
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK );
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK);
}
else
{
@@ -74,3 +73,27 @@ void UsersDialog::OnCancel(wxCommandEvent& event)
{
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();
}

View File

@@ -6,6 +6,7 @@
#include <wx/wx.h>
#include <wx/choice.h>
#include <wx/textctrl.h>
#include <wx/textdlg.h>
#include <controller/KissCount.h>
#include "wxUI.h"
@@ -19,6 +20,7 @@ public:
void OnOK(wxCommandEvent& event);
void OnCancel(wxCommandEvent& event);
void OnNewUser(wxCommandEvent& event);
private:
KissCount* _kiss;

View File

@@ -8,7 +8,8 @@ END_EVENT_TABLE()
wxString months[12] = {_("january"), _("february"), _("march"), _("april"), _("may"), _("june"), _("july"), _("august"), _("september"), _("october"), _("november"), _("december")} ;
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL)
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss), _accountPanel(NULL), _preferencesPanel(NULL), _curPanel(NULL),
_needReload(false)
{
_hbox = new wxBoxSizer(wxVERTICAL);
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
@@ -80,14 +81,16 @@ void wxUI::LoadUser()
if (_preferencesPanel)
delete _preferencesPanel;
_accountPanel = new AccountPanel(_kiss, this);
_preferencesPanel = new PreferencesPanel(_kiss, this);
_accountPanel = new AccountPanel(_kiss, this);
ShowPanel(_accountPanel);
}
void wxUI::ShowPanel(wxPanel* panel)
{
int month, year;
if (!panel) return;
if (_curPanel)
@@ -96,6 +99,16 @@ void wxUI::ShowPanel(wxPanel* panel)
_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;
_hbox->Add(panel);
_curPanel->Show();
@@ -106,3 +119,26 @@ void wxUI::GenerateMonth(int month, int 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;
}

View File

@@ -32,13 +32,17 @@ public:
void ShowPreferences();
void GenerateMonth(int month, int year);
void KillMe();
void NeedReload();
private:
KissCount *_kiss;
wxBoxSizer *_hbox;
AccountPanel *_accountPanel;
PreferencesPanel *_preferencesPanel;
wxPanel *_curPanel;
bool _needReload;
void ShowPanel(wxPanel* panel);
DECLARE_EVENT_TABLE();