diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-12-30 16:27:24 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-12-30 16:27:24 +0000 |
commit | ea653b2e9e1b46a07440833f96b3d2b788592c61 (patch) | |
tree | 252bb23d2064d14d4aa0796aa159f94873cb6419 /src/gui/login.cpp | |
parent | 57d63f1dd5df0beb1a3d81f014686a2f80dfe7fc (diff) | |
download | mana-ea653b2e9e1b46a07440833f96b3d2b788592c61.tar.gz mana-ea653b2e9e1b46a07440833f96b3d2b788592c61.tar.bz2 mana-ea653b2e9e1b46a07440833f96b3d2b788592c61.tar.xz mana-ea653b2e9e1b46a07440833f96b3d2b788592c61.zip |
Added a new item, improved smooth login sequence, added a registration window (a lot of duplicated code to be removed).
Diffstat (limited to 'src/gui/login.cpp')
-rw-r--r-- | src/gui/login.cpp | 130 |
1 files changed, 28 insertions, 102 deletions
diff --git a/src/gui/login.cpp b/src/gui/login.cpp index a8e906e1..ad469d22 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -39,52 +39,29 @@ #include "checkbox.h" #include "passwordfield.h" #include "textfield.h" -#include "ok_dialog.h" #include "../net/messagein.h" #include "../net/messageout.h" #include "../net/network.h" -OkDialog *wrongLoginNotice = NULL; SERVER_INFO **server_info; -WrongUsernameNoticeListener wrongUsernameNoticeListener; -WrongPasswordNoticeListener wrongPasswordNoticeListener; - void -WrongPasswordNoticeListener::setLoginDialog(LoginDialog *loginDialog) +WrongDataNoticeListener::setTarget(gcn::TextField *textField) { - mLoginDialog = loginDialog; + this->target = textField; } void -WrongPasswordNoticeListener::action(const std::string &eventId) +WrongDataNoticeListener::action(const std::string &eventId) { if (eventId == "ok") { - // Reset the password and put the caret ready to retype it. - mLoginDialog->passField->setText(""); - mLoginDialog->passField->setCaretPosition(0); - mLoginDialog->passField->requestFocus(); - wrongLoginNotice = NULL; - } -} - -void -WrongUsernameNoticeListener::setLoginDialog(LoginDialog *loginDialog) -{ - mLoginDialog = loginDialog; -} - -void -WrongUsernameNoticeListener::action(const std::string &eventId) -{ - if (eventId == "ok") - { - // Set the focus on the username Field - mLoginDialog->userField->setCaretPosition(LEN_MAX_USERNAME - 1); - mLoginDialog->userField->requestFocus(); - wrongLoginNotice = NULL; + // Reset the field + target->setText(""); + target->setCaretPosition(0); + target->requestFocus(); + //wrongLoginNotice = NULL; } } @@ -165,8 +142,16 @@ LoginDialog::LoginDialog(): serverField->setText(config.getValue("host", "")); - wrongUsernameNoticeListener.setLoginDialog(this); - wrongPasswordNoticeListener.setLoginDialog(this); + wrongDataNoticeListener = NULL; + wrongLoginNotice = NULL; +} + +LoginDialog::~LoginDialog() +{ + if (wrongLoginNotice) + { + delete wrongLoginNotice; + } } void @@ -193,9 +178,15 @@ LoginDialog::action(const std::string& eventId) // Check login if (user.length() == 0) { + wrongDataNoticeListener = new WrongDataNoticeListener(); + wrongDataNoticeListener->setTarget(this->passField); + if (wrongLoginNotice) + { + delete wrongLoginNotice; + } wrongLoginNotice = new OkDialog("Error", - "Enter your username first", - &wrongUsernameNoticeListener); + "Enter your username first", + wrongDataNoticeListener); } else { @@ -212,70 +203,7 @@ LoginDialog::action(const std::string& eventId) } else if (eventId == "register") { - const std::string user = userField->getText(); - logger->log("LoginDialog::register Username is %s", user.c_str()); - - // Store config settings - config.setValue("remember", keepCheck->isMarked()); - if (keepCheck->isMarked()) { - config.setValue("username", user); - } else { - config.setValue("username", ""); - } - - std::stringstream errorMsg; - bool error = false; - - // Check login - if (user.length() == 0) - { - // No username - errorMsg << "Enter your username first."; - } - else if (user.length() < LEN_MIN_USERNAME) - { - // Name too short - errorMsg << "The username needs to be at least " - << LEN_MIN_USERNAME - << " characters long."; - } - else if (user.length() > LEN_MAX_USERNAME - 1 ) - { - // Name too long - errorMsg << "The username needs to be less than " - << LEN_MAX_USERNAME - << " characters long."; - } - else if (passField->getText().length() < LEN_MIN_PASSWORD) - { - // Pass too short - errorMsg << "The password needs to be at least " - << LEN_MIN_PASSWORD - << " characters long."; - } - else if (passField->getText().length() > LEN_MAX_PASSWORD - 1 ) - { - // Pass too long - errorMsg << "The password needs to be less than " - << LEN_MAX_PASSWORD - << " characters long."; - } - - if (error) - { - wrongLoginNotice = new OkDialog("Error", errorMsg.str(), - &wrongPasswordNoticeListener); - } - else - { - // No errors detected, register the new user. - const std::string host(config.getValue("host", "animesites.de")); - short port = (short)config.getValue("port", 0); - // Attempt to connect to login server - openConnection(host.c_str(), port); - mStatus = NET_CONNECTING; - registration = true; - } + state = REGISTER_STATE; } } @@ -295,9 +223,7 @@ LoginDialog::logic() logger->log("Connection closed"); break; case NET_DATA: - // TODO: this is a very quick hack, we should implement something - // like a bool completePacket() in network functions. - if (in_size > 2) + if (packetReady()) { checkLogin(); closeConnection(); |