diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-08-07 00:37:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-08-07 00:37:14 +0300 |
commit | 07e638798767239e4ea5fa39f17e9e8576fb1f14 (patch) | |
tree | 2b52e6ddb5778085f3c343a624cde230dd8c23ad | |
parent | 671ca11caba0dc80636ff76035f55b6b8fc3893e (diff) | |
download | manaverse-07e638798767239e4ea5fa39f17e9e8576fb1f14.tar.gz manaverse-07e638798767239e4ea5fa39f17e9e8576fb1f14.tar.bz2 manaverse-07e638798767239e4ea5fa39f17e9e8576fb1f14.tar.xz manaverse-07e638798767239e4ea5fa39f17e9e8576fb1f14.zip |
Add connect button to edit server dialog.
-rw-r--r-- | src/gui/editserverdialog.cpp | 12 | ||||
-rw-r--r-- | src/gui/editserverdialog.h | 1 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 78 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 2 |
4 files changed, 54 insertions, 39 deletions
diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 0a8c3e816..434a4f827 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -86,6 +86,7 @@ EditServerDialog::EditServerDialog(ServerDialog *parent, ServerInfo server, mNameField = new TextField(std::string()); mDescriptionField = new TextField(std::string()); + mConnectButton = new Button(_("Connect"), "connect", this); mOkButton = new Button(_("OK"), "addServer", this); mCancelButton = new Button(_("Cancel"), "cancel", this); @@ -102,6 +103,7 @@ EditServerDialog::EditServerDialog(ServerDialog *parent, ServerInfo server, place(1, 3, mTypeField).setPadding(3); place(0, 4, descriptionLabel); place(1, 4, mDescriptionField, 4).setPadding(3); + place(0, 5, mConnectButton); place(4, 5, mOkButton); place(3, 5, mCancelButton); @@ -182,12 +184,14 @@ void EditServerDialog::logic() void EditServerDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "ok") + const std::string &eventId = event.getId(); + + if (eventId == "ok") { // Give focus back to the server dialog. mServerAddressField->requestFocus(); } - if (event.getId() == "addServer") + if (eventId == "addServer" || eventId == "connect") { // Check the given information if (mServerAddressField->getText().empty() @@ -249,10 +253,12 @@ void EditServerDialog::action(const gcn::ActionEvent &event) //Add server mServerDialog->updateServer(mServer, mIndex); + if (eventId == "connect") + mServerDialog->connectToSelectedServer(); scheduleDelete(); } } - else if (event.getId() == "cancel") + else if (eventId == "cancel") { scheduleDelete(); } diff --git a/src/gui/editserverdialog.h b/src/gui/editserverdialog.h index 5f7b4318d..79169c3a3 100644 --- a/src/gui/editserverdialog.h +++ b/src/gui/editserverdialog.h @@ -99,6 +99,7 @@ class EditServerDialog : public Window, TextField *mPortField; TextField *mNameField; TextField *mDescriptionField; + Button *mConnectButton; Button *mOkButton; Button *mCancelButton; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 0badba504..80e793cd2 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -339,68 +339,74 @@ ServerDialog::~ServerDialog() mServersListModel = nullptr; } -void ServerDialog::action(const gcn::ActionEvent &event) +void ServerDialog::connectToSelectedServer() { - if (event.getId() == "connect") - { - if (Client::getState() == STATE_CONNECT_SERVER) - return; + if (Client::getState() == STATE_CONNECT_SERVER) + return; - int index = mServersList->getSelected(); - if (index < 0) - return; + int index = mServersList->getSelected(); + if (index < 0) + return; - if (mDownload) - mDownload->cancel(); + if (mDownload) + mDownload->cancel(); - mQuitButton->setEnabled(false); - mConnectButton->setEnabled(false); - mLoadButton->setEnabled(false); + mQuitButton->setEnabled(false); + mConnectButton->setEnabled(false); + mLoadButton->setEnabled(false); - ServerInfo server = mServers.at(index); - mServerInfo->hostname = server.hostname; - mServerInfo->port = server.port; - mServerInfo->type = server.type; - mServerInfo->name = server.name; - mServerInfo->description = server.description; - mServerInfo->save = true; + ServerInfo server = mServers.at(index); + mServerInfo->hostname = server.hostname; + mServerInfo->port = server.port; + mServerInfo->type = server.type; + mServerInfo->name = server.name; + mServerInfo->description = server.description; + mServerInfo->save = true; - if (chatLogger) - chatLogger->setServerName(mServerInfo->hostname); + if (chatLogger) + chatLogger->setServerName(mServerInfo->hostname); - saveCustomServers(*mServerInfo); + saveCustomServers(*mServerInfo); - if (!LoginDialog::savedPasswordKey.empty()) - { - if (mServerInfo->hostname != LoginDialog::savedPasswordKey) - LoginDialog::savedPassword = ""; - } + if (!LoginDialog::savedPasswordKey.empty()) + { + if (mServerInfo->hostname != LoginDialog::savedPasswordKey) + LoginDialog::savedPassword = ""; + } - config.setValue("usePersistentIP", - mPersistentIPCheckBox->isSelected()); - Client::setState(STATE_CONNECT_SERVER); + config.setValue("usePersistentIP", + mPersistentIPCheckBox->isSelected()); + Client::setState(STATE_CONNECT_SERVER); +} + +void ServerDialog::action(const gcn::ActionEvent &event) +{ + const std::string &eventId = event.getId(); + if (eventId == "connect") + { + connectToSelectedServer(); } - else if (event.getId() == "quit") + else if (eventId == "quit") { if (mDownload) mDownload->cancel(); Client::setState(STATE_FORCE_QUIT); } - else if (event.getId() == "load") + else if (eventId == "load") { downloadServerList(); } - else if (event.getId() == "addEntry") + else if (eventId == "addEntry") { new EditServerDialog(this, ServerInfo(), -1); } - else if (event.getId() == "editEntry") + else if (eventId == "editEntry") { int index = mServersList->getSelected(); if (index >= 0) new EditServerDialog(this, mServers.at(index), index); } - else if (event.getId() == "remove") + else if (eventId == "remove") { int index = mServersList->getSelected(); if (index >= 0) diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index 61620364c..b6a45dfd9 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -125,6 +125,8 @@ class ServerDialog : public Window, void updateServer(ServerInfo server, int index); + void connectToSelectedServer(); + protected: friend class ServersListModel; |