From cc7e9dc6e6f7a006db7417fd9b7d93d587e27529 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Sat, 19 May 2012 20:35:47 +0300
Subject: Rename register.cpp/h files to registerdialog.cpp/h

---
 src/CMakeLists.txt                  |   4 +-
 src/Makefile.am                     |   4 +-
 src/client.cpp                      |   2 +-
 src/gui/changeemaildialog.cpp       |   2 +-
 src/gui/changepassworddialog.cpp    |   2 +-
 src/gui/register.cpp                | 276 ------------------------------------
 src/gui/register.h                  | 113 ---------------
 src/gui/registerdialog.cpp          | 276 ++++++++++++++++++++++++++++++++++++
 src/gui/registerdialog.h            | 113 +++++++++++++++
 src/gui/unregisterdialog.cpp        |   2 +-
 src/net/manaserv/generalhandler.cpp |   2 +-
 src/net/tmwa/generalhandler.cpp     |   2 +-
 12 files changed, 399 insertions(+), 399 deletions(-)
 delete mode 100644 src/gui/register.cpp
 delete mode 100644 src/gui/register.h
 create mode 100644 src/gui/registerdialog.cpp
 create mode 100644 src/gui/registerdialog.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3a6fa7f87..c0e33dc0b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -292,8 +292,8 @@ SET(SRCS
     gui/popupmenu.h
     gui/quitdialog.cpp
     gui/quitdialog.h
-    gui/register.cpp
-    gui/register.h
+    gui/registerdialog.cpp
+    gui/registerdialog.h
     gui/sdlinput.cpp
     gui/sdlinput.h
     gui/selldialog.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index c36d972d4..12f107a97 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -304,8 +304,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
 	      gui/popupmenu.h \
 	      gui/quitdialog.cpp \
 	      gui/quitdialog.h \
-	      gui/register.cpp \
-	      gui/register.h \
+	      gui/registerdialog.cpp \
+	      gui/registerdialog.h \
 	      gui/sdlinput.cpp \
 	      gui/sdlinput.h \
 	      gui/selldialog.cpp \
diff --git a/src/client.cpp b/src/client.cpp
index 89e3f6ecf..383a40da1 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -54,7 +54,7 @@
 #include "gui/logindialog.h"
 #include "gui/okdialog.h"
 #include "gui/quitdialog.h"
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 #include "gui/npcdialog.h"
 #include "gui/selldialog.h"
 #include "gui/sdlinput.h"
diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp
index 1a468d44f..125266b9a 100644
--- a/src/gui/changeemaildialog.cpp
+++ b/src/gui/changeemaildialog.cpp
@@ -25,7 +25,7 @@
 #include "client.h"
 #include "logger.h"
 
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 #include "gui/okdialog.h"
 
 #include "gui/widgets/button.h"
diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp
index a58d8616b..5f233df77 100644
--- a/src/gui/changepassworddialog.cpp
+++ b/src/gui/changepassworddialog.cpp
@@ -25,7 +25,7 @@
 #include "client.h"
 #include "logger.h"
 
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 #include "gui/okdialog.h"
 
 #include "gui/widgets/button.h"
diff --git a/src/gui/register.cpp b/src/gui/register.cpp
deleted file mode 100644
index 33c507a63..000000000
--- a/src/gui/register.cpp
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- *  The ManaPlus Client
- *  Copyright (C) 2004-2009  The Mana World Development Team
- *  Copyright (C) 2009-2010  The Mana Developers
- *  Copyright (C) 2011-2012  The ManaPlus Developers
- *
- *  This file is part of The ManaPlus Client.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/register.h"
-
-#include "client.h"
-#include "configuration.h"
-#include "logger.h"
-
-#include "gui/logindialog.h"
-#include "gui/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/passwordfield.h"
-#include "gui/widgets/radiobutton.h"
-#include "gui/widgets/textfield.h"
-
-#include "net/logindata.h"
-#include "net/loginhandler.h"
-#include "net/net.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-WrongDataNoticeListener::WrongDataNoticeListener():
-    mTarget(nullptr)
-{
-}
-
-void WrongDataNoticeListener::setTarget(gcn::TextField *textField)
-{
-    mTarget = textField;
-}
-
-void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
-{
-    if (event.getId() == "ok" && mTarget)
-        mTarget->requestFocus();
-}
-
-RegisterDialog::RegisterDialog(LoginData *data):
-    Window(_("Register"), false, nullptr, "register.xml"),
-    mEmailField(nullptr),
-    mMaleButton(nullptr),
-    mFemaleButton(nullptr),
-    mOtherButton(nullptr),
-    mWrongDataNoticeListener(new WrongDataNoticeListener),
-    mLoginData(data)
-{
-    int optionalActions = Net::getLoginHandler()->supportedOptionalActions();
-
-    gcn::Label *userLabel = new Label(_("Name:"));
-    gcn::Label *passwordLabel = new Label(_("Password:"));
-    gcn::Label *confirmLabel = new Label(_("Confirm:"));
-    mUserField = new TextField(mLoginData->username);
-    mPasswordField = new PasswordField(mLoginData->password);
-    mConfirmField = new PasswordField;
-    mRegisterButton = new Button(_("Register"), "register", this);
-    mCancelButton = new Button(_("Cancel"), "cancel", this);
-
-    ContainerPlacer placer;
-    placer = getPlacer(0, 0);
-    placer(0, 0, userLabel);
-    placer(0, 1, passwordLabel);
-    placer(0, 2, confirmLabel);
-
-    placer(1, 0, mUserField, 3).setPadding(2);
-    placer(1, 1, mPasswordField, 3).setPadding(2);
-    placer(1, 2, mConfirmField, 3).setPadding(2);
-
-    int row = 3;
-
-    if (optionalActions & Net::LoginHandler::SetGenderOnRegister)
-    {
-        mMaleButton = new RadioButton(_("Male"), "sex", true);
-        mFemaleButton = new RadioButton(_("Female"), "sex", false);
-        if (serverVersion >= 5)
-        {
-            mOtherButton = new RadioButton(_("Other"), "sex", false);
-            placer(0, row, mMaleButton);
-            placer(1, row, mFemaleButton);
-            placer(2, row, mOtherButton);
-        }
-        else
-        {
-            placer(1, row, mMaleButton);
-            placer(2, row, mFemaleButton);
-        }
-
-        row++;
-    }
-
-    if (optionalActions & Net::LoginHandler::SetEmailOnRegister)
-    {
-        gcn::Label *emailLabel = new Label(_("Email:"));
-        mEmailField = new TextField;
-        placer(0, row, emailLabel);
-        placer(1, row, mEmailField, 3).setPadding(2);
-
-        row++;
-    }
-
-    placer = getPlacer(0, 2);
-    placer(1, 0, mRegisterButton);
-    placer(2, 0, mCancelButton);
-    reflowLayout(250, 0);
-
-    mUserField->addKeyListener(this);
-    mPasswordField->addKeyListener(this);
-    mConfirmField->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
-     * input system of Guichan 0.6.0. See also the login dialog.
-     */
-    mUserField->setActionEventId("register");
-    mPasswordField->setActionEventId("register");
-    mConfirmField->setActionEventId("register");
-
-    mUserField->addActionListener(this);
-    mPasswordField->addActionListener(this);
-    mConfirmField->addActionListener(this);
-
-    center();
-    setVisible(true);
-    mUserField->requestFocus();
-    mUserField->setCaretPosition(static_cast<unsigned>(
-                                 mUserField->getText().length()));
-
-    mRegisterButton->setEnabled(canSubmit());
-}
-
-RegisterDialog::~RegisterDialog()
-{
-    delete mWrongDataNoticeListener;
-    mWrongDataNoticeListener = nullptr;
-}
-
-void RegisterDialog::action(const gcn::ActionEvent &event)
-{
-    if (event.getId() == "cancel")
-    {
-        Client::setState(STATE_LOGIN);
-    }
-    else if (event.getId() == "register" && canSubmit())
-    {
-        const std::string user = mUserField->getText();
-        logger->log("RegisterDialog::register Username is %s", user.c_str());
-
-        std::string errorMsg;
-        int error = 0;
-
-        unsigned int minUser = Net::getLoginHandler()->getMinUserNameLength();
-        unsigned int maxUser = Net::getLoginHandler()->getMaxUserNameLength();
-        unsigned int minPass = Net::getLoginHandler()->getMinPasswordLength();
-        unsigned int maxPass = Net::getLoginHandler()->getMaxPasswordLength();
-
-        if (user.length() < minUser)
-        {
-            // Name too short
-            errorMsg = strprintf
-                (_("The username needs to be at least %d characters long."),
-                 minUser);
-            error = 1;
-        }
-        else if (user.length() > maxUser - 1 )
-        {
-            // Name too long
-            errorMsg = strprintf
-                (_("The username needs to be less than %d characters long."),
-                 maxUser);
-            error = 1;
-        }
-        else if (mPasswordField->getText().length() < minPass)
-        {
-            // Pass too short
-            errorMsg = strprintf
-                (_("The password needs to be at least %d characters long."),
-                 minPass);
-            error = 2;
-        }
-        else if (mPasswordField->getText().length() > maxPass - 1 )
-        {
-            // Pass too long
-            errorMsg = strprintf
-                (_("The password needs to be less than %d characters long."),
-                 maxPass);
-            error = 2;
-        }
-        else if (mPasswordField->getText() != mConfirmField->getText())
-        {
-            // Password does not match with the confirmation one
-            errorMsg = _("Passwords do not match.");
-            error = 2;
-        }
-
-        // TODO: Check if a valid email address was given
-
-        if (error > 0)
-        {
-            if (error == 1)
-            {
-                mWrongDataNoticeListener->setTarget(this->mUserField);
-            }
-            else if (error == 2)
-            {
-                // Reset password confirmation
-                mPasswordField->setText("");
-                mConfirmField->setText("");
-
-                mWrongDataNoticeListener->setTarget(this->mPasswordField);
-            }
-
-            OkDialog *dlg = new OkDialog(_("Error"), errorMsg, DIALOG_ERROR);
-            dlg->addActionListener(mWrongDataNoticeListener);
-        }
-        else
-        {
-            // No errors detected, register the new user.
-            mRegisterButton->setEnabled(false);
-
-            mLoginData->username = mUserField->getText();
-            mLoginData->password = mPasswordField->getText();
-            if (mFemaleButton && mFemaleButton->isSelected())
-                mLoginData->gender = GENDER_FEMALE;
-            else if (mOtherButton && mOtherButton->isSelected())
-                mLoginData->gender = GENDER_OTHER;
-            else
-                mLoginData->gender = GENDER_MALE;
-
-            if (mEmailField)
-                mLoginData->email = mEmailField->getText();
-            mLoginData->registerLogin = true;
-
-            Client::setState(STATE_REGISTER_ATTEMPT);
-        }
-    }
-}
-
-void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent A_UNUSED)
-{
-    mRegisterButton->setEnabled(canSubmit());
-}
-
-bool RegisterDialog::canSubmit() const
-{
-    return !mUserField->getText().empty() &&
-           !mPasswordField->getText().empty() &&
-           !mConfirmField->getText().empty() &&
-           Client::getState() == STATE_REGISTER;
-}
diff --git a/src/gui/register.h b/src/gui/register.h
deleted file mode 100644
index 188390bba..000000000
--- a/src/gui/register.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- *  The ManaPlus Client
- *  Copyright (C) 2004-2009  The Mana World Development Team
- *  Copyright (C) 2009-2010  The Mana Developers
- *  Copyright (C) 2011-2012  The ManaPlus Developers
- *
- *  This file is part of The ManaPlus Client.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef REGISTER_H
-#define REGISTER_H
-
-#include "gui/widgets/window.h"
-
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
-
-#include <string>
-
-class LoginData;
-class OkDialog;
-
-namespace gcn
-{
-    class Button;
-    class RadioButton;
-    class TextField;
-}
-
-/**
- * Listener used while dealing with wrong data. It is used to direct the focus
- * to the field which contained wrong data when the Ok button was pressed on
- * the error notice.
- */
-class WrongDataNoticeListener : public gcn::ActionListener
-{
-    public:
-        WrongDataNoticeListener();
-        void setTarget(gcn::TextField *textField);
-        void action(const gcn::ActionEvent &event);
-    private:
-        gcn::TextField *mTarget;
-};
-
-/**
- * The registration dialog.
- *
- * \ingroup Interface
- */
-class RegisterDialog : public Window, public gcn::ActionListener,
-                       public gcn::KeyListener
-{
-    public:
-        /**
-         * Constructor. Name, password and server fields will be initialized to
-         * the information already present in the LoginData instance.
-         *
-         * @see Window::Window
-         */
-        RegisterDialog(LoginData *loginData);
-
-        /**
-         * Destructor
-         */
-        ~RegisterDialog();
-
-        /**
-         * Called when receiving actions from the widgets.
-         */
-        void action(const gcn::ActionEvent &event);
-
-        /**
-         * 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() const;
-
-        gcn::TextField *mUserField;
-        gcn::TextField *mPasswordField;
-        gcn::TextField *mConfirmField;
-        gcn::TextField *mEmailField;
-
-        gcn::Button *mRegisterButton;
-        gcn::Button *mCancelButton;
-        gcn::RadioButton *mMaleButton;
-        gcn::RadioButton *mFemaleButton;
-        gcn::RadioButton *mOtherButton;
-
-        WrongDataNoticeListener *mWrongDataNoticeListener;
-
-        LoginData *mLoginData;
-};
-
-#endif
diff --git a/src/gui/registerdialog.cpp b/src/gui/registerdialog.cpp
new file mode 100644
index 000000000..895d841b6
--- /dev/null
+++ b/src/gui/registerdialog.cpp
@@ -0,0 +1,276 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2004-2009  The Mana World Development Team
+ *  Copyright (C) 2009-2010  The Mana Developers
+ *  Copyright (C) 2011-2012  The ManaPlus Developers
+ *
+ *  This file is part of The ManaPlus Client.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/registerdialog.h"
+
+#include "client.h"
+#include "configuration.h"
+#include "logger.h"
+
+#include "gui/logindialog.h"
+#include "gui/okdialog.h"
+
+#include "gui/widgets/button.h"
+#include "gui/widgets/checkbox.h"
+#include "gui/widgets/label.h"
+#include "gui/widgets/layout.h"
+#include "gui/widgets/passwordfield.h"
+#include "gui/widgets/radiobutton.h"
+#include "gui/widgets/textfield.h"
+
+#include "net/logindata.h"
+#include "net/loginhandler.h"
+#include "net/net.h"
+
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
+
+#include "debug.h"
+
+WrongDataNoticeListener::WrongDataNoticeListener():
+    mTarget(nullptr)
+{
+}
+
+void WrongDataNoticeListener::setTarget(gcn::TextField *textField)
+{
+    mTarget = textField;
+}
+
+void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
+{
+    if (event.getId() == "ok" && mTarget)
+        mTarget->requestFocus();
+}
+
+RegisterDialog::RegisterDialog(LoginData *data):
+    Window(_("Register"), false, nullptr, "register.xml"),
+    mEmailField(nullptr),
+    mMaleButton(nullptr),
+    mFemaleButton(nullptr),
+    mOtherButton(nullptr),
+    mWrongDataNoticeListener(new WrongDataNoticeListener),
+    mLoginData(data)
+{
+    int optionalActions = Net::getLoginHandler()->supportedOptionalActions();
+
+    gcn::Label *userLabel = new Label(_("Name:"));
+    gcn::Label *passwordLabel = new Label(_("Password:"));
+    gcn::Label *confirmLabel = new Label(_("Confirm:"));
+    mUserField = new TextField(mLoginData->username);
+    mPasswordField = new PasswordField(mLoginData->password);
+    mConfirmField = new PasswordField;
+    mRegisterButton = new Button(_("Register"), "register", this);
+    mCancelButton = new Button(_("Cancel"), "cancel", this);
+
+    ContainerPlacer placer;
+    placer = getPlacer(0, 0);
+    placer(0, 0, userLabel);
+    placer(0, 1, passwordLabel);
+    placer(0, 2, confirmLabel);
+
+    placer(1, 0, mUserField, 3).setPadding(2);
+    placer(1, 1, mPasswordField, 3).setPadding(2);
+    placer(1, 2, mConfirmField, 3).setPadding(2);
+
+    int row = 3;
+
+    if (optionalActions & Net::LoginHandler::SetGenderOnRegister)
+    {
+        mMaleButton = new RadioButton(_("Male"), "sex", true);
+        mFemaleButton = new RadioButton(_("Female"), "sex", false);
+        if (serverVersion >= 5)
+        {
+            mOtherButton = new RadioButton(_("Other"), "sex", false);
+            placer(0, row, mMaleButton);
+            placer(1, row, mFemaleButton);
+            placer(2, row, mOtherButton);
+        }
+        else
+        {
+            placer(1, row, mMaleButton);
+            placer(2, row, mFemaleButton);
+        }
+
+        row++;
+    }
+
+    if (optionalActions & Net::LoginHandler::SetEmailOnRegister)
+    {
+        gcn::Label *emailLabel = new Label(_("Email:"));
+        mEmailField = new TextField;
+        placer(0, row, emailLabel);
+        placer(1, row, mEmailField, 3).setPadding(2);
+
+        row++;
+    }
+
+    placer = getPlacer(0, 2);
+    placer(1, 0, mRegisterButton);
+    placer(2, 0, mCancelButton);
+    reflowLayout(250, 0);
+
+    mUserField->addKeyListener(this);
+    mPasswordField->addKeyListener(this);
+    mConfirmField->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
+     * input system of Guichan 0.6.0. See also the login dialog.
+     */
+    mUserField->setActionEventId("register");
+    mPasswordField->setActionEventId("register");
+    mConfirmField->setActionEventId("register");
+
+    mUserField->addActionListener(this);
+    mPasswordField->addActionListener(this);
+    mConfirmField->addActionListener(this);
+
+    center();
+    setVisible(true);
+    mUserField->requestFocus();
+    mUserField->setCaretPosition(static_cast<unsigned>(
+                                 mUserField->getText().length()));
+
+    mRegisterButton->setEnabled(canSubmit());
+}
+
+RegisterDialog::~RegisterDialog()
+{
+    delete mWrongDataNoticeListener;
+    mWrongDataNoticeListener = nullptr;
+}
+
+void RegisterDialog::action(const gcn::ActionEvent &event)
+{
+    if (event.getId() == "cancel")
+    {
+        Client::setState(STATE_LOGIN);
+    }
+    else if (event.getId() == "register" && canSubmit())
+    {
+        const std::string user = mUserField->getText();
+        logger->log("RegisterDialog::register Username is %s", user.c_str());
+
+        std::string errorMsg;
+        int error = 0;
+
+        unsigned int minUser = Net::getLoginHandler()->getMinUserNameLength();
+        unsigned int maxUser = Net::getLoginHandler()->getMaxUserNameLength();
+        unsigned int minPass = Net::getLoginHandler()->getMinPasswordLength();
+        unsigned int maxPass = Net::getLoginHandler()->getMaxPasswordLength();
+
+        if (user.length() < minUser)
+        {
+            // Name too short
+            errorMsg = strprintf
+                (_("The username needs to be at least %d characters long."),
+                 minUser);
+            error = 1;
+        }
+        else if (user.length() > maxUser - 1 )
+        {
+            // Name too long
+            errorMsg = strprintf
+                (_("The username needs to be less than %d characters long."),
+                 maxUser);
+            error = 1;
+        }
+        else if (mPasswordField->getText().length() < minPass)
+        {
+            // Pass too short
+            errorMsg = strprintf
+                (_("The password needs to be at least %d characters long."),
+                 minPass);
+            error = 2;
+        }
+        else if (mPasswordField->getText().length() > maxPass - 1 )
+        {
+            // Pass too long
+            errorMsg = strprintf
+                (_("The password needs to be less than %d characters long."),
+                 maxPass);
+            error = 2;
+        }
+        else if (mPasswordField->getText() != mConfirmField->getText())
+        {
+            // Password does not match with the confirmation one
+            errorMsg = _("Passwords do not match.");
+            error = 2;
+        }
+
+        // TODO: Check if a valid email address was given
+
+        if (error > 0)
+        {
+            if (error == 1)
+            {
+                mWrongDataNoticeListener->setTarget(this->mUserField);
+            }
+            else if (error == 2)
+            {
+                // Reset password confirmation
+                mPasswordField->setText("");
+                mConfirmField->setText("");
+
+                mWrongDataNoticeListener->setTarget(this->mPasswordField);
+            }
+
+            OkDialog *dlg = new OkDialog(_("Error"), errorMsg, DIALOG_ERROR);
+            dlg->addActionListener(mWrongDataNoticeListener);
+        }
+        else
+        {
+            // No errors detected, register the new user.
+            mRegisterButton->setEnabled(false);
+
+            mLoginData->username = mUserField->getText();
+            mLoginData->password = mPasswordField->getText();
+            if (mFemaleButton && mFemaleButton->isSelected())
+                mLoginData->gender = GENDER_FEMALE;
+            else if (mOtherButton && mOtherButton->isSelected())
+                mLoginData->gender = GENDER_OTHER;
+            else
+                mLoginData->gender = GENDER_MALE;
+
+            if (mEmailField)
+                mLoginData->email = mEmailField->getText();
+            mLoginData->registerLogin = true;
+
+            Client::setState(STATE_REGISTER_ATTEMPT);
+        }
+    }
+}
+
+void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent A_UNUSED)
+{
+    mRegisterButton->setEnabled(canSubmit());
+}
+
+bool RegisterDialog::canSubmit() const
+{
+    return !mUserField->getText().empty() &&
+           !mPasswordField->getText().empty() &&
+           !mConfirmField->getText().empty() &&
+           Client::getState() == STATE_REGISTER;
+}
diff --git a/src/gui/registerdialog.h b/src/gui/registerdialog.h
new file mode 100644
index 000000000..188390bba
--- /dev/null
+++ b/src/gui/registerdialog.h
@@ -0,0 +1,113 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2004-2009  The Mana World Development Team
+ *  Copyright (C) 2009-2010  The Mana Developers
+ *  Copyright (C) 2011-2012  The ManaPlus Developers
+ *
+ *  This file is part of The ManaPlus Client.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef REGISTER_H
+#define REGISTER_H
+
+#include "gui/widgets/window.h"
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/keylistener.hpp>
+
+#include <string>
+
+class LoginData;
+class OkDialog;
+
+namespace gcn
+{
+    class Button;
+    class RadioButton;
+    class TextField;
+}
+
+/**
+ * Listener used while dealing with wrong data. It is used to direct the focus
+ * to the field which contained wrong data when the Ok button was pressed on
+ * the error notice.
+ */
+class WrongDataNoticeListener : public gcn::ActionListener
+{
+    public:
+        WrongDataNoticeListener();
+        void setTarget(gcn::TextField *textField);
+        void action(const gcn::ActionEvent &event);
+    private:
+        gcn::TextField *mTarget;
+};
+
+/**
+ * The registration dialog.
+ *
+ * \ingroup Interface
+ */
+class RegisterDialog : public Window, public gcn::ActionListener,
+                       public gcn::KeyListener
+{
+    public:
+        /**
+         * Constructor. Name, password and server fields will be initialized to
+         * the information already present in the LoginData instance.
+         *
+         * @see Window::Window
+         */
+        RegisterDialog(LoginData *loginData);
+
+        /**
+         * Destructor
+         */
+        ~RegisterDialog();
+
+        /**
+         * Called when receiving actions from the widgets.
+         */
+        void action(const gcn::ActionEvent &event);
+
+        /**
+         * 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() const;
+
+        gcn::TextField *mUserField;
+        gcn::TextField *mPasswordField;
+        gcn::TextField *mConfirmField;
+        gcn::TextField *mEmailField;
+
+        gcn::Button *mRegisterButton;
+        gcn::Button *mCancelButton;
+        gcn::RadioButton *mMaleButton;
+        gcn::RadioButton *mFemaleButton;
+        gcn::RadioButton *mOtherButton;
+
+        WrongDataNoticeListener *mWrongDataNoticeListener;
+
+        LoginData *mLoginData;
+};
+
+#endif
diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp
index 9ba895ec8..6887ffbb8 100644
--- a/src/gui/unregisterdialog.cpp
+++ b/src/gui/unregisterdialog.cpp
@@ -26,7 +26,7 @@
 #include "logger.h"
 
 #include "gui/okdialog.h"
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 
 #include "gui/widgets/button.h"
 #include "gui/widgets/checkbox.h"
diff --git a/src/net/manaserv/generalhandler.cpp b/src/net/manaserv/generalhandler.cpp
index 241377956..510e6ef0b 100644
--- a/src/net/manaserv/generalhandler.cpp
+++ b/src/net/manaserv/generalhandler.cpp
@@ -27,7 +27,7 @@
 #include "gui/changeemaildialog.h"
 #include "gui/charselectdialog.h"
 #include "gui/inventorywindow.h"
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 #include "gui/skilldialog.h"
 #include "gui/specialswindow.h"
 
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index 8188efc73..466d382fc 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -28,7 +28,7 @@
 
 #include "gui/charselectdialog.h"
 #include "gui/inventorywindow.h"
-#include "gui/register.h"
+#include "gui/registerdialog.h"
 #include "gui/skilldialog.h"
 #include "gui/socialwindow.h"
 #include "gui/statuswindow.h"
-- 
cgit v1.2.3-70-g09d2