KissCount/view/UsersDialog.cpp

100 lines
2.5 KiB
C++
Raw Normal View History

#include "UsersDialog.h"
2010-06-27 21:39:49 +02:00
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)
2010-06-27 21:39:49 +02:00
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)
{
2010-06-27 21:39:49 +02:00
wxGridBagSizer *gridBagSizer;
wxStaticText* label;
2010-06-27 21:39:49 +02:00
gridBagSizer = new wxGridBagSizer(4, 4);
2010-05-15 11:21:42 +02:00
2010-06-27 21:39:49 +02:00
label = new wxStaticText(this, -1, _("User "));
gridBagSizer->Add(label, wxGBPosition(0, 0));
_users = new wxChoice(this, wxID_ANY);
gridBagSizer->Add(_users, wxGBPosition(0, 1));
2010-06-27 21:39:49 +02:00
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);
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();
for(std::list<wxString>::iterator i = users_list.begin(); i != users_list.end(); i++)
{
_users->Append(*i);
}
2010-06-27 21:39:49 +02:00
_users->Select(0);
2010-06-27 21:39:49 +02:00
SetSizer(gridBagSizer);
2010-06-27 21:39:49 +02:00
_users->SetFocus();
Layout();
Center();
}
void UsersDialog::OnOK(wxCommandEvent& event)
{
// No users in database
if (!_users->GetStringSelection().Length())
{
2010-06-27 21:39:49 +02:00
return;
}
if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0)))
{
2010-06-27 21:39:49 +02:00
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK);
}
else
{
_kiss->LoadUser(_users->GetStringSelection());
Close();
}
}
void UsersDialog::OnCancel(wxCommandEvent& event)
{
Close();
}
2010-06-27 21:39:49 +02:00
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();
}