summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-02-01 04:15:19 +0300
committerAndrei Karas <akaras@inbox.ru>2012-02-01 04:15:19 +0300
commit292968544ed758ae58c29b613cb89a7b67e551fa (patch)
tree710b40f187592a1f3efb44b308a457f002f096f8 /src
parentd90303a19147d679f46759aba8b8711962b6e176 (diff)
downloadplus-292968544ed758ae58c29b613cb89a7b67e551fa.tar.gz
plus-292968544ed758ae58c29b613cb89a7b67e551fa.tar.bz2
plus-292968544ed758ae58c29b613cb89a7b67e551fa.tar.xz
plus-292968544ed758ae58c29b613cb89a7b67e551fa.zip
Rename CustomServerDialog to EditServerDialog.
Use EditServerDialog for adding new servers to ServerDialog.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/editserverdialog.cpp (renamed from src/gui/customserverdialog.cpp)99
-rw-r--r--src/gui/editserverdialog.h (renamed from src/gui/customserverdialog.h)28
-rw-r--r--src/gui/serverdialog.cpp296
-rw-r--r--src/gui/serverdialog.h39
-rw-r--r--src/net/serverinfo.h2
7 files changed, 192 insertions, 276 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d2c003559..955795a14 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -245,6 +245,8 @@ SET(SRCS
gui/debugwindow.h
gui/didyouknowwindow.cpp
gui/didyouknowwindow.h
+ gui/editserverdialog.cpp
+ gui/editserverdialog.h
gui/emotepopup.cpp
gui/emotepopup.h
gui/equipmentwindow.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index b39145c63..0e76af87c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -248,6 +248,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
gui/debugwindow.h \
gui/didyouknowwindow.cpp \
gui/didyouknowwindow.h \
+ gui/editserverdialog.cpp \
+ gui/editserverdialog.h \
gui/emotepopup.cpp \
gui/emotepopup.h \
gui/equipmentwindow.cpp \
diff --git a/src/gui/customserverdialog.cpp b/src/gui/editserverdialog.cpp
index b84595d0d..43457456e 100644
--- a/src/gui/customserverdialog.cpp
+++ b/src/gui/editserverdialog.cpp
@@ -1,8 +1,9 @@
/*
* The Mana Client
* Copyright (C) 2011-2012 The Mana Developers
+ * Copyright (C) 2012 The ManaPlus Developers
*
- * This file is part of The Mana Client.
+ * 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
@@ -18,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/customserverdialog.h"
+#include "gui/editserverdialog.h"
#include "configuration.h"
@@ -39,17 +40,23 @@ std::string TypeListModel::getElementAt(int elementIndex)
if (elementIndex == 0)
return "TmwAthena";
else if (elementIndex == 1)
+ return "Evol";
+#ifdef MANASERV_SUPPORT
+ else if (elementIndex == 2)
return "ManaServ";
+#endif
else
return "Unknown";
}
-CustomServerDialog::CustomServerDialog(ServerDialog *parent, int index):
- Window(_("Custom Server"), true, parent),
+EditServerDialog::EditServerDialog(ServerDialog *parent, ServerInfo server,
+ int index) :
+ Window(_("Edit Server"), true, parent),
mServerDialog(parent),
+ mServer(server),
mIndex(index)
{
- setWindowName("CustomServerDialog");
+ setWindowName("EditServerDialog");
Label *nameLabel = new Label(_("Name:"));
Label *serverAdressLabel = new Label(_("Address:"));
@@ -58,6 +65,8 @@ CustomServerDialog::CustomServerDialog(ServerDialog *parent, int index):
Label *descriptionLabel = new Label(_("Description:"));
mServerAddressField = new TextField(std::string());
mPortField = new TextField(std::string());
+ mPortField->setNumeric(true);
+ mPortField->setRange(1, 65535);
mTypeListModel = new TypeListModel();
mTypeField = new DropDown(mTypeListModel);
@@ -111,16 +120,26 @@ CustomServerDialog::CustomServerDialog(ServerDialog *parent, int index):
loadWindowState();
- // Add the entry's info when in modify mode.
- if (index > -1)
+ mNameField->setText(mServer.name);
+ mDescriptionField->setText(mServer.description);
+ mServerAddressField->setText(mServer.hostname);
+ mPortField->setText(toString(mServer.port));
+
+ switch (mServer.type)
{
- const ServerInfo &serverInfo = mServerDialog->mServers[index];
- mNameField->setText(serverInfo.name);
- mDescriptionField->setText(serverInfo.description);
- mServerAddressField->setText(serverInfo.hostname);
- mPortField->setText(toString(serverInfo.port));
- mTypeField->setSelected(serverInfo.type ? ServerInfo::MANASERV :
- ServerInfo::TMWATHENA);
+ case ServerInfo::MANASERV:
+#ifdef MANASERV_SUPPORT
+ mTypeField->setSelected(2);
+ break;
+#endif
+ default:
+ case ServerInfo::UNKNOWN:
+ case ServerInfo::TMWATHENA:
+ mTypeField->setSelected(0);
+ break;
+ case ServerInfo::EVOL:
+ mTypeField->setSelected(1);
+ break;
}
setLocationRelativeTo(getParentWindow());
@@ -129,17 +148,17 @@ CustomServerDialog::CustomServerDialog(ServerDialog *parent, int index):
mNameField->requestFocus();
}
-CustomServerDialog::~CustomServerDialog()
+EditServerDialog::~EditServerDialog()
{
delete mTypeListModel;
}
-void CustomServerDialog::logic()
+void EditServerDialog::logic()
{
Window::logic();
}
-void CustomServerDialog::action(const gcn::ActionEvent &event)
+void EditServerDialog::action(const gcn::ActionEvent &event)
{
if (event.getId() == "ok")
{
@@ -162,28 +181,40 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
mCancelButton->setEnabled(false);
mOkButton->setEnabled(false);
- ServerInfo serverInfo;
- serverInfo.name = mNameField->getText();
- serverInfo.description = mDescriptionField->getText();
- serverInfo.hostname = mServerAddressField->getText();
- serverInfo.port = (short) atoi(mPortField->getText().c_str());
- switch (mTypeField->getSelected())
+ mServer.name = mNameField->getText();
+ mServer.description = mDescriptionField->getText();
+ mServer.hostname = mServerAddressField->getText();
+ mServer.port = (short) atoi(mPortField->getText().c_str());
+
+ if (mTypeField)
+ {
+ switch (mTypeField->getSelected())
+ {
+ case 0:
+ mServer.type = ServerInfo::TMWATHENA;
+ break;
+ case 1:
+ mServer.type = ServerInfo::EVOL;
+ break;
+#ifdef MANASERV_SUPPORT
+ case 2:
+ mServer.type = ServerInfo::MANASERV;
+ break;
+#endif
+ default:
+ mServer.type = ServerInfo::UNKNOWN;
+ }
+ }
+ else
{
- case 0:
- serverInfo.type = ServerInfo::TMWATHENA;
- break;
- case 1:
- serverInfo.type = ServerInfo::MANASERV;
- break;
- default:
- serverInfo.type = ServerInfo::UNKNOWN;
+ mServer.type = ServerInfo::TMWATHENA;
}
// Tell the server has to be saved
- serverInfo.save = true;
+ mServer.save = true;
//Add server
- mServerDialog->saveCustomServers(serverInfo, mIndex);
+ mServerDialog->updateServer(mServer, mIndex);
scheduleDelete();
}
}
@@ -193,7 +224,7 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
}
}
-void CustomServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void EditServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
{
gcn::Key key = keyEvent.getKey();
diff --git a/src/gui/customserverdialog.h b/src/gui/editserverdialog.h
index 25c320e81..6035b0e50 100644
--- a/src/gui/customserverdialog.h
+++ b/src/gui/editserverdialog.h
@@ -1,6 +1,7 @@
/*
* The Mana Client
* Copyright (C) 2011-2012 The Mana Developers
+ * Copyright (C) 2012 The ManaPlus Developers
*
* This file is part of The Mana Client.
*
@@ -18,8 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef CUSTOMSERVERDIALOG_H
-#define CUSTOMSERVERDIALOG_H
+#ifndef EDITSERVERDIALOG_H
+#define EDITSERVERDIALOG_H
class Button;
class Label;
@@ -48,7 +49,12 @@ class TypeListModel : public gcn::ListModel
/**
* Used to get number of line in the list
*/
- int getNumberOfElements() { return 2; }
+ int getNumberOfElements()
+#ifdef MANASERV_SUPPORT
+ { return 3; }
+#else
+ { return 2; }
+#endif
/**
* Used to get an element from the list
@@ -61,14 +67,14 @@ class TypeListModel : public gcn::ListModel
*
* \ingroup Interface
*/
-class CustomServerDialog : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+class EditServerDialog : public Window,
+ public gcn::ActionListener,
+ public gcn::KeyListener
{
public:
- CustomServerDialog(ServerDialog *parent, int index = -1);
+ EditServerDialog(ServerDialog *parent, ServerInfo server, int index);
- ~CustomServerDialog();
+ ~EditServerDialog();
/**
* Called when receiving actions from the widgets.
@@ -82,7 +88,7 @@ class CustomServerDialog : public Window,
private:
TextField *mServerAddressField;
TextField *mPortField;
- TextField *mNameField;
+ TextField *mNameField;
TextField *mDescriptionField;
Button *mOkButton;
Button *mCancelButton;
@@ -91,8 +97,8 @@ class CustomServerDialog : public Window,
TypeListModel *mTypeListModel;
ServerDialog *mServerDialog;
- // The index of the entry to modify, -1 when only adding a new entry.
+ ServerInfo mServer;
int mIndex;
};
-#endif // CUSTOMSERVERDIALOG_H
+#endif // EDITSERVERDIALOG_H
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 39ff19a89..cf2c3f0f9 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -28,6 +28,7 @@
#include "logger.h"
#include "main.h"
+#include "gui/editserverdialog.h"
#include "gui/gui.h"
#include "gui/logindialog.h"
#include "gui/okdialog.h"
@@ -117,8 +118,8 @@ std::string ServersListModel::getElementAt(int elementIndex)
const ServerInfo &server = mServers->at(elementIndex);
std::string myServer;
myServer += server.hostname;
- myServer += ":";
- myServer += toString(server.port);
+// myServer += ":";
+// myServer += toString(server.port);
return myServer;
}
@@ -138,20 +139,6 @@ void ServersListModel::setVersionString(int index, const std::string &version)
}
}
-std::string TypeListModel::getElementAt(int elementIndex)
-{
- if (elementIndex == 0)
- return "TmwAthena";
- else if (elementIndex == 1)
- return "Evol";
-#ifdef MANASERV_SUPPORT
- else if (elementIndex == 2)
- return "ManaServ";
-#endif
- else
- return "Unknown";
-}
-
class ServersListBox : public ListBox
{
public:
@@ -249,11 +236,6 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
setWindowName("ServerDialog");
- Label *serverLabel = new Label(_("Server:"));
- Label *portLabel = new Label(_("Port:"));
-
- mServerNameField = new TextField(mServerInfo->hostname);
- mPortField = new TextField(toString(mServerInfo->port));
mPersistentIPCheckBox = new CheckBox(_("Use same ip for game sub servers"),
config.getBoolValue("usePersistentIP"),
this, "persitent ip");
@@ -268,66 +250,33 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
ScrollArea *usedScroll = new ScrollArea(mServersList);
usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- Label *typeLabel = new Label(_("Server type:"));
- mTypeListModel = new TypeListModel();
- mTypeField = new DropDown(mTypeListModel);
- switch (serverInfo->type)
- {
- case ServerInfo::MANASERV:
-#ifdef MANASERV_SUPPORT
- mTypeField->setSelected(2);
- break;
-#endif
- default:
- case ServerInfo::UNKNOWN:
- case ServerInfo::TMWATHENA:
- mTypeField->setSelected(0);
- break;
- case ServerInfo::EVOL:
- mTypeField->setSelected(1);
- break;
- }
- int n = 1;
+ int n = 0;
mDescription = new Label(std::string());
mQuitButton = new Button(_("Quit"), "quit", this);
mLoadButton = new Button(_("Load"), "load", this);
mConnectButton = new Button(_("Connect"), "connect", this);
- mManualEntryButton = new Button(_("Custom Server"), "addEntry", this);
+ mAddEntryButton = new Button(_("Add"), "addEntry", this);
+ mEditEntryButton = new Button(_("Edit"), "editEntry", this);
mDeleteButton = new Button(_("Delete"), "remove", this);
- mServerNameField->setActionEventId("connect");
- mPortField->setActionEventId("connect");
-
- mServerNameField->addActionListener(this);
- mPortField->addActionListener(this);
- mManualEntryButton->addActionListener(this);
mServersList->addSelectionListener(this);
usedScroll->setVerticalScrollAmount(0);
- place(0, 0, serverLabel);
- place(1, 0, mServerNameField, 5).setPadding(3);
- place(0, 1, portLabel);
- place(1, 1, mPortField, 5).setPadding(3);
- place(0, 2, typeLabel);
- place(1, 2, mTypeField, 5).setPadding(3);
- place(0, 2 + n, usedScroll, 6, 5).setPadding(3);
- place(0, 7 + n, mDescription, 6);
- place(0, 8 + n, mPersistentIPCheckBox, 6);
- place(0, 9 + n, mManualEntryButton);
- place(1, 9 + n, mDeleteButton);
- place(2, 9 + n, mLoadButton);
- place(4, 9 + n, mQuitButton);
- place(5, 9 + n, mConnectButton);
+ place(0, 0 + n, usedScroll, 7, 5).setPadding(3);
+ place(0, 5 + n, mDescription, 7);
+ place(0, 6 + n, mPersistentIPCheckBox, 7);
+ place(0, 7 + n, mAddEntryButton);
+ place(1, 7 + n, mEditEntryButton);
+ place(2, 7 + n, mLoadButton);
+ place(3, 7 + n, mDeleteButton);
+ place(5, 7 + n, mQuitButton);
+ place(6, 7 + n, mConnectButton);
// Make sure the list has enough height
- getLayout().setRowHeight(3, 80);
+ getLayout().setRowHeight(0, 80);
-/*
- reflowLayout(400, 300);
- setDefaultSize(400, 300, ImageRect::CENTER);
-*/
// Do this manually instead of calling reflowLayout so we can enforce a
// minimum width.
int width = 0, height = 0;
@@ -353,17 +302,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
mServersList->setSelected(0); // Do this after for the Delete button
setVisible(true);
- if (mServerNameField->getText().empty())
- {
- mServerNameField->requestFocus();
- }
- else
- {
- if (mPortField->getText().empty())
- mPortField->requestFocus();
- else
- mConnectButton->requestFocus();
- }
+ mConnectButton->requestFocus();
loadServers(true);
@@ -381,82 +320,48 @@ ServerDialog::~ServerDialog()
}
delete mServersListModel;
mServersListModel = nullptr;
- delete mTypeListModel;
- mTypeListModel = nullptr;
}
void ServerDialog::action(const gcn::ActionEvent &event)
{
- if (event.getId() == "ok")
- {
- // Give focus back to the server dialog.
- mServerNameField->requestFocus();
- }
- else if (event.getId() == "connect")
+ if (event.getId() == "connect")
{
- // Check login
- if (mServerNameField->getText().empty()
- || mPortField->getText().empty())
- {
- OkDialog *dlg = new OkDialog(_("Error"),
- _("Please type both the address and the port of a server."));
- dlg->addActionListener(this);
- }
- else
- {
- if (mDownload)
- mDownload->cancel();
-
- mQuitButton->setEnabled(false);
- mConnectButton->setEnabled(false);
- mLoadButton->setEnabled(false);
+ if (Client::getState() == STATE_CONNECT_SERVER)
+ return;
- mServerInfo->hostname = mServerNameField->getText();
- mServerInfo->port = static_cast<short>(
- atoi(mPortField->getText().c_str()));
+ if (mDownload)
+ mDownload->cancel();
- if (mTypeField)
- {
- switch (mTypeField->getSelected())
- {
- case 0:
- mServerInfo->type = ServerInfo::TMWATHENA;
- break;
- case 1:
- mServerInfo->type = ServerInfo::EVOL;
- break;
-#ifdef MANASERV_SUPPORT
- case 2:
- mServerInfo->type = ServerInfo::MANASERV;
- break;
-#endif
- default:
- mServerInfo->type = ServerInfo::UNKNOWN;
- }
- }
- else
- {
- mServerInfo->type = ServerInfo::TMWATHENA;
- }
+ mQuitButton->setEnabled(false);
+ mConnectButton->setEnabled(false);
+ mLoadButton->setEnabled(false);
- // Save the selected server
- mServerInfo->save = true;
+ int index = mServersList->getSelected();
+ if (index < 0)
+ return;
- if (chatLogger)
- chatLogger->setServerName(mServerInfo->hostname);
+ 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;
- saveCustomServers(*mServerInfo);
+ if (chatLogger)
+ chatLogger->setServerName(mServerInfo->hostname);
- if (!LoginDialog::savedPasswordKey.empty())
- {
- if (mServerInfo->hostname != LoginDialog::savedPasswordKey)
- LoginDialog::savedPassword = "";
- }
+ saveCustomServers(*mServerInfo);
- config.setValue("usePersistentIP",
- mPersistentIPCheckBox->isSelected());
- Client::setState(STATE_CONNECT_SERVER);
+ if (!LoginDialog::savedPasswordKey.empty())
+ {
+ if (mServerInfo->hostname != LoginDialog::savedPasswordKey)
+ LoginDialog::savedPassword = "";
}
+
+ config.setValue("usePersistentIP",
+ mPersistentIPCheckBox->isSelected());
+ Client::setState(STATE_CONNECT_SERVER);
}
else if (event.getId() == "quit")
{
@@ -470,15 +375,23 @@ void ServerDialog::action(const gcn::ActionEvent &event)
}
else if (event.getId() == "addEntry")
{
- setFieldsReadOnly(false);
+ new EditServerDialog(this, ServerInfo(), -1);
+ }
+ else if (event.getId() == "editEntry")
+ {
+ int index = mServersList->getSelected();
+ if (index >= 0)
+ new EditServerDialog(this, mServers.at(index), index);
}
else if (event.getId() == "remove")
{
int index = mServersList->getSelected();
- mServersList->setSelected(0);
- mServers.erase(mServers.begin() + index);
-
- saveCustomServers();
+ if (index >= 0)
+ {
+ mServersList->setSelected(0);
+ mServers.erase(mServers.begin() + index);
+ saveCustomServers();
+ }
}
}
@@ -504,32 +417,6 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &)
// Update the server and post fields according to the new selection
const ServerInfo &myServer = mServersListModel->getServer(index);
mDescription->setCaption(myServer.description);
- mServerNameField->setText(myServer.hostname);
- mPortField->setText(toString(myServer.port));
- if (mTypeField)
- {
- switch (myServer.type)
- {
- case ServerInfo::TMWATHENA:
- case ServerInfo::UNKNOWN:
-#ifdef MANASERV_SUPPORT
- default:
- mTypeField->setSelected(0);
- break;
- case ServerInfo::MANASERV:
- mTypeField->setSelected(2);
- break;
-#else
- case ServerInfo::MANASERV:
- default:
- mTypeField->setSelected(0);
- break;
-#endif
- case ServerInfo::EVOL:
- mTypeField->setSelected(1);
- break;
- }
- }
setFieldsReadOnly(true);
mDeleteButton->setEnabled(myServer.save);
@@ -581,24 +468,14 @@ void ServerDialog::setFieldsReadOnly(bool readOnly)
{
if (!readOnly)
{
- mDescription->setCaption(std::string());
mServersList->setSelected(-1);
-
- mServerNameField->setText(std::string());
- mPortField->setText(std::string("6901"));
-
- mServerNameField->requestFocus();
+ mDescription->setCaption(std::string());
}
- mManualEntryButton->setEnabled(readOnly);
+ mAddEntryButton->setEnabled(readOnly);
mDeleteButton->setEnabled(false);
mLoadButton->setEnabled(readOnly);
mDescription->setVisible(readOnly);
-
- mServerNameField->setEnabled(!readOnly);
- mPortField->setEnabled(!readOnly);
- if (mTypeField)
- mTypeField->setEnabled(!readOnly);
}
void ServerDialog::downloadServerList()
@@ -731,12 +608,16 @@ void ServerDialog::loadCustomServers()
for (int i = 0; i < MAX_SERVERLIST; ++i)
{
const std::string index = toString(i);
- const std::string nameKey = "MostUsedServerName" + index;
+ const std::string nameKey = "MostUsedServerDescName" + index;
+ const std::string descKey = "MostUsedServerDescription" + index;
+ const std::string hostKey = "MostUsedServerName" + index;
const std::string typeKey = "MostUsedServerType" + index;
const std::string portKey = "MostUsedServerPort" + index;
ServerInfo server;
- server.hostname = config.getValue(nameKey, "");
+ server.name = config.getValue(nameKey, "");
+ server.description = config.getValue(descKey, "");
+ server.hostname = config.getValue(hostKey, "");
server.type = ServerInfo::parseType(config.getValue(typeKey, ""));
const int defaultPort = defaultPortForServerType(server.type);
@@ -752,21 +633,29 @@ void ServerDialog::loadCustomServers()
}
}
-void ServerDialog::saveCustomServers(const ServerInfo &currentServer)
+void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
+ int index)
{
// Make sure the current server is mentioned first
if (currentServer.isValid())
{
- ServerInfos::iterator i, i_end = mServers.end();
- for (i = mServers.begin(); i != i_end; ++i)
+ if (index >= 0 && (unsigned)index < mServers.size())
+ {
+ mServers[index] = currentServer;
+ }
+ else
{
- if (*i == currentServer)
+ ServerInfos::iterator i, i_end = mServers.end();
+ for (i = mServers.begin(); i != i_end; ++i)
{
- mServers.erase(i);
- break;
+ if (*i == currentServer)
+ {
+ mServers.erase(i);
+ break;
+ }
}
+ mServers.insert(mServers.begin(), currentServer);
}
- mServers.insert(mServers.begin(), currentServer);
}
int savedServerCount = 0;
@@ -780,15 +669,19 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer)
if (!(server.save && server.isValid()))
continue;
- const std::string index = toString(savedServerCount);
- const std::string nameKey = "MostUsedServerName" + index;
- const std::string typeKey = "MostUsedServerType" + index;
- const std::string portKey = "MostUsedServerPort" + index;
+ const std::string num = toString(savedServerCount);
+ const std::string nameKey = "MostUsedServerDescName" + num;
+ const std::string descKey = "MostUsedServerDescription" + num;
+ const std::string hostKey = "MostUsedServerName" + num;
+ const std::string typeKey = "MostUsedServerType" + num;
+ const std::string portKey = "MostUsedServerPort" + num;
- config.setValue(nameKey, toString(server.hostname));
+ config.setValue(nameKey, toString(server.name));
+ config.setValue(descKey, toString(server.description));
+ config.setValue(hostKey, toString(server.hostname));
config.setValue(typeKey, serverTypeToString(server.type));
config.setValue(portKey, toString(server.port));
- ++savedServerCount;
+ ++ savedServerCount;
}
// Insert an invalid entry at the end to make the loading stop there
@@ -853,3 +746,8 @@ int ServerDialog::downloadUpdate(void *ptr, DownloadStatus status,
return 0;
}
+
+void ServerDialog::updateServer(ServerInfo server, int index)
+{
+ saveCustomServers(server, index);
+}
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index d2fe0d25b..0618d4c4c 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -83,30 +83,6 @@ class ServersListModel : public gcn::ListModel
ServerDialog *mParent;
};
-/**
- * Server Type List Model
- */
-class TypeListModel : public gcn::ListModel
-{
- public:
- TypeListModel() {}
-
- /**
- * Used to get number of line in the list
- */
- int getNumberOfElements()
-#ifdef MANASERV_SUPPORT
- { return 3; }
-#else
- { return 2; }
-#endif
-
- /**
- * Used to get an element from the list
- */
- std::string getElementAt(int elementIndex);
-};
-
/**
* The server choice dialog.
@@ -147,12 +123,16 @@ class ServerDialog : public Window,
void logic();
+ void updateServer(ServerInfo server, int index);
+
protected:
friend class ServersListModel;
MutexLocker lock()
{ return MutexLocker(&mMutex); }
private:
+ friend class EditServerDialog;
+
/**
* Called to load a list of available server from an online xml file.
*/
@@ -160,28 +140,25 @@ class ServerDialog : public Window,
void loadServers(bool addNew = true);
void loadCustomServers();
- void saveCustomServers(const ServerInfo &currentServer = ServerInfo());
+ void saveCustomServers(const ServerInfo &currentServer = ServerInfo(),
+ int index = -1);
static int downloadUpdate(void *ptr, DownloadStatus status,
size_t total, size_t remaining);
void setFieldsReadOnly(bool readOnly);
- TextField *mServerNameField;
- TextField *mPortField;
Label *mDescription;
Button *mQuitButton;
Button *mConnectButton;
- Button *mManualEntryButton;
+ Button *mAddEntryButton;
+ Button *mEditEntryButton;
Button *mDeleteButton;
Button *mLoadButton;
ListBox *mServersList;
ServersListModel *mServersListModel;
- DropDown *mTypeField;
- TypeListModel *mTypeListModel;
-
const std::string &mDir;
enum ServerDialogDownloadStatus
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index fb6a99a33..b4bb1a2d8 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -54,7 +54,7 @@ public:
ServerInfo()
{
type = TMWATHENA;
- port = 0;
+ port = 6901;
save = false;
version.first = 0;
}