16 #define GETTEXT_DOMAIN "wesnoth-lib" 33 #include <boost/algorithm/string/trim.hpp> 36 #define ERR_DLG LOG_STREAM(err, log_mpconnect) 37 #define WRN_DLG LOG_STREAM(warn, log_mpconnect) 38 #define LOG_DLG LOG_STREAM(info, log_mpconnect) 39 #define DBG_DLG LOG_STREAM(debug, log_mpconnect) 49 void clear_listbox_selection(listbox& listbox)
51 const auto selection = listbox.get_selected_row();
53 listbox.select_row(selection,
false);
67 , host_name_(register_text("host_name",
84 text_box& hostname_box = find_widget<text_box>(&win,
"host_name",
false);
86 button& button_add = find_widget<button>(&win,
"server_add",
false);
87 button& button_del = find_widget<button>(&win,
"server_delete",
false);
90 for(
const auto& server : *servers) {
117 text_box& hostname_box = find_widget<text_box>(
window,
"host_name",
false);
119 button& button_add = find_widget<button>(
window,
"server_add",
false);
120 button& button_del = find_widget<button>(
window,
"server_delete",
false);
122 const auto& address = boost::trim_copy(hostname_box.
get_value());
127 for(
const auto& server : *servers) {
128 if(server.address == address) {
129 server_list.select_row(row);
149 clear_listbox_selection(server_list);
150 button_del.set_active(
false);
152 button_add.set_active(!address.empty());
165 text_box& hostname_box = find_widget<text_box>(
window,
"host_name",
false);
168 const auto& address = boost::trim_copy(hostname_box.
get_value());
171 if(address.empty() || !selection.valid()) {
180 const std::size_t mem_pos = selection.user_defined() && !
user_servers_.empty()
181 ? 1 + selection.relative_index() : 0;
182 const unsigned int ui_pos = selection.user_defined() ? 1 + selection.row() :
builtin_servers_.size();
186 if(!gui2::dialogs::edit_text::execute(
_(
"Add Server"),
_(
"Name:"), name,
true) || name.empty()) {
209 if(!selection.valid() || !selection.user_defined()) {
225 text_box& hostname_box = find_widget<text_box>(
window,
"host_name",
false);
226 button& button_add = find_widget<button>(
window,
"server_add",
false);
227 button& button_del = find_widget<button>(
window,
"server_delete",
false);
231 if(!selection.valid()) {
235 button_del.set_active(
false);
239 hostname_box.
set_value(selection.get().address);
242 button_add.set_active(
false);
244 button_del.set_active(selection.user_defined());
256 return parent_list().at(relative_index());
262 return unsigned(row_);
268 return user_defined() ? row() -
owner_->builtin_servers_.size() : row();
274 return user_defined() ?
owner_->user_servers_ :
owner_->builtin_servers_;
window(const builder_window::window_resolution &definition)
< Needs to be initialized in show.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
server_list builtin_servers_
server_list & parent_list() const
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::string get_value() const
std::string network_host()
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
void set_network_host(const std::string &host)
int get_selected_row() const
Returns the first selected row.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
static std::string _(const char *str)
std::array< server_list *, 2 > server_lists()
std::string address
may include ':' followed by port number
Class for a single line text area.
server_list user_servers_
const std::vector< game_config::server_info > & builtin_servers_list()
std::map< std::string, t_string > widget_item
This file contains the settings handling of the widget library.
selection current_selection()
This shows the dialog to the MP server to connect to.
void set_user_servers_list(const std::vector< game_config::server_info > &value)
Modify, read and display user preferences.
Various uncategorised dialogs.
window * get_window()
Returns a pointer to the dialog's window.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
std::vector< server_info > server_list
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
Abstract base class for all modal dialogs.
Standard logging facilities (interface).
void select_first_match()
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
dialogs::modal_dialog * owner_
The dialog that owns the window.
std::map< std::string, widget_item > widget_data
void insert_into_server_listbox(listbox &listbox, const server_info &srv, int pos=-1)
std::vector< game_config::server_info > user_servers_list()
base class of top level items, the only item which needs to store the final canvases to draw on...
static lg::log_domain log_mpconnect
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::size_t relative_index() const