diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-22 00:47:41 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-22 00:47:41 +0000 |
commit | cacb143040c018a24aed00c3ce1f513b75ec7f99 (patch) | |
tree | 22afb23dc50f2bad06abb0730f88745b09ff654a /src/gui/login.cpp | |
parent | 823aa330987205b251d9f662cfdd4c39149c6ec7 (diff) | |
download | mana-cacb143040c018a24aed00c3ce1f513b75ec7f99.tar.gz mana-cacb143040c018a24aed00c3ce1f513b75ec7f99.tar.bz2 mana-cacb143040c018a24aed00c3ce1f513b75ec7f99.tar.xz mana-cacb143040c018a24aed00c3ce1f513b75ec7f99.zip |
Only enable login button when a username, password and server are filled in.
Pass username, password and server on to the register dialog. Go back to login
dialog when canceling registration. Fixed a crash caused by deleting an
OkDialog twice (it also deletes itself). Made the register dialog a bit wider.
Register dialog no longer clears username field when it is invalid.
Diffstat (limited to 'src/gui/login.cpp')
-rw-r--r-- | src/gui/login.cpp | 75 |
1 files changed, 34 insertions, 41 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 27623442..00b99e72 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -36,24 +36,6 @@ #include "passwordfield.h" #include "textfield.h" -void -WrongDataNoticeListener::setTarget(gcn::TextField *textField) -{ - mTarget = textField; -} - -void -WrongDataNoticeListener::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "ok") - { - // Reset the field - mTarget->setText(""); - mTarget->setCaretPosition(0); - mTarget->requestFocus(); - } -} - LoginDialog::LoginDialog(LoginData *loginData): Window("Login"), mLoginData(loginData) { @@ -99,6 +81,9 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->setActionEventId("ok"); mServerField->setActionEventId("ok"); + mUserField->addKeyListener(this); + mPassField->addKeyListener(this); + mServerField->addKeyListener(this); mUserField->addActionListener(this); mPassField->addActionListener(this); mServerField->addActionListener(this); @@ -124,39 +109,27 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->requestFocus(); } - mWrongDataNoticeListener = new WrongDataNoticeListener(); + mOkButton->setEnabled(canSubmit()); } LoginDialog::~LoginDialog() { - delete mWrongDataNoticeListener; } void LoginDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "ok") + if (event.getId() == "ok" && canSubmit()) { - // Check login - if (mUserField->getText().empty()) - { - mWrongDataNoticeListener->setTarget(mPassField); - OkDialog *dlg = new OkDialog("Error", "Enter your username first"); - dlg->addActionListener(mWrongDataNoticeListener); - } - else - { - mLoginData->hostname = mServerField->getText(); - mLoginData->username = mUserField->getText(); - mLoginData->password = mPassField->getText(); - mLoginData->remember = mKeepCheck->isMarked(); - - mOkButton->setEnabled(false); - //mCancelButton->setEnabled(false); - mRegisterButton->setEnabled(false); - - state = ACCOUNT_STATE; - } + mLoginData->hostname = mServerField->getText(); + mLoginData->username = mUserField->getText(); + mLoginData->password = mPassField->getText(); + mLoginData->remember = mKeepCheck->isMarked(); + + mOkButton->setEnabled(false); + mRegisterButton->setEnabled(false); + + state = ACCOUNT_STATE; } else if (event.getId() == "cancel") { @@ -164,6 +137,26 @@ LoginDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "register") { + // Transfer these fields on to the register dialog + mLoginData->hostname = mServerField->getText(); + mLoginData->username = mUserField->getText(); + mLoginData->password = mPassField->getText(); + state = REGISTER_STATE; } } + +void +LoginDialog::keyPressed(gcn::KeyEvent& keyEvent) +{ + mOkButton->setEnabled(canSubmit()); +} + +bool +LoginDialog::canSubmit() +{ + return !mUserField->getText().empty() && + !mPassField->getText().empty() && + !mServerField->getText().empty() && + state == LOGIN_STATE; +} |