diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-22 19:43:14 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-10-22 19:43:14 +0000 |
commit | 113c3440f04470aca4f45840ab9b8db0459b7113 (patch) | |
tree | 58ac13a4bc1bd0dafd4c72a867208e95dd0c7077 /src/gui | |
parent | c2d102ed9adfdf1a960b6eb97ce58961022f62c8 (diff) | |
download | mana-113c3440f04470aca4f45840ab9b8db0459b7113.tar.gz mana-113c3440f04470aca4f45840ab9b8db0459b7113.tar.bz2 mana-113c3440f04470aca4f45840ab9b8db0459b7113.tar.xz mana-113c3440f04470aca4f45840ab9b8db0459b7113.zip |
Plugged memory leak. Simplified code. Removed annoying reset of text fields. Changed error message and marked it as translatable.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/serverdialog.cpp | 60 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 27 |
2 files changed, 22 insertions, 65 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 2051518d..c05e7aa9 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -46,34 +46,6 @@ const short MAX_SERVERLIST = 5; -void -DropDownListener::action(const gcn::ActionEvent &event) -{ - if (event.getId() == "ok") - { - // Reset the text fields and give back the server dialog. - mServerNameField->setText(""); - mServerNameField->setCaretPosition(0); - mServerPortField->setText(""); - mServerPortField->setCaretPosition(0); - - mServerNameField->requestFocus(); - } - else if (event.getId() == "changeSelection") - { - // Change the textField Values according to new selection - if (currentSelectedIndex != mServersListBox->getSelected()) - { - Server myServer; - myServer = mServersListModel->getServer( - mServersListBox->getSelected()); - mServerNameField->setText(myServer.serverName); - mServerPortField->setText(toString(myServer.port)); - currentSelectedIndex = mServersListBox->getSelected(); - } - } -} - int ServersListModel::getNumberOfElements() { return servers.size(); @@ -134,19 +106,16 @@ ServerDialog::ServerDialog(LoginData *loginData): mMostUsedServersDropDown = new DropDown(mMostUsedServersListModel, mMostUsedServersScrollArea, mMostUsedServersListBox); - mDropDownListener = new DropDownListener(mServerNameField, mPortField, - mMostUsedServersListModel, mMostUsedServersListBox); - - mOkButton = new Button(_("Ok"), "ok", this); + mOkButton = new Button(_("Ok"), "connect", this); mCancelButton = new Button(_("Cancel"), "cancel", this); - mServerNameField->setActionEventId("ok"); - mPortField->setActionEventId("ok"); + mServerNameField->setActionEventId("connect"); + mPortField->setActionEventId("connect"); mMostUsedServersDropDown->setActionEventId("changeSelection"); mServerNameField->addActionListener(this); mPortField->addActionListener(this); - mMostUsedServersDropDown->addActionListener(mDropDownListener); + mMostUsedServersDropDown->addActionListener(this); place(0, 0, serverLabel); place(0, 1, portLabel); @@ -177,7 +146,8 @@ ServerDialog::ServerDialog(LoginData *loginData): ServerDialog::~ServerDialog() { - delete mDropDownListener; + delete mMostUsedServersListModel; + delete mMostUsedServersScrollArea; } void @@ -185,11 +155,25 @@ ServerDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { + // Give focus back to the server dialog. + mServerNameField->requestFocus(); + } + else if (event.getId() == "changeSelection") + { + // Change the textField Values according to new selection + Server myServer = mMostUsedServersListModel->getServer + (mMostUsedServersListBox->getSelected()); + mServerNameField->setText(myServer.serverName); + mPortField->setText(toString(myServer.port)); + } + else if (event.getId() == "connect") + { // Check login if (mServerNameField->getText().empty() || mPortField->getText().empty()) { - OkDialog *dlg = new OkDialog(_("Error"), "Enter the chosen server."); - dlg->addActionListener(mDropDownListener); + OkDialog *dlg = new OkDialog(_("Error"), + _("Please type both the address and the port of a server.")); + dlg->addActionListener(this); } else { diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index ae81cb2d..53474611 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -84,31 +84,6 @@ class ServersListModel : public gcn::ListModel }; /** - * Listener used for handling the DropDown in the server Dialog. - */ -class DropDownListener : public gcn::ActionListener -{ - public: - DropDownListener(gcn::TextField *serverNameField, - gcn::TextField *serverPortField, - ServersListModel *serversListModel, - gcn::ListBox *serversListBox): - currentSelectedIndex(0), - mServerNameField(serverNameField), - mServerPortField(serverPortField), - mServersListModel(serversListModel), - mServersListBox(serversListBox) {}; - void action(const gcn::ActionEvent &event); - private: - short currentSelectedIndex; - gcn::TextField *mServerNameField; - gcn::TextField *mServerPortField; - ServersListModel *mServersListModel; - gcn::ListBox *mServersListBox; -}; - - -/** * The server choice dialog. * * \ingroup Interface @@ -144,8 +119,6 @@ class ServerDialog : public Window, public gcn::ActionListener gcn::ScrollArea *mMostUsedServersScrollArea; ServersListModel *mMostUsedServersListModel; - DropDownListener *mDropDownListener; - LoginData *mLoginData; }; |