Mana
Loading...
Searching...
No Matches
serverdialog.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "gui/widgets/window.h"
25
26#include "net/download.h"
27#include "net/serverinfo.h"
28#include "utils/xml.h"
29
30#include <guichan/actionlistener.hpp>
31#include <guichan/keylistener.hpp>
32#include <guichan/listmodel.hpp>
33#include <guichan/selectionlistener.hpp>
34
35#include <memory>
36#include <string>
37#include <vector>
38
39class Button;
40class Label;
41class ListBox;
42class ServerDialog;
43class TextField;
44class DropDown;
45
49class ServersListModel : public gcn::ListModel
50{
51 public:
52 using VersionString = std::pair<int, std::string>;
53
54 ServersListModel(ServerInfos *servers, ServerDialog *parent);
55
59 int getNumberOfElements() override;
60
64 std::string getElementAt(int elementIndex) override;
65
69 const ServerInfo &getServer(int elementIndex) const
70 { return mServers->at(elementIndex); }
71
72 void setVersionString(int index, const std::string &version);
73
74 private:
76 std::vector<VersionString> mVersionStrings;
78};
79
85class ServerDialog : public Window,
86 public gcn::ActionListener,
87 public gcn::KeyListener,
88 public gcn::SelectionListener
89{
90 public:
91 ServerDialog(ServerInfo *serverInfo, const std::string &dir);
92 ~ServerDialog() override;
93
97 void action(const gcn::ActionEvent &event) override;
98
99 void keyPressed(gcn::KeyEvent &keyEvent) override;
100
104 void valueChanged(const gcn::SelectionEvent &event) override;
105
106 void mouseClicked(gcn::MouseEvent &mouseEvent) override;
107
108 void logic() override;
109
110 protected:
111 friend class CustomServerDialog;
112
118 void saveCustomServers(const ServerInfo &currentServer = ServerInfo(),
119 int index = -1);
120
121 private:
125 void downloadServerList();
126 void loadServers();
127 void loadServer(XML::Node serverNode);
128
129 void loadCustomServers();
130
137
139 std::unique_ptr<ServersListModel> mServersListModel;
140
141 const std::string &mDir;
142
143 std::unique_ptr<Net::Download> mDownload;
144 bool mDownloadDone = false;
148};
Button widget.
Definition button.h:38
The custom server addition dialog.
A drop down box from which you can select different values.
Definition dropdown.h:34
Label widget.
Definition label.h:34
A list box, meant to be used inside a scroll area.
Definition listbox.h:36
The server choice dialog.
void valueChanged(const gcn::SelectionEvent &event) override
Called when the selected value changed in the servers list box.
Button * mQuitButton
void saveCustomServers(const ServerInfo &currentServer=ServerInfo(), int index=-1)
Saves the new server entry in the custom server list.
const std::string & mDir
Button * mConnectButton
Label * mDescription
Button * mModifyButton
void downloadServerList()
Called to load a list of available server from an online xml file.
void keyPressed(gcn::KeyEvent &keyEvent) override
ServerInfos mServers
void loadServer(XML::Node serverNode)
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
Label * mDownloadText
void loadCustomServers()
Button * mManualEntryButton
void logic() override
ListBox * mServersList
Button * mDeleteButton
std::unique_ptr< ServersListModel > mServersListModel
void mouseClicked(gcn::MouseEvent &mouseEvent) override
~ServerDialog() override
ServerInfo * mServerInfo
std::unique_ptr< Net::Download > mDownload
Server and Port List Model.
std::pair< int, std::string > VersionString
ServerInfos * mServers
std::string getElementAt(int elementIndex) override
Used to get an element from the list.
const ServerInfo & getServer(int elementIndex) const
Used to get the corresponding Server struct.
int getNumberOfElements() override
Used to get number of line in the list.
std::vector< VersionString > mVersionStrings
ServerDialog * mParent
void setVersionString(int index, const std::string &version)
A text field.
Definition textfield.h:72
A window.
Definition window.h:59
std::deque< ServerInfo > ServerInfos
Definition serverinfo.h:109