summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-24 13:05:27 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-24 13:05:27 +0000
commitb5a95c2e1151ce61a2615cffcbb6821c150f40fd (patch)
treedaca526b12ba0d9f761af3d65d033719ea50c8d3 /src/gui
parentd5e8513e085b6fc8da2ea4bb7151ac8e98be74c8 (diff)
downloadmana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.gz
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.bz2
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.tar.xz
mana-b5a95c2e1151ce61a2615cffcbb6821c150f40fd.zip
Make sure that when a network error occurs, the error message is available and
shown to the user. Also, only enable Register button when all necessary fields are filled in.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/login.cpp2
-rw-r--r--src/gui/login.h2
-rw-r--r--src/gui/register.cpp25
-rw-r--r--src/gui/register.h17
4 files changed, 40 insertions, 6 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 4e4c5b34..2c13f204 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -148,7 +148,7 @@ LoginDialog::action(const gcn::ActionEvent &event)
}
void
-LoginDialog::keyPressed(gcn::KeyEvent& keyEvent)
+LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
mOkButton->setEnabled(canSubmit());
}
diff --git a/src/gui/login.h b/src/gui/login.h
index 981665d5..e08120cb 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -62,7 +62,7 @@ class LoginDialog : public Window, public gcn::ActionListener,
/**
* Called when a key is pressed in one of the text fields.
*/
- void keyPressed(gcn::KeyEvent& keyEvent);
+ void keyPressed(gcn::KeyEvent &keyEvent);
private:
/**
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
index ad3a6388..b42a7af8 100644
--- a/src/gui/register.cpp
+++ b/src/gui/register.cpp
@@ -108,6 +108,11 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
mCancelButton->getX() - mRegisterButton->getWidth() - 5,
height - mRegisterButton->getHeight() - 5);
+ mUserField->addKeyListener(this);
+ mPasswordField->addKeyListener(this);
+ mConfirmField->addKeyListener(this);
+ mServerField->addKeyListener(this);
+
/* TODO:
* This is a quick and dirty way to respond to the ENTER key, regardless of
* which text field is selected. There may be a better way now with the new
@@ -139,6 +144,8 @@ RegisterDialog::RegisterDialog(LoginData *loginData):
setVisible(true);
mUserField->requestFocus();
mUserField->setCaretPosition(mUserField->getText().length());
+
+ mRegisterButton->setEnabled(canSubmit());
}
RegisterDialog::~RegisterDialog()
@@ -153,7 +160,7 @@ RegisterDialog::action(const gcn::ActionEvent &event)
{
state = LOGIN_STATE;
}
- else if (event.getId() == "register")
+ else if (event.getId() == "register" && canSubmit())
{
const std::string user = mUserField->getText();
logger->log("RegisterDialog::register Username is %s", user.c_str());
@@ -235,3 +242,19 @@ RegisterDialog::action(const gcn::ActionEvent &event)
}
}
}
+
+void
+RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
+{
+ mRegisterButton->setEnabled(canSubmit());
+}
+
+bool
+RegisterDialog::canSubmit()
+{
+ return !mUserField->getText().empty() &&
+ !mPasswordField->getText().empty() &&
+ !mConfirmField->getText().empty() &&
+ !mServerField->getText().empty() &&
+ state == REGISTER_STATE;
+}
diff --git a/src/gui/register.h b/src/gui/register.h
index 6b23c97f..a80594af 100644
--- a/src/gui/register.h
+++ b/src/gui/register.h
@@ -26,6 +26,7 @@
#include <iosfwd>
#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
#include "window.h"
#include "../guichanfwd.h"
@@ -51,7 +52,8 @@ class WrongDataNoticeListener : public gcn::ActionListener {
*
* \ingroup Interface
*/
-class RegisterDialog : public Window, public gcn::ActionListener
+class RegisterDialog : public Window, public gcn::ActionListener,
+ public gcn::KeyListener
{
public:
/**
@@ -72,10 +74,19 @@ class RegisterDialog : public Window, public gcn::ActionListener
*/
void action(const gcn::ActionEvent &event);
- // Made them public to have the possibility to request focus
- // from external functions.
+ /**
+ * Called when a key is pressed in one of the text fields.
+ */
+ void keyPressed(gcn::KeyEvent &keyEvent);
private:
+ /**
+ * Returns whether submit can be enabled. This is true in the register
+ * state, when all necessary fields have some text.
+ */
+ bool
+ canSubmit();
+
gcn::TextField *mUserField;
gcn::TextField *mPasswordField;
gcn::TextField *mConfirmField;