summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/models/updatelistmodel.h37
-rw-r--r--src/gui/windows/logindialog.cpp43
-rw-r--r--src/gui/windows/logindialog.h8
-rw-r--r--src/gui/windows/serverdialog.cpp34
4 files changed, 104 insertions, 18 deletions
diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h
index 67fffc34e..0f1104200 100644
--- a/src/gui/models/updatelistmodel.h
+++ b/src/gui/models/updatelistmodel.h
@@ -25,17 +25,25 @@
#include "gui/models/listmodel.h"
-#include "net/logindata.h"
+#include "net/hostsgroup.h"
+
+#include "utils/stringvector.h"
#include "localconsts.h"
class UpdateListModel final : public ListModel
{
public:
- explicit UpdateListModel(LoginData *const data) :
+ explicit UpdateListModel(ServerInfo *const server) :
ListModel(),
- mLoginData(data)
+ mNames(),
+ mServer(server)
{
+ FOR_EACH(std::vector<HostsGroup>::const_iterator, it, server->updateHosts)
+ {
+ const HostsGroup &group = *it;
+ mNames.push_back(group.name);
+ }
}
A_DELETE_COPY(UpdateListModel)
@@ -45,20 +53,31 @@ class UpdateListModel final : public ListModel
int getNumberOfElements() override final
{
- if (!mLoginData)
- return 0;
- return CAST_S32(mLoginData->updateHosts.size());
+ return CAST_S32(mNames.size());
}
std::string getElementAt(int i) override final
{
- if (!mLoginData || i >= getNumberOfElements() || i < 0)
+ if (i >= getNumberOfElements() || i < 0)
return "???";
- return mLoginData->updateHosts[i];
+ return mNames[i];
+ }
+
+ HostsGroup &getSelectedGroup(const unsigned int sel)
+ {
+ if (sel >= mServer->updateHosts.size())
+ return mServer->updateHosts[0];
+ mServer->updateHosts[sel];
+ }
+
+ bool empty() const
+ {
+ return mNames.empty();
}
protected:
- LoginData *mLoginData;
+ StringVect mNames;
+ ServerInfo *mServer;
};
#endif // GUI_MODELS_UPDATELISTMODEL_H
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 34f84fee4..937af72be 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -41,7 +41,9 @@
#include "gui/widgets/layoutcell.h"
#include "net/charserverhandler.h"
+#include "net/logindata.h"
#include "net/loginhandler.h"
+#include "net/serverinfo.h"
#include "net/updatetypeoperators.h"
#include "utils/delete2.h"
@@ -58,13 +60,14 @@ namespace
} // namespace
LoginDialog::LoginDialog(LoginData &data,
- std::string serverName,
+ ServerInfo *const server,
std::string *const updateHost) :
// TRANSLATORS: login dialog name
Window(_("Login"), Modal_false, nullptr, "login.xml"),
ActionListener(),
KeyListener(),
mLoginData(&data),
+ mServer(server),
mUserField(new TextField(this, mLoginData->username)),
mPassField(new PasswordField(this, mLoginData->password)),
// TRANSLATORS: login dialog label
@@ -89,7 +92,7 @@ LoginDialog::LoginDialog(LoginData &data,
mUpdateListModel(nullptr),
mUpdateHostDropDown(nullptr),
mUpdateHost(updateHost),
- mServerName(serverName)
+ mServerName(server->hostname)
{
setCloseButton(true);
setWindowName("Login");
@@ -97,20 +100,22 @@ LoginDialog::LoginDialog(LoginData &data,
if (charServerHandler)
charServerHandler->clear();
+ mergeUpdateHosts();
+
// TRANSLATORS: login dialog label
Label *const serverLabel1 = new Label(this, _("Server:"));
- Label *const serverLabel2 = new Label(this, serverName);
+ Label *const serverLabel2 = new Label(this, mServerName);
serverLabel2->adjustSize();
// TRANSLATORS: login dialog label
Label *const userLabel = new Label(this, _("Name:"));
// TRANSLATORS: login dialog label
Label *const passLabel = new Label(this, _("Password:"));
- if (mLoginData->updateHosts.size() > 1)
+ if (mServer->updateHosts.size() > 1)
{
// TRANSLATORS: login dialog label
mUpdateHostLabel = new Label(this, strprintf(_("Update host: %s"),
mLoginData->updateHost.c_str()));
- mUpdateListModel = new UpdateListModel(mLoginData);
+ mUpdateListModel = new UpdateListModel(mServer);
mUpdateHostDropDown = new DropDown(this, mUpdateListModel,
false, Modal_false, this, "updateselect");
const std::string str = serverConfig.getValue("updateHost2", "");
@@ -321,14 +326,28 @@ void LoginDialog::prepareUpdate()
std::string str;
if (mUpdateHostDropDown)
{
- str = mUpdateHostDropDown->getSelectedString();
+ const int sel = mUpdateHostDropDown->getSelected();
+ if (sel >= 0)
+ {
+ const HostsGroup &group = mServer->updateHosts[sel];
+ if (!group.hosts.empty())
+ {
+ str = group.hosts[0];
+ mLoginData->updateHosts = group.hosts;
+ serverConfig.setValue("updateHost2", group.name);
+ }
+ else
+ {
+ serverConfig.setValue("updateHost2", "");
+ }
+ }
}
else if (mLoginData->updateHost.empty()
&& !mLoginData->updateHosts.empty())
{
str = mLoginData->updateHosts[0];
+ serverConfig.setValue("updateHost2", str);
}
- serverConfig.setValue("updateHost2", str);
if (!str.empty() && checkPath(str))
{
mLoginData->updateHost = str;
@@ -360,3 +379,13 @@ void LoginDialog::close()
client->setState(State::SWITCH_SERVER);
Window::close();
}
+
+void LoginDialog::mergeUpdateHosts()
+{
+ HostsGroup group;
+
+ // TRANSLATORS: update hosts group default name
+ group.name = _("default");
+ group.hosts = mLoginData->updateHosts;
+ mServer->updateHosts.insert(mServer->updateHosts.begin(), group);
+}
diff --git a/src/gui/windows/logindialog.h b/src/gui/windows/logindialog.h
index 8feaa39f5..9047bf123 100644
--- a/src/gui/windows/logindialog.h
+++ b/src/gui/windows/logindialog.h
@@ -33,6 +33,7 @@ class CheckBox;
class DropDown;
class Label;
class LoginData;
+class ServerInfo;
class TextField;
class UpdateListModel;
class UpdateTypeModel;
@@ -53,8 +54,8 @@ class LoginDialog final : public Window,
* @see Window::Window
*/
LoginDialog(LoginData &data,
- std::string serverName,
- std::string *const updateHost);
+ ServerInfo *const server,
+ std::string *const updateHost) A_NONNULL(3, 4);
A_DELETE_COPY(LoginDialog)
@@ -86,7 +87,10 @@ class LoginDialog final : public Window,
void prepareUpdate();
+ void mergeUpdateHosts();
+
LoginData *mLoginData A_NONNULLPOINTER;
+ ServerInfo *mServer A_NONNULLPOINTER;
TextField *mUserField A_NONNULLPOINTER;
TextField *mPassField A_NONNULLPOINTER;
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index dac370887..04663de71 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -44,6 +44,7 @@
#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
+#include "utils/paths.h"
#include "debug.h"
@@ -237,6 +238,7 @@ void ServerDialog::connectToSelectedServer()
mServerInfo->persistentIp = server.persistentIp;
mServerInfo->updateMirrors = server.updateMirrors;
mServerInfo->packetVersion = server.packetVersion;
+ mServerInfo->updateHosts = server.updateHosts;
settings.persistentIp = mServerInfo->persistentIp;
settings.supportUrl = mServerInfo->supportUrl;
@@ -447,6 +449,33 @@ void ServerDialog::downloadServerList()
config.setValue("serverslistupdate", getDateString());
}
+static void loadHostsGroup(const XmlNodePtr node,
+ ServerInfo &server)
+{
+ HostsGroup group;
+ group.name = XML::getProperty(node,
+ "name",
+ // TRANSLATORS: unknown hosts group name
+ _("Unknown"));
+ for_each_xml_child_node(hostNode, node)
+ {
+ if (!xmlNameEqual(hostNode, "host"))
+ continue;
+ const std::string host = XmlChildContent(hostNode);
+ if (host.empty())
+ continue;
+ if (!checkPath(host))
+ {
+ logger->log1("Warning: incorrect update server name");
+ continue;
+ }
+
+ group.hosts.push_back(host);
+ }
+ if (!group.hosts.empty())
+ server.updateHosts.push_back(group);
+}
+
void ServerDialog::loadServers(const bool addNew)
{
XML::Document doc(std::string(mDir).append("/").append(
@@ -563,6 +592,10 @@ void ServerDialog::loadServers(const bool addNew)
{
server.updateMirrors.push_back(XmlChildContent(subNode));
}
+ else if (xmlNameEqual(subNode, "updates"))
+ {
+ loadHostsGroup(subNode, server);
+ }
}
server.version.first = font->getWidth(version);
@@ -587,6 +620,7 @@ void ServerDialog::loadServers(const bool addNew)
mServers[i].althostname = server.althostname;
mServers[i].persistentIp = server.persistentIp;
mServers[i].updateMirrors = server.updateMirrors;
+ mServers[i].updateHosts = server.updateHosts;
mServers[i].packetVersion = server.packetVersion;
mServersListModel->setVersionString(i, version);
found = true;