KissCount/view/UsersDialog.cpp

77 lines
1.9 KiB
C++
Raw Normal View History

#include "UsersDialog.h"
enum {ID_BUTTON_OK=1, ID_BUTTON_CANCEL};
BEGIN_EVENT_TABLE(UsersDialog, wxDialog)
EVT_BUTTON(ID_BUTTON_OK, UsersDialog::OnOK)
EVT_BUTTON(ID_BUTTON_CANCEL, UsersDialog::OnCancel)
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);
_users = new wxChoice(this, wxID_ANY);
_password = new wxTextCtrl(this, wxID_ANY);
_password->SetWindowStyle(wxTE_PASSWORD);
wxButton* ok = new wxButton(this, ID_BUTTON_OK, _("OK"));
wxButton* cancel = new wxButton(this, ID_BUTTON_CANCEL, _("Cancel"));
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-05-15 11:21:42 +02:00
_users->Select(0);
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);
Center();
SetSizer(vbox);
2010-05-16 10:35:34 +02:00
_users->SetFocus();
Layout();
}
void UsersDialog::OnOK(wxCommandEvent& event)
{
// No users in database
if (!_users->GetStringSelection().Length())
{
Close();
}
if (!_kiss->IsValidUser(_users->GetStringSelection(), _password->GetLineText(0)))
{
wxMessageBox(_("Invalid password"), _("Error"), wxICON_ERROR | wxOK );
}
else
{
_kiss->LoadUser(_users->GetStringSelection());
Close();
}
}
void UsersDialog::OnCancel(wxCommandEvent& event)
{
Close();
}