diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-03 13:57:34 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-03 13:57:34 +0000 |
commit | 9dc99e1888de6194c7ce555c33245e6bff586b3d (patch) | |
tree | 39b4159d2a56976474da4cc4659e5dd04f1cfa25 | |
parent | f8d16a36db8f9d1f22f3a15d2fbee19b7c68ebef (diff) | |
download | mana-9dc99e1888de6194c7ce555c33245e6bff586b3d.tar.gz mana-9dc99e1888de6194c7ce555c33245e6bff586b3d.tar.bz2 mana-9dc99e1888de6194c7ce555c33245e6bff586b3d.tar.xz mana-9dc99e1888de6194c7ce555c33245e6bff586b3d.zip |
Made the login dialog work on LoginData only, without playing with the config, it's not its job to do so.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/gui/login.cpp | 45 | ||||
-rw-r--r-- | src/gui/login.h | 7 | ||||
-rw-r--r-- | src/logindata.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 34 |
5 files changed, 45 insertions, 46 deletions
@@ -1,5 +1,8 @@ 2006-02-03 Björn Steinbrink <B.Steinbrink@gmx.de> + * src/logindata.h, src/main.cpp, src/gui/login.cpp, src/gui/login.h: + Made the login dialog work on LoginData only, without playing with the + config, it's not its job to do so. * src/net/protocol.cpp, src/net/protocol.h: Removed some unused code. 2006-02-02 Philipp Sehmisch <tmw@crushnet.org> diff --git a/src/gui/login.cpp b/src/gui/login.cpp index e3828af7..a66273da 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -28,8 +28,6 @@ #include <guichan/widgets/label.hpp> #include "../main.h" -#include "../configuration.h" -#include "../log.h" #include "../logindata.h" #include "button.h" @@ -62,9 +60,9 @@ LoginDialog::LoginDialog(LoginData *loginData): userLabel = new gcn::Label("Name:"); passLabel = new gcn::Label("Password:"); serverLabel = new gcn::Label("Server:"); - userField = new TextField("player"); - passField = new PasswordField(); - serverField = new TextField(); + userField = new TextField(mLoginData->username); + passField = new PasswordField(mLoginData->password); + serverField = new TextField(mLoginData->hostname); keepCheck = new CheckBox("Keep", false); okButton = new Button("OK"); cancelButton = new Button("Cancel"); @@ -84,7 +82,7 @@ LoginDialog::LoginDialog(LoginData *loginData): passField->setWidth(130); serverField->setWidth(130); keepCheck->setPosition(4, 77); - keepCheck->setMarked(config.getValue("remember", 0)); + keepCheck->setMarked(mLoginData->remember); cancelButton->setPosition( 200 - cancelButton->getWidth() - 5, 100 - cancelButton->getHeight() - 5); @@ -121,18 +119,13 @@ LoginDialog::LoginDialog(LoginData *loginData): add(registerButton); setLocationRelativeTo(getParent()); - userField->requestFocus(); - userField->setCaretPosition(userField->getText().length()); - if (config.getValue("remember", 0) != 0) { - if (config.getValue("username", "") != "") { - userField->setText(config.getValue("username", "")); - passField->requestFocus(); - } + if (!userField->getText().length()) { + userField->requestFocus(); + } else { + passField->requestFocus(); } - serverField->setText(config.getValue("host", "")); - wrongDataNoticeListener = new WrongDataNoticeListener(); } @@ -146,24 +139,8 @@ LoginDialog::action(const std::string& eventId) { if (eventId == "ok") { - const std::string user = userField->getText(); - logger->log("Network: Username is %s", user.c_str()); - - // Store config settings - config.setValue("remember", keepCheck->isMarked()); - - if (keepCheck->isMarked()) - { - config.setValue("username", user); - config.setValue("host", serverField->getText()); - } - else - { - config.setValue("username", ""); - } - // Check login - if (user.length() == 0) + if (userField->getText().length() == 0) { wrongDataNoticeListener->setTarget(this->passField); OkDialog *dlg = new OkDialog("Error", "Enter your username first"); @@ -171,10 +148,10 @@ LoginDialog::action(const std::string& eventId) } else { - mLoginData->hostname = config.getValue("host", "animesites.de"); - mLoginData->port = (short)config.getValue("port", 0); + mLoginData->hostname = serverField->getText(); mLoginData->username = userField->getText(); mLoginData->password = passField->getText(); + mLoginData->remember = keepCheck->isMarked(); okButton->setEnabled(false); //cancelButton->setEnabled(false); diff --git a/src/gui/login.h b/src/gui/login.h index b096d05f..9e6dc6b4 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -67,15 +67,12 @@ class LoginDialog : public Window, public gcn::ActionListener { */ void action(const std::string& eventId); - // Made them public to have the possibility to request focus - // from external functions. - gcn::TextField *userField; - gcn::TextField *passField; - private: gcn::Label *userLabel; gcn::Label *passLabel; gcn::Label *serverLabel; + gcn::TextField *userField; + gcn::TextField *passField; gcn::TextField *serverField; gcn::CheckBox *keepCheck; gcn::Button *okButton; diff --git a/src/logindata.h b/src/logindata.h index fa4628a1..a5a48687 100644 --- a/src/logindata.h +++ b/src/logindata.h @@ -30,6 +30,8 @@ struct LoginData std::string password; std::string hostname; short port; + + bool remember; }; #endif diff --git a/src/main.cpp b/src/main.cpp index 0ea554bf..3424e90a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -405,6 +405,7 @@ MapLoginHandler mapLoginHandler; void accountLogin(Network *network, LoginData *loginData) { logger->log("Trying to connect to account server..."); + logger->log("Username is %s", loginData->username.c_str()); network->connect(loginData->hostname.c_str(), loginData->port); network->registerHandler(&loginHandler); @@ -415,6 +416,14 @@ void accountLogin(Network *network, LoginData *loginData) outMsg.writeString(loginData->username, 24); outMsg.writeString(loginData->password, 24); outMsg.writeInt8(0); // unknown + + // TODO This is not the best place to save the config, but at least better + // than the login gui window + if (loginData->remember) { + config.setValue("host", loginData->hostname); + config.setValue("username", loginData->username); + } + config.setValue("remember", loginData->remember); } void charLogin(Network *network, const SERVER_INFO *si) @@ -505,6 +514,19 @@ int main(int argc, char *argv[]) sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg"); + accountLoginData.username = options.username; + if (accountLoginData.username.empty()) { + if (config.getValue("remember", 0)) { + accountLoginData.username = config.getValue("username", ""); + } + } + if (!options.password.empty()) { + accountLoginData.password = options.password; + } + accountLoginData.hostname = config.getValue("host", "animesites.de"); + accountLoginData.port = (short)config.getValue("port", 0); + accountLoginData.remember = config.getValue("remember", 0); + SDLNet_Init(); Network *network = new Network(); while (state != EXIT_STATE) @@ -577,18 +599,16 @@ int main(int argc, char *argv[]) if (currentDialog && state != ACCOUNT_STATE && state != CHAR_CONNECT_STATE) { delete currentDialog; + currentDialog = NULL; } switch (state) { case LOGIN_STATE: logger->log("State: LOGIN"); - currentDialog = new LoginDialog(&accountLoginData); - - if (!options.username.empty()) { - LoginDialog *loginDialog = (LoginDialog*)currentDialog; - loginDialog->userField->setText(options.username); - loginDialog->passField->setText(options.password); - loginDialog->action("ok"); + if (!accountLoginData.password.empty()) { + state = ACCOUNT_STATE; + } else { + currentDialog = new LoginDialog(&accountLoginData); } break; |